mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
Replace minimist, convert build scripts to ES modules + misc refactoring
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user