From 2014566cc4ca97e0cf0979f78a386e4fbc6cc659 Mon Sep 17 00:00:00 2001 From: hensm Date: Tue, 26 Feb 2019 14:08:17 +0000 Subject: [PATCH] Reorganize ext build scripts and add linting --- app/bin/build.js | 6 +++--- app/tslint.json | 23 ++--------------------- ext/{ => bin}/build.js | 29 +++++++++++++++-------------- ext/bin/lib/paths.js | 8 ++++++++ ext/bin/lint.js | 13 +++++++++++++ ext/package.json | 9 +++++---- ext/tslint.json | 5 +++++ package.json | 5 +++-- tslintCommon.json | 24 ++++++++++++++++++++++++ 9 files changed, 78 insertions(+), 44 deletions(-) rename ext/{ => bin}/build.js (83%) create mode 100644 ext/bin/lib/paths.js create mode 100644 ext/bin/lint.js create mode 100644 ext/tslint.json create mode 100644 tslintCommon.json diff --git a/app/bin/build.js b/app/bin/build.js index d388f5b..5b3266f 100644 --- a/app/bin/build.js +++ b/app/bin/build.js @@ -51,9 +51,9 @@ async function build () { spawnSync(`tsc --project ${ROOT_PATH} \ --outDir ${BUILD_PATH}` , { - shell: true - , stdio: [ process.stdin, process.stdout, process.stderr ] - }); + shell: true + , stdio: [ process.stdin, process.stdout, process.stderr ] + }); // Move tsc output to build dir fs.moveSync(path.join(BUILD_PATH, "src"), BUILD_PATH); diff --git a/app/tslint.json b/app/tslint.json index cd2a8ef..b138f8f 100644 --- a/app/tslint.json +++ b/app/tslint.json @@ -1,24 +1,5 @@ { - "defaultSeverity": "error" - , "extends": [ - "tslint:recommended" + "extends": [ + "../tslintCommon.json" ] - , "jsRules": {} - , "rules": { - "no-consecutive-blank-lines": false - , "arrow-parens": false - , "interface-name": false - , "max-classes-per-file": false - , "max-line-length": [ true, { - "limit": 80 - , "ignore-pattern": "//" - }] - , "no-console": [ true, "log" ] - , "object-literal-sort-keys": false - , "radix": false - , "semicolon": [ true, "always" ] - , "space-before-function-paren": [ true, "always" ] - , "trailing-comma": false - } - , "rulesDirectory": [] } diff --git a/ext/build.js b/ext/bin/build.js similarity index 83% rename from ext/build.js rename to ext/bin/build.js index 053aec8..a60c40b 100644 --- a/ext/build.js +++ b/ext/bin/build.js @@ -1,17 +1,18 @@ +"use strict"; + const fs = require("fs-extra"); const path = require("path"); const minimist = require("minimist"); const webpack = require("webpack"); const webExt = require("web-ext").default; -const package = require("./package.json"); -const appPackage = require("../app/package.json"); +const { ROOT + , INCLUDE_PATH + , DIST_PATH + , UNPACKED_PATH } = require("./lib/paths"); - -const INCLUDE_PATH = path.resolve(__dirname, "src"); - -const DIST_PATH = path.join(__dirname, "../dist/ext"); -const UNPACKED_PATH = path.join(DIST_PATH, "unpacked"); +const packageMeta = require(`${ROOT}/package.json`); +const appPackageMeta = require(`${ROOT}/../app/package.json`); const argv = minimist(process.argv.slice(2), { @@ -20,7 +21,7 @@ const argv = minimist(process.argv.slice(2), { , default: { package: false // Should package with web-ext , watch: false // Should run webpack in watch mode - , mirroringAppId: package.__mirroringAppId // Chromecast receiver app ID + , mirroringAppId: packageMeta.__mirroringAppId // Chromecast receiver app ID , mode: "development" // webpack mode } }); @@ -37,7 +38,7 @@ if (argv.package) { // Import webpack config and specify env values -const webpackConfig = require("./webpack.config.js")({ +const webpackConfig = require(`${ROOT}/webpack.config.js`)({ includePath: INCLUDE_PATH /** * If watching files, output directly to dist. Unpacked @@ -47,11 +48,11 @@ const webpackConfig = require("./webpack.config.js")({ ? UNPACKED_PATH : DIST_PATH - , extensionName: package.__extensionName - , extensionId: package.__extensionId - , extensionVersion: package.__extensionVersion - , applicationName: appPackage.__applicationName - , applicationVersion: appPackage.__applicationVersion + , extensionName: packageMeta.__extensionName + , extensionId: packageMeta.__extensionId + , extensionVersion: packageMeta.__extensionVersion + , applicationName: appPackageMeta.__applicationName + , applicationVersion: appPackageMeta.__applicationVersion , mirroringAppId: argv.mirroringAppId // eval source map needs special CSP diff --git a/ext/bin/lib/paths.js b/ext/bin/lib/paths.js new file mode 100644 index 0000000..62a5374 --- /dev/null +++ b/ext/bin/lib/paths.js @@ -0,0 +1,8 @@ +"use strict"; + +const path = require("path"); + +exports.ROOT = path.resolve(__dirname, "../../"); +exports.INCLUDE_PATH = path.resolve(exports.ROOT, "src"); +exports.DIST_PATH = path.join(exports.ROOT, "../dist/ext"); +exports.UNPACKED_PATH = path.join(exports.DIST_PATH, "unpacked"); diff --git a/ext/bin/lint.js b/ext/bin/lint.js new file mode 100644 index 0000000..037e3f5 --- /dev/null +++ b/ext/bin/lint.js @@ -0,0 +1,13 @@ +"use strict"; + +const { spawnSync } = require("child_process"); +const { ROOT, INCLUDE_PATH } = require("./lib/paths"); + + +spawnSync(`tslint --config ${ROOT}/tslint.json \ + --project ${ROOT}/tsconfig.json \ + "${INCLUDE_PATH}/**/*.ts{,x}"` + , { + shell: true + , stdio: [ process.stdin, process.stdout, process.stderr ] + }); diff --git a/ext/package.json b/ext/package.json index 1ba58d2..c9a4c42 100644 --- a/ext/package.json +++ b/ext/package.json @@ -5,10 +5,11 @@ "__mirroringAppId": "19A6F4AE", "scripts": { - "build": "node build.js", - "package": "node build.js --package", - "watch": "node build.js --watch", - "start": "web-ext run -s ../dist/ext/" + "build": "node bin/build.js", + "package": "node bin/build.js --package", + "watch": "node bin/build.js --watch", + "start": "web-ext run -s ../dist/ext/", + "lint": "node bin/lint.js" }, "devDependencies": { "@types/react": "^16.8.4", diff --git a/ext/tslint.json b/ext/tslint.json new file mode 100644 index 0000000..b138f8f --- /dev/null +++ b/ext/tslint.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "../tslintCommon.json" + ] +} diff --git a/package.json b/package.json index 55f0c6f..3dbe704 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,9 @@ "test": "node test/driver.js", "install-manifest": "npm run install-manifest --prefix ./app", "remove-manifest": "npm run remove-manifest --prefix ./app", - "lint": "npm run lint:app", - "lint:app": "npm run lint --prefix ./app" + "lint": "npm run lint:app && npm run lint:ext", + "lint:app": "npm run lint --prefix ./app", + "lint:ext": "npm run lint --prefix ./ext" }, "devDependencies": { "@types/uuid": "^3.4.4", diff --git a/tslintCommon.json b/tslintCommon.json new file mode 100644 index 0000000..7298d00 --- /dev/null +++ b/tslintCommon.json @@ -0,0 +1,24 @@ +{ + "defaultSeverity": "error" + , "extends": [ + "tslint:recommended" + ] + , "jsRules": false + , "rules": { + "no-consecutive-blank-lines": false + , "arrow-parens": false + , "interface-name": false + , "max-classes-per-file": false + , "max-line-length": [ true, { + "limit": 80 + , "ignore-pattern": "//" + }] + , "no-console": [ true, "log" ] + , "object-literal-sort-keys": false + , "radix": false + , "semicolon": [ true, "always" ] + , "space-before-function-paren": [ true, "always" ] + , "trailing-comma": false + } + , "rulesDirectory": [] +}