Reorganize ext build scripts and add linting

This commit is contained in:
hensm
2019-02-26 14:08:17 +00:00
parent 1e49fbe9be
commit 2014566cc4
9 changed files with 78 additions and 44 deletions

View File

@@ -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);

View File

@@ -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": []
}

View File

@@ -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

8
ext/bin/lib/paths.js Normal file
View File

@@ -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");

13
ext/bin/lint.js Normal file
View File

@@ -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 ]
});

View File

@@ -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",

5
ext/tslint.json Normal file
View File

@@ -0,0 +1,5 @@
{
"extends": [
"../tslintCommon.json"
]
}

View File

@@ -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",

24
tslintCommon.json Normal file
View File

@@ -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": []
}