mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 02:29:59 +00:00
Define build script arguments
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const minimist = require("minimist");
|
||||||
|
|
||||||
const { spawnSync } = require("child_process");
|
const { spawnSync } = require("child_process");
|
||||||
const { exec: pkgExec } = require("pkg");
|
const { exec: pkgExec } = require("pkg");
|
||||||
@@ -10,42 +11,48 @@ const { executableName
|
|||||||
, manifestName
|
, manifestName
|
||||||
, manifestPath
|
, manifestPath
|
||||||
, pkgPlatform
|
, pkgPlatform
|
||||||
, DIST_DIR_PATH } = require("./lib/paths");
|
, DIST_PATH } = require("./lib/paths");
|
||||||
|
|
||||||
const argv = require("minimist")(process.argv.slice(2));
|
|
||||||
|
|
||||||
|
|
||||||
const BUILD_DIR_PATH = path.join(__dirname, "../build");
|
const argv = minimist(process.argv.slice(2), {
|
||||||
|
boolean: [ "package" ]
|
||||||
|
, string: [ "platform" ]
|
||||||
|
, default: {
|
||||||
|
platform: os.platform()
|
||||||
|
, package: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const BUILD_PATH = path.join(__dirname, "../build");
|
||||||
|
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
fs.removeSync(DIST_DIR_PATH);
|
fs.removeSync(DIST_PATH);
|
||||||
|
|
||||||
// Make directories
|
// Make directories
|
||||||
fs.ensureDirSync(BUILD_DIR_PATH);
|
fs.ensureDirSync(BUILD_PATH);
|
||||||
fs.ensureDirSync(DIST_DIR_PATH, { recursive: true });
|
fs.ensureDirSync(DIST_PATH, { recursive: true });
|
||||||
|
|
||||||
|
|
||||||
async function build () {
|
async function build () {
|
||||||
const platform = argv.platform || os.platform();
|
|
||||||
|
|
||||||
// Run Babel
|
// Run Babel
|
||||||
spawnSync(`babel src -d ${BUILD_DIR_PATH} --copy-files `
|
spawnSync(`babel src -d ${BUILD_PATH} --copy-files `
|
||||||
, { shell: true });
|
, { shell: true });
|
||||||
|
|
||||||
// Add either installed path or dist path to app manifest
|
// Add either installed path or dist path to app manifest
|
||||||
const manifest = JSON.parse(fs.readFileSync(manifestName, "utf8"));
|
const manifest = JSON.parse(fs.readFileSync(manifestName, "utf8"));
|
||||||
manifest.path = argv.package
|
manifest.path = argv.package
|
||||||
? path.join(executablePath[platform], executableName[platform])
|
? path.join(executablePath[argv.platform], executableName[argv.platform])
|
||||||
: path.join(DIST_DIR_PATH, executableName[platform]);
|
: path.join(DIST_PATH, executableName[argv.platform]);
|
||||||
|
|
||||||
// Write manifest
|
// Write manifest
|
||||||
fs.writeFileSync(path.join(BUILD_DIR_PATH, manifestName)
|
fs.writeFileSync(path.join(BUILD_PATH, manifestName)
|
||||||
, JSON.stringify(manifest, null, 4));
|
, JSON.stringify(manifest, null, 4));
|
||||||
|
|
||||||
|
|
||||||
// File permissions
|
// File permissions
|
||||||
for (const file of fs.readdirSync(BUILD_DIR_PATH)) {
|
for (const file of fs.readdirSync(BUILD_PATH)) {
|
||||||
fs.chmodSync(path.resolve(BUILD_DIR_PATH, file), 0o755);
|
fs.chmodSync(path.resolve(BUILD_PATH, file), 0o755);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -59,35 +66,35 @@ async function build () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.writeFileSync(path.join(BUILD_DIR_PATH, "package.json")
|
fs.writeFileSync(path.join(BUILD_PATH, "package.json")
|
||||||
, JSON.stringify(pkgInfo))
|
, JSON.stringify(pkgInfo))
|
||||||
|
|
||||||
// Package executable
|
// Package executable
|
||||||
await pkgExec([
|
await pkgExec([
|
||||||
BUILD_DIR_PATH
|
BUILD_PATH
|
||||||
, "--target", pkgPlatform[platform]
|
, "--target", pkgPlatform[argv.platform]
|
||||||
, "--output", path.join(BUILD_DIR_PATH, executableName[platform])
|
, "--output", path.join(BUILD_PATH, executableName[argv.platform])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (argv.package) {
|
if (argv.package) {
|
||||||
const installerName = await buildInstaller(platform);
|
const installerName = await buildInstaller(argv.platform);
|
||||||
|
|
||||||
// Move installer to dist
|
// Move installer to dist
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, installerName)
|
fs.moveSync(path.join(BUILD_PATH, installerName)
|
||||||
, path.join(DIST_DIR_PATH, installerName)
|
, path.join(DIST_PATH, installerName)
|
||||||
, { overwrite: true });
|
, { overwrite: true });
|
||||||
} else {
|
} else {
|
||||||
// Move binary / app manifest
|
// Move binary / app manifest
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, manifestName)
|
fs.moveSync(path.join(BUILD_PATH, manifestName)
|
||||||
, path.join(DIST_DIR_PATH, manifestName)
|
, path.join(DIST_PATH, manifestName)
|
||||||
, { overwrite: true });
|
, { overwrite: true });
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, executableName[platform])
|
fs.moveSync(path.join(BUILD_PATH, executableName[argv.platform])
|
||||||
, path.join(DIST_DIR_PATH, executableName[platform])
|
, path.join(DIST_PATH, executableName[argv.platform])
|
||||||
, { overwrite: true });
|
, { overwrite: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove build directory
|
// Remove build directory
|
||||||
fs.removeSync(BUILD_DIR_PATH);
|
fs.removeSync(BUILD_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildInstaller (platform) {
|
async function buildInstaller (platform) {
|
||||||
@@ -95,13 +102,13 @@ async function buildInstaller (platform) {
|
|||||||
case "darwin": {
|
case "darwin": {
|
||||||
const installerName = "fx_cast_bridge.pkg";
|
const installerName = "fx_cast_bridge.pkg";
|
||||||
const componentName = "fx_cast_bridge_default.pkg";
|
const componentName = "fx_cast_bridge_default.pkg";
|
||||||
const installerPath = path.join(BUILD_DIR_PATH, installerName);
|
const installerPath = path.join(BUILD_PATH, installerName);
|
||||||
const componentPath = path.join(BUILD_DIR_PATH, componentName);
|
const componentPath = path.join(BUILD_PATH, componentName);
|
||||||
|
|
||||||
const packagingDir = path.join(__dirname, "../packaging/macos/");
|
const packagingDir = path.join(__dirname, "../packaging/macos/");
|
||||||
|
|
||||||
// Create pkgbuild root
|
// Create pkgbuild root
|
||||||
const rootPath = path.join(BUILD_DIR_PATH, "root");
|
const rootPath = path.join(BUILD_PATH, "root");
|
||||||
const rootExecutablePath = path.join(rootPath
|
const rootExecutablePath = path.join(rootPath
|
||||||
, executablePath[platform]);
|
, executablePath[platform]);
|
||||||
const rootManifestPath = path.join(rootPath
|
const rootManifestPath = path.join(rootPath
|
||||||
@@ -112,9 +119,9 @@ async function buildInstaller (platform) {
|
|||||||
fs.ensureDirSync(rootManifestPath, { recursive: true });
|
fs.ensureDirSync(rootManifestPath, { recursive: true });
|
||||||
|
|
||||||
// Move files to root
|
// Move files to root
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, executableName[platform])
|
fs.moveSync(path.join(BUILD_PATH, executableName[platform])
|
||||||
, path.join(rootExecutablePath, executableName[platform]));
|
, path.join(rootExecutablePath, executableName[platform]));
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, manifestName)
|
fs.moveSync(path.join(BUILD_PATH, manifestName)
|
||||||
, path.join(rootManifestPath, manifestName));
|
, path.join(rootManifestPath, manifestName));
|
||||||
|
|
||||||
// Build component package
|
// Build component package
|
||||||
@@ -132,7 +139,7 @@ async function buildInstaller (platform) {
|
|||||||
// Build installer package
|
// Build installer package
|
||||||
spawnSync(
|
spawnSync(
|
||||||
`productbuild --distribution ${distFilePath} `
|
`productbuild --distribution ${distFilePath} `
|
||||||
+ `--package-path ${BUILD_DIR_PATH} `
|
+ `--package-path ${BUILD_PATH} `
|
||||||
+ `${installerPath}`
|
+ `${installerPath}`
|
||||||
, { shell: true });
|
, { shell: true });
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const minimist = require("minimist");
|
||||||
|
|
||||||
const { manifestName
|
const { manifestName
|
||||||
, manifestPath
|
, manifestPath
|
||||||
, DIST_DIR_PATH } = require("./lib/paths");
|
, DIST_PATH } = require("./lib/paths");
|
||||||
|
|
||||||
const argv = require("minimist")(process.argv.slice(2));
|
|
||||||
|
|
||||||
|
|
||||||
const CURRENT_MANIFEST_PATH = path.join(DIST_DIR_PATH, manifestName);
|
const argv = minimist(process.argv.slice(2), {
|
||||||
|
boolean: [ "remove" ]
|
||||||
|
, default: {
|
||||||
|
remove: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const CURRENT_MANIFEST_PATH = path.join(DIST_PATH, manifestName);
|
||||||
const WIN_REGISTRY_KEY = "fx_cast_bridge";
|
const WIN_REGISTRY_KEY = "fx_cast_bridge";
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
exports.DIST_DIR_PATH = path.join(__dirname, "../../../dist/app");
|
exports.DIST_PATH = path.join(__dirname, "../../../dist/app");
|
||||||
|
|
||||||
exports.executableName = {
|
exports.executableName = {
|
||||||
win32: "bridge.exe"
|
win32: "bridge.exe"
|
||||||
|
|||||||
36
ext/build.js
36
ext/build.js
@@ -1,22 +1,29 @@
|
|||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { spawn } = require("child_process");
|
const { spawn } = require("child_process");
|
||||||
const argv = require("minimist")(process.argv.slice(2));
|
const minimist = require("minimist");
|
||||||
|
|
||||||
|
|
||||||
const extensionName = "fx_cast";
|
const argv = minimist(process.argv.slice(2), {
|
||||||
const extensionId = "fx_cast@matt.tf";
|
boolean: [ "package", "watch" ]
|
||||||
const extensionVersion = "0.0.1";
|
, string: [ "mirroringAppId", "mode" ]
|
||||||
|
, default: {
|
||||||
|
package: false
|
||||||
|
, watch: false
|
||||||
|
, mirroringAppId: "19A6F4AE"
|
||||||
|
, mode: "development"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (argv.package) {
|
if (argv.package) {
|
||||||
argv.mode = "production";
|
argv.mode = "production";
|
||||||
argv.watch = false;
|
argv.watch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default argument values
|
|
||||||
const { mirroringAppId = "19A6F4AE"
|
const extensionName = "fx_cast";
|
||||||
, mode = "development" } = argv;
|
const extensionId = "fx_cast@matt.tf";
|
||||||
|
const extensionVersion = "0.0.1";
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
fs.removeSync(path.join(__dirname, "../dist/ext/"));
|
fs.removeSync(path.join(__dirname, "../dist/ext/"));
|
||||||
@@ -25,12 +32,13 @@ const child = spawn(
|
|||||||
`webpack --env.extensionName=${extensionName} `
|
`webpack --env.extensionName=${extensionName} `
|
||||||
+ `--env.extensionId=${extensionId} `
|
+ `--env.extensionId=${extensionId} `
|
||||||
+ `--env.extensionVersion=${extensionVersion} `
|
+ `--env.extensionVersion=${extensionVersion} `
|
||||||
+ `--env.mirroringAppId=${mirroringAppId} `
|
+ `--env.mirroringAppId=${argv.mirroringAppId} `
|
||||||
+ `--mode=${mode} `
|
+ `--mode=${argv.mode} `
|
||||||
+ `${argv.watch ? "--watch" : ""} `
|
+ `${argv.watch ? "--watch" : ""} && `
|
||||||
+ `&& web-ext build --overwrite-dest `
|
|
||||||
+ `--source-dir ../dist/ext/unpacked `
|
+ `web-ext build --overwrite-dest `
|
||||||
+ `--artifacts-dir ../dist/ext `
|
+ `--source-dir ../dist/ext/unpacked `
|
||||||
|
+ `--artifacts-dir ../dist/ext `
|
||||||
, { shell: true }
|
, { shell: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user