Replace minimist, convert build scripts to ES modules + misc refactoring

This commit is contained in:
hensm
2022-08-19 03:09:59 +01:00
parent 170b80283d
commit a186570dc8
17 changed files with 702 additions and 505 deletions

View File

@@ -1,45 +1,50 @@
// @ts-check
"use strict";
const fs = require("fs-extra");
const path = require("path");
import fs from "fs-extra";
import path from "path";
import url from "url";
const esbuild = require("esbuild");
const minimist = require("minimist");
const sveltePlugin = require("esbuild-svelte");
const sveltePreprocess = require("svelte-preprocess");
const webExt = require("web-ext");
import esbuild from "esbuild";
import sveltePlugin from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";
import yargs from "yargs";
import webExt from "web-ext";
const { copyFilesPlugin } = require("./lib/copyFilesPlugin.js");
import copyFilesPlugin from "./lib/copyFilesPlugin.js";
const BRIDGE_NAME = "fx_cast_bridge";
const BRIDGE_VERSION = "0.2.0";
const MIRRORING_APP_ID = "19A6F4AE";
const argv = minimist(process.argv.slice(2), {
boolean: ["package", "watch"],
string: ["mirroringAppId", "mode"],
default: {
package: false,
watch: false,
mirroringAppId: MIRRORING_APP_ID,
mode: "development"
}
});
if (argv.package && argv.watch) {
console.error("Cannot package whilst watching files.");
process.exit(1);
}
const argv = yargs()
.help()
.version(false)
.option("watch", {
describe: "Rebuild on changes",
type: "boolean"
})
.option("package", {
describe: "Package with web-ext",
type: "boolean",
conflicts: "watch"
})
.option("mode", {
describe: "Set build mode",
choices: ["development", "production"],
default: "development"
})
.parseSync(process.argv);
// If packaging, use production mode
if (argv.package) {
argv.mode = "production";
}
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
// Paths
const rootPath = path.resolve(__dirname, "../");
const rootPath = path.join(__dirname, "../");
const srcPath = path.join(rootPath, "src");
const distPath = path.join(rootPath, "../dist/ext/");
@@ -75,7 +80,7 @@ const buildOpts = {
define: {
BRIDGE_NAME: `"${BRIDGE_NAME}"`,
BRIDGE_VERSION: `"${BRIDGE_VERSION}"`,
MIRRORING_APP_ID: `"${argv.mirroringAppId}"`
MIRRORING_APP_ID: `"${MIRRORING_APP_ID}"`
},
plugins: [
// @ts-ignore

View File

@@ -1,11 +1,11 @@
// @ts-check
"use strict";
const path = require("path");
const fs = require("fs");
import path from "path";
import fs from "fs";
// eslint-disable-next-line no-unused-vars
const esbuild = require("esbuild");
import esbuild from "esbuild";
/**
* Walks file tree from a given root path.
@@ -37,17 +37,14 @@ function* walk(rootPath) {
*
* @type {(opts: CopyFilesPluginOpts) => esbuild.Plugin}
*/
exports.copyFilesPlugin = opts => {
export default opts => {
if (!fs.existsSync(opts.src)) {
throw new Error("copyFilesPlugin: src path not found!");
}
const matchingPaths = [];
for (const path of walk(opts.src)) {
if (!opts.excludePattern?.test(path)) {
matchingPaths.push(path);
}
}
const matchingPaths = [...walk(opts.src)].filter(
path => !opts.excludePattern?.test(path)
);
return {
name: "copy-files",

104
ext/package-lock.json generated
View File

@@ -17,7 +17,8 @@
"ts-loader": "^9.2.8",
"typescript": "^4.6.3",
"uuid": "^8.3.2",
"web-ext": "^6.8.0"
"web-ext": "^6.8.0",
"yargs": "^17.5.1"
}
},
"node_modules/@babel/code-frame": {
@@ -753,15 +754,6 @@
"node": ">=12"
}
},
"node_modules/addons-linter/node_modules/yargs-parser": {
"version": "21.0.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.0.1.tgz",
"integrity": "sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==",
"dev": true,
"engines": {
"node": ">=12"
}
},
"node_modules/addons-moz-compare": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/addons-moz-compare/-/addons-moz-compare-1.2.0.tgz",
@@ -7433,6 +7425,33 @@
"npm": ">=6.9.0"
}
},
"node_modules/web-ext/node_modules/yargs": {
"version": "16.2.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
"integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==",
"dev": true,
"dependencies": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",
"get-caller-file": "^2.0.5",
"require-directory": "^2.1.1",
"string-width": "^4.2.0",
"y18n": "^5.0.5",
"yargs-parser": "^20.2.2"
},
"engines": {
"node": ">=10"
}
},
"node_modules/web-ext/node_modules/yargs-parser": {
"version": "20.2.9",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==",
"dev": true,
"engines": {
"node": ">=10"
}
},
"node_modules/webpack": {
"version": "5.72.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.0.tgz",
@@ -7690,30 +7709,30 @@
"dev": true
},
"node_modules/yargs": {
"version": "16.2.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
"integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==",
"version": "17.5.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.5.1.tgz",
"integrity": "sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==",
"dev": true,
"dependencies": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",
"get-caller-file": "^2.0.5",
"require-directory": "^2.1.1",
"string-width": "^4.2.0",
"string-width": "^4.2.3",
"y18n": "^5.0.5",
"yargs-parser": "^20.2.2"
"yargs-parser": "^21.0.0"
},
"engines": {
"node": ">=10"
"node": ">=12"
}
},
"node_modules/yargs-parser": {
"version": "20.2.9",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==",
"version": "21.1.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
"dev": true,
"engines": {
"node": ">=10"
"node": ">=12"
}
},
"node_modules/yauzl": {
@@ -8390,12 +8409,6 @@
"y18n": "^5.0.5",
"yargs-parser": "^21.0.0"
}
},
"yargs-parser": {
"version": "21.0.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.0.1.tgz",
"integrity": "sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==",
"dev": true
}
}
},
@@ -13452,6 +13465,29 @@
"ws": "7.4.6",
"yargs": "16.2.0",
"zip-dir": "2.0.0"
},
"dependencies": {
"yargs": {
"version": "16.2.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
"integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==",
"dev": true,
"requires": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",
"get-caller-file": "^2.0.5",
"require-directory": "^2.1.1",
"string-width": "^4.2.0",
"y18n": "^5.0.5",
"yargs-parser": "^20.2.2"
}
},
"yargs-parser": {
"version": "20.2.9",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==",
"dev": true
}
}
},
"webpack": {
@@ -13639,24 +13675,24 @@
"dev": true
},
"yargs": {
"version": "16.2.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
"integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==",
"version": "17.5.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.5.1.tgz",
"integrity": "sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==",
"dev": true,
"requires": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",
"get-caller-file": "^2.0.5",
"require-directory": "^2.1.1",
"string-width": "^4.2.0",
"string-width": "^4.2.3",
"y18n": "^5.0.5",
"yargs-parser": "^20.2.2"
"yargs-parser": "^21.0.0"
}
},
"yargs-parser": {
"version": "20.2.9",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==",
"version": "21.1.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
"dev": true
},
"yauzl": {

View File

@@ -1,4 +1,5 @@
{
"type": "module",
"scripts": {
"build": "node bin/build.js",
"package": "node bin/build.js --package",
@@ -19,6 +20,7 @@
"ts-loader": "^9.2.8",
"typescript": "^4.6.3",
"uuid": "^8.3.2",
"web-ext": "^6.8.0"
"web-ext": "^6.8.0",
"yargs": "^17.5.1"
}
}