mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Build without pkg unless packaging
This commit is contained in:
16
README.md
16
README.md
@@ -85,7 +85,7 @@ npm run remove-manifest
|
||||
This will build the ext and app, outputting to `dist/`:
|
||||
|
||||
* #### `dist/app/`
|
||||
... contains the bridge executable and manifest with the path pointing that executable. The `install-manifest` script copies this manifest to the proper location (or adds its current location to the registry on Windows).
|
||||
... contains the built bridge with launcher and manifest with the path pointing that launcher. The `install-manifest` script copies this manifest to the proper location (or adds its current location to the registry on Windows).
|
||||
* #### `dist/ext/`
|
||||
... contains the unpacked extension.
|
||||
|
||||
@@ -107,7 +107,7 @@ npm run start --prefix ./ext
|
||||
Should package with web-ext.
|
||||
* `--watch`
|
||||
Should run webpack in watch mode.
|
||||
* `--packageType` `"<appID>"`
|
||||
* `--mirroringAppId` `"<appID>"`
|
||||
Provide an alternative default mirroring receiver app ID.
|
||||
* `--mode` `"production"`, `"development"`
|
||||
Run webpack in a different mode. Defaults to `"development"` unless combined with `--package`.
|
||||
@@ -132,20 +132,12 @@ npm run package:ext # Packaging extension
|
||||
npm run package:app # Packaging bridge application
|
||||
|
||||
# Linux platforms
|
||||
npm run package:app -- -- --platform=linux --packageType=deb
|
||||
npm run package:app -- -- --platform=linux --packageType=rpm
|
||||
|
||||
# Windows
|
||||
npm run package:app -- -- --platform=win32
|
||||
|
||||
# macOS
|
||||
npm run package:app -- -- --platform=darwin
|
||||
npm run package:app -- -- --packageType=deb
|
||||
npm run package:app -- -- --packageType=rpm
|
||||
````
|
||||
|
||||
#### Bridge package script arguments
|
||||
|
||||
* `--platform` `"win32"`,`"darwin"`,`"linux"`
|
||||
Select the platform to build for. Defaults to current platform.
|
||||
* `--arch` `"x64"`,`"x86"`
|
||||
Select platform arch to build for. Defaults to current platform arch.
|
||||
* `--packageType` `"deb"`,`"rpm"`
|
||||
|
||||
224
app/bin/build.js
224
app/bin/build.js
@@ -3,6 +3,7 @@
|
||||
const fs = require("fs-extra");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
|
||||
const minimist = require("minimist");
|
||||
const glob = require("glob");
|
||||
const mustache = require("mustache");
|
||||
@@ -11,8 +12,7 @@ const pkg = require("pkg");
|
||||
|
||||
const { spawnSync } = require("child_process");
|
||||
|
||||
const { __applicationName: applicationName
|
||||
, __applicationVersion: applicationVersion } = require("../package.json");
|
||||
const meta = require("../package.json");
|
||||
|
||||
const { author
|
||||
, homepage } = require("../../package.json");
|
||||
@@ -33,10 +33,9 @@ const { executableName
|
||||
// Command line args
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
boolean: [ "package", "skipNativeBuilds" ]
|
||||
, string: [ "platform", "arch", "packageType" ]
|
||||
, string: [ "arch", "packageType" ]
|
||||
, default: {
|
||||
platform: os.platform()
|
||||
, arch: os.arch()
|
||||
arch: os.arch()
|
||||
, package: false
|
||||
// Linux package type (deb/rpm)
|
||||
, packageType: "deb"
|
||||
@@ -61,7 +60,7 @@ for (const target of supportedTargets) {
|
||||
supportedArchs.push(arch);
|
||||
}
|
||||
|
||||
if (!supportedPlatforms.includes(pkgPlatform[argv.platform])) {
|
||||
if (!supportedPlatforms.includes(pkgPlatform[process.platform])) {
|
||||
console.error("Unsupported target platform");
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -80,9 +79,6 @@ const spawnOptions = {
|
||||
, stdio: [ process.stdin, process.stdout, process.stderr ]
|
||||
};
|
||||
|
||||
const isBuildingForMac = argv.platform === "darwin";
|
||||
const isBuildingForMacOnMac = isBuildingForMac && process.platform === "darwin";
|
||||
|
||||
/**
|
||||
* Shouldn't exist, but cleanup and re-create any existing
|
||||
* build directories, just in case.
|
||||
@@ -98,54 +94,17 @@ const MDNS_BINDING_PATH = path.join(
|
||||
const MDNS_BINDING_NAME = "dns_sd_bindings.node";
|
||||
|
||||
async function build () {
|
||||
/**
|
||||
* Because the native receiver selector can only be built on
|
||||
* systems with the capacity to link to the native AppKit
|
||||
* libraries, and the pkg installer can only be built on
|
||||
* platforms with the requisite pkgbuild/productbuild binaries,
|
||||
* there's no point in trying to build from other platforms.
|
||||
*/
|
||||
if (isBuildingForMac && !isBuildingForMacOnMac) {
|
||||
console.error("macOS version must be built on macOS");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Run tsc
|
||||
spawnSync(`tsc --project ${ROOT_PATH} \
|
||||
--outDir ${BUILD_PATH}`
|
||||
, spawnOptions);
|
||||
|
||||
// Move tsc output to build dir
|
||||
if (process.platform === "linux") {
|
||||
// Quick workaround for issue on linux
|
||||
spawnSync("mv", [ path.join(BUILD_PATH, "src/*"), BUILD_PATH ]
|
||||
, spawnOptions);
|
||||
} else {
|
||||
const buildSrcDir = path.join(BUILD_PATH, "src");
|
||||
|
||||
for (const fileName of fs.readdirSync(buildSrcDir)) {
|
||||
fs.moveSync(path.join(buildSrcDir, fileName)
|
||||
, path.join(BUILD_PATH, fileName));
|
||||
}
|
||||
|
||||
fs.removeSync(buildSrcDir);
|
||||
}
|
||||
|
||||
// Copy other files
|
||||
fs.copySync(SRC_PATH, BUILD_PATH, {
|
||||
overwrite: true
|
||||
, filter (src, dest) {
|
||||
return !/.(js|ts)$/.test(src);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Native app manifest
|
||||
* https://mdn.io/Native_manifests#Native_messaging_manifests
|
||||
*/
|
||||
const manifest = {
|
||||
"name": applicationName
|
||||
"name": meta.__applicationName
|
||||
, "description": ""
|
||||
, "type": "stdio"
|
||||
, "allowed_extensions": [ extensionId ]
|
||||
@@ -156,12 +115,68 @@ async function build () {
|
||||
* add the path to the built executable in the dist folder.
|
||||
*/
|
||||
if (argv.package) {
|
||||
// If packaging for windows, use win32 path helpers.
|
||||
manifest.path = (argv.platform === "win32" ? path.win32 : path)
|
||||
.join(executablePath[argv.platform]
|
||||
, executableName[argv.platform]);
|
||||
// Need a minimal package.json for pkg.
|
||||
const pkgManifest = {
|
||||
bin: "main.js"
|
||||
, pkg: {
|
||||
/**
|
||||
* Workaround for pkg asset detection
|
||||
* https://github.com/thibauts/node-castv2/issues/46
|
||||
*/
|
||||
"assets": "../../node_modules/castv2/lib/cast_channel.proto"
|
||||
}
|
||||
};
|
||||
|
||||
// Write pkg manifest
|
||||
fs.writeFileSync(path.join(BUILD_PATH, "src/package.json")
|
||||
, JSON.stringify(pkgManifest))
|
||||
|
||||
// Run pkg to create a single executable
|
||||
await pkg.exec([
|
||||
path.join(BUILD_PATH, "src")
|
||||
, "--target", `node12-${pkgPlatform[process.platform]}-${argv.arch}`
|
||||
, "--output", path.join(BUILD_PATH, executableName[process.platform])
|
||||
]);
|
||||
|
||||
fs.copySync(path.join(MDNS_BINDING_PATH, MDNS_BINDING_NAME)
|
||||
, path.join(BUILD_PATH, MDNS_BINDING_NAME));
|
||||
|
||||
fs.removeSync(path.join(BUILD_PATH, "src"));
|
||||
|
||||
|
||||
manifest.path = path.join(executablePath[process.platform]
|
||||
, executableName[process.platform]);
|
||||
|
||||
} else {
|
||||
manifest.path = path.join(DIST_PATH, executableName[argv.platform]);
|
||||
let launcherPath = path.join(BUILD_PATH
|
||||
, meta.__applicationExecutableName);
|
||||
const modulesDir = path.join(ROOT_PATH, "node_modules");
|
||||
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
launcherPath += ".bat";
|
||||
fs.writeFileSync(launcherPath,
|
||||
`@echo off
|
||||
setlocal
|
||||
set NODE_PATH=${modulesDir}
|
||||
node .\\src\\main.js %*
|
||||
endlocal
|
||||
`);
|
||||
break;
|
||||
}
|
||||
|
||||
case "linux":
|
||||
case "darwin": {
|
||||
launcherPath += ".sh";
|
||||
fs.writeFileSync(launcherPath,
|
||||
`#!/usr/bin/env sh
|
||||
NODE_PATH="${modulesDir}" node ./src/main.js "$@"
|
||||
`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
manifest.path = path.join(DIST_PATH, path.basename(launcherPath));
|
||||
}
|
||||
|
||||
|
||||
@@ -176,34 +191,8 @@ async function build () {
|
||||
}
|
||||
|
||||
|
||||
// Need a minimal package.json for pkg.
|
||||
const pkgManifest = {
|
||||
bin: "main.js"
|
||||
, pkg: {
|
||||
/**
|
||||
* Workaround for pkg asset detection
|
||||
* https://github.com/thibauts/node-castv2/issues/46
|
||||
*/
|
||||
"assets": "../node_modules/castv2/lib/cast_channel.proto"
|
||||
}
|
||||
};
|
||||
|
||||
// Write pkg manifest
|
||||
fs.writeFileSync(path.join(BUILD_PATH, "package.json")
|
||||
, JSON.stringify(pkgManifest))
|
||||
|
||||
// Run pkg to create a single executable
|
||||
await pkg.exec([
|
||||
BUILD_PATH
|
||||
, "--target", `node12-${pkgPlatform[argv.platform]}-${argv.arch}`
|
||||
, "--output", path.join(BUILD_PATH, executableName[argv.platform])
|
||||
]);
|
||||
|
||||
fs.copySync(path.join(MDNS_BINDING_PATH, MDNS_BINDING_NAME)
|
||||
, path.join(BUILD_PATH, MDNS_BINDING_NAME));
|
||||
|
||||
// Build NativeMacReceiverSelector
|
||||
if (isBuildingForMacOnMac && !argv.skipNativeBuilds) {
|
||||
if (process.platform === "darwin" && !argv.skipNativeBuilds) {
|
||||
const selectorPath = path.join(__dirname, "../selector/mac/");
|
||||
const derivedDataPath = path.join(__dirname, "../selector/mac/build/");
|
||||
|
||||
@@ -218,7 +207,8 @@ async function build () {
|
||||
const selectorBundlePath = path.join(derivedDataPath
|
||||
, "Build/Products/Release/", selectorExecutableName);
|
||||
|
||||
fs.moveSync(selectorBundlePath, path.join(BUILD_PATH, selectorExecutableName));
|
||||
fs.moveSync(selectorBundlePath
|
||||
, path.join(BUILD_PATH, selectorExecutableName));
|
||||
fs.removeSync(derivedDataPath);
|
||||
}
|
||||
|
||||
@@ -229,7 +219,7 @@ async function build () {
|
||||
* to dist.
|
||||
*/
|
||||
if (argv.package) {
|
||||
const installerName = await packageApp(argv.platform, argv.arch);
|
||||
const installerName = await packageApp(process.platform, argv.arch);
|
||||
if (installerName) {
|
||||
// Move installer to dist
|
||||
fs.moveSync(
|
||||
@@ -238,37 +228,25 @@ async function build () {
|
||||
, { overwrite: true });
|
||||
}
|
||||
} else {
|
||||
// Move executable and app manifest to dist
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, manifestName)
|
||||
, path.join(DIST_PATH, manifestName)
|
||||
, { overwrite: true });
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, executableName[argv.platform])
|
||||
, path.join(DIST_PATH, executableName[argv.platform])
|
||||
, { overwrite: true });
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, MDNS_BINDING_NAME)
|
||||
, path.join(DIST_PATH, MDNS_BINDING_NAME)
|
||||
, { overwrite: true });
|
||||
|
||||
if (isBuildingForMacOnMac && !argv.skipNativeBuilds) {
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, selectorExecutableName)
|
||||
, path.join(DIST_PATH, selectorExecutableName)
|
||||
, { overwrite: true });
|
||||
}
|
||||
// Move tsc output and launcher to dist
|
||||
fs.moveSync(BUILD_PATH, DIST_PATH, { overwrite: true });
|
||||
/*
|
||||
spawnSync("npm install --production", {
|
||||
...spawnOptions
|
||||
, cwd: DIST_PATH
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
// Remove build directory
|
||||
fs.removeSync(BUILD_PATH);
|
||||
//fs.removeSync(BUILD_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a platform and returns the path of the created
|
||||
* installer package.
|
||||
*/
|
||||
function packageApp (platform, arch) {
|
||||
async function packageApp (platform, arch) {
|
||||
const packageFunctionArgs = [
|
||||
arch
|
||||
, executableName[platform] // platformExecutableName
|
||||
@@ -323,8 +301,9 @@ function packageDarwin (
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
|
||||
const outputName = `${applicationName}-${applicationVersion}-${arch}.pkg`;
|
||||
const componentName = `${applicationName}_component.pkg`;
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.pkg`;
|
||||
const componentName = `${meta.__applicationName}_component.pkg`;
|
||||
|
||||
const packagingDir = path.join(__dirname, "../packaging/mac/");
|
||||
const packagingOutputDir = path.join(BUILD_PATH, "packaging");
|
||||
@@ -346,7 +325,7 @@ function packageDarwin (
|
||||
fs.moveSync(path.join(BUILD_PATH, manifestName)
|
||||
, path.join(rootManifestPath, manifestName));
|
||||
|
||||
if (isBuildingForMacOnMac && !argv.skipNativeBuilds) {
|
||||
if (process.platform === "darwin" && !argv.skipNativeBuilds) {
|
||||
// Move selector executable alongside main executable
|
||||
fs.moveSync(path.join(BUILD_PATH, selectorExecutableName)
|
||||
, path.join(rootExecutablePath, selectorExecutableName));
|
||||
@@ -357,10 +336,10 @@ function packageDarwin (
|
||||
fs.copySync(packagingDir, packagingOutputDir);
|
||||
|
||||
const view = {
|
||||
applicationName
|
||||
applicationName: meta.__applicationName
|
||||
, manifestName
|
||||
, componentName
|
||||
, packageId: `tf.matt.${applicationName}`
|
||||
, packageId: `tf.matt.${meta.__applicationName}`
|
||||
, executablePath: platformExecutablePath
|
||||
, manifestPath: platformManifestPath
|
||||
};
|
||||
@@ -381,8 +360,8 @@ function packageDarwin (
|
||||
// Build component package
|
||||
spawnSync(`
|
||||
pkgbuild --root ${rootPath} \
|
||||
--identifier "tf.matt.${applicationName}" \
|
||||
--version "${applicationVersion}" \
|
||||
--identifier "tf.matt.${meta.__applicationName}" \
|
||||
--version "${meta.__applicationVersion}" \
|
||||
--scripts ${path.join(packagingOutputDir, "scripts")} \
|
||||
${path.join(BUILD_PATH, componentName)}`
|
||||
, spawnOptions);
|
||||
@@ -415,7 +394,8 @@ function packageLinuxDeb (
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
|
||||
const outputName = `${applicationName}-${applicationVersion}-${arch}.deb`;
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.deb`;
|
||||
|
||||
// Create root
|
||||
const rootPath = path.join(BUILD_PATH, "root");
|
||||
@@ -445,9 +425,9 @@ function packageLinuxDeb (
|
||||
|
||||
const view = {
|
||||
// Debian package names can't contain underscores
|
||||
packageName: applicationName.replace(/_/g, "-")
|
||||
, applicationName
|
||||
, applicationVersion
|
||||
packageName: meta.__applicationName.replace(/_/g, "-")
|
||||
, applicationName: meta.__applicationName
|
||||
, applicationVersion: meta.__applicationVersion
|
||||
, author
|
||||
};
|
||||
|
||||
@@ -479,7 +459,8 @@ function packageLinuxRpm (
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
|
||||
const outputName = `${applicationName}-${applicationVersion}-${arch}.rpm`;
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.rpm`;
|
||||
|
||||
const specPath = path.join(__dirname
|
||||
, "../packaging/linux/rpm/package.spec");
|
||||
@@ -487,9 +468,9 @@ function packageLinuxRpm (
|
||||
const specOutputPath = path.join(BUILD_PATH, path.basename(specPath));
|
||||
|
||||
const view = {
|
||||
packageName: applicationName
|
||||
, applicationName
|
||||
, applicationVersion
|
||||
packageName: meta.__applicationName
|
||||
, applicationName: meta.__applicationName
|
||||
, applicationVersion: meta.__applicationVersion
|
||||
, executablePath: platformExecutablePath
|
||||
, manifestPath: platformManifestPath
|
||||
, executableName: platformExecutableName
|
||||
@@ -532,14 +513,15 @@ function packageWin32 (
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
|
||||
const outputName = `${applicationName}-${applicationVersion}-${arch}.exe`;
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.exe`;
|
||||
|
||||
const scriptPath = path.join(__dirname, "../packaging/win/installer.nsi");
|
||||
const scriptOutputPath = path.join(BUILD_PATH, path.basename(scriptPath));
|
||||
|
||||
const view = {
|
||||
applicationName
|
||||
, applicationVersion
|
||||
applicationName: meta.__applicationName
|
||||
, applicationVersion: meta.__applicationVersion
|
||||
, executableName: platformExecutableName
|
||||
, executablePath: platformExecutablePath
|
||||
, manifestName
|
||||
|
||||
11
app/package-lock.json
generated
11
app/package-lock.json
generated
@@ -187,12 +187,6 @@
|
||||
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/dedent": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/dedent/-/dedent-0.7.0.tgz",
|
||||
"integrity": "sha512-EGlKlgMhnLt/cM4DbUSafFdrkeJoC9Mvnj0PUCU7tFmTjMjNRT957kXCx0wYm3JuEq4o4ZsS5vG+NlkM2DMd2A==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/long": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.0.tgz",
|
||||
@@ -470,11 +464,6 @@
|
||||
"assert-plus": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"dedent": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz",
|
||||
"integrity": "sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw="
|
||||
},
|
||||
"deep-is": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
"bplist-creator": "0.0.8",
|
||||
"bplist-parser": "^0.2.0",
|
||||
"castv2": "^0.1.10",
|
||||
"dedent": "^0.7.0",
|
||||
"fast-srp-hap": "^2.0.2",
|
||||
"mdns": "^2.5.1",
|
||||
"mime-types": "^2.1.27",
|
||||
@@ -22,7 +21,6 @@
|
||||
"tweetnacl": "^1.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dedent": "^0.7.0",
|
||||
"@types/mdns": "0.0.33",
|
||||
"@types/mime-types": "^2.1.0",
|
||||
"@types/node": "^13.13.5",
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
import meta from "../package.json";
|
||||
|
||||
import dedent from "dedent";
|
||||
import path from "path";
|
||||
import minimist from "minimist";
|
||||
|
||||
import * as daemon from "./daemon";
|
||||
|
||||
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
boolean: [ "daemon", "help", "version" ]
|
||||
@@ -25,21 +21,22 @@ const argv = minimist(process.argv.slice(2), {
|
||||
|
||||
|
||||
if (argv.version) {
|
||||
console.log(meta.__applicationVersion);
|
||||
// TODO: Replace this automatically
|
||||
console.log(`v0.0.7`);
|
||||
} else if (argv.help) {
|
||||
console.log(dedent`
|
||||
Usage: ${meta.__applicationExecutableName} [options]
|
||||
console.log(
|
||||
`Usage: ${path.basename(process.argv[0])} [options]
|
||||
|
||||
Options:
|
||||
-h, --help Print usage info
|
||||
-v, --version Print version info
|
||||
-d, --daemon Launch in daemon mode. This starts a WebSocket server that
|
||||
the extension can be configured to connect to under bridge
|
||||
options.
|
||||
-p, --port Set port number for WebSocket server. This must match the
|
||||
port set in the extension options.
|
||||
Options:
|
||||
-h, --help Print usage info
|
||||
-v, --version Print version info
|
||||
-d, --daemon Launch in daemon mode. This starts a WebSocket server that
|
||||
the extension can be configured to connect to under bridge
|
||||
options.
|
||||
-p, --port Set port number for WebSocket server. This must match the
|
||||
port set in the extension options.
|
||||
`);
|
||||
|
||||
`);
|
||||
} else if (argv.daemon) {
|
||||
const port = parseInt(argv.port);
|
||||
if (!port || port < 1025 || port > 65535) {
|
||||
@@ -47,7 +44,10 @@ if (argv.version) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
daemon.init(port);
|
||||
import("./daemon")
|
||||
.then(daemon => {
|
||||
daemon.init(port);
|
||||
});
|
||||
} else {
|
||||
import("./bridge");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user