mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 18:19:58 +00:00
Add prettier and re-format .js files
This commit is contained in:
420
app/bin/build.js
420
app/bin/build.js
@@ -13,40 +13,36 @@ const { spawnSync } = require("child_process");
|
||||
const meta = require("../package.json");
|
||||
const paths = require("./lib/paths");
|
||||
|
||||
const { author
|
||||
, homepage } = require("../../package.json");
|
||||
const { author, homepage } = require("../../package.json");
|
||||
|
||||
|
||||
const EXTENSION_ID = "fx_cast@matt.tf";
|
||||
|
||||
|
||||
// Command line args
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
boolean: [ "usePkg", "package", "skipNativeBuilds" ]
|
||||
, string: [ "arch", "packageType" ]
|
||||
, default: {
|
||||
arch: os.arch()
|
||||
, package: false
|
||||
boolean: ["usePkg", "package", "skipNativeBuilds"],
|
||||
string: ["arch", "packageType"],
|
||||
default: {
|
||||
arch: os.arch(),
|
||||
package: false,
|
||||
// Linux package type (deb/rpm)
|
||||
, packageType: "deb"
|
||||
, skipNativeBuilds: false
|
||||
packageType: "deb",
|
||||
skipNativeBuilds: false
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const supportedTargets = [
|
||||
"win-x64"
|
||||
, "win-x86"
|
||||
, "macos-x64"
|
||||
, "macos-arm64"
|
||||
, "linux-x64"
|
||||
"win-x64",
|
||||
"win-x86",
|
||||
"macos-x64",
|
||||
"macos-arm64",
|
||||
"linux-x64"
|
||||
];
|
||||
|
||||
const supportedPlatforms = [];
|
||||
const supportedArchs = [];
|
||||
|
||||
for (const target of supportedTargets) {
|
||||
const [ platform, arch ] = target.split("-");
|
||||
const [platform, arch] = target.split("-");
|
||||
|
||||
supportedPlatforms.push(platform);
|
||||
supportedArchs.push(arch);
|
||||
@@ -61,14 +57,13 @@ if (!supportedArchs.includes(argv.arch)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
const ROOT_PATH = path.join(__dirname, "..");
|
||||
const SRC_PATH = path.join(ROOT_PATH, "src");
|
||||
const BUILD_PATH = path.join(ROOT_PATH, "build");
|
||||
|
||||
const spawnOptions = {
|
||||
shell: true
|
||||
, stdio: [ process.stdin, process.stdout, process.stderr ]
|
||||
shell: true,
|
||||
stdio: [process.stdin, process.stdout, process.stderr]
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -80,26 +75,29 @@ fs.removeSync(paths.DIST_PATH, { recursive: true });
|
||||
fs.ensureDirSync(BUILD_PATH);
|
||||
fs.ensureDirSync(paths.DIST_PATH, { recursive: true });
|
||||
|
||||
|
||||
const MDNS_BINDING_PATH = path.join(
|
||||
__dirname, "../node_modules/mdns/build/Release/");
|
||||
__dirname,
|
||||
"../node_modules/mdns/build/Release/"
|
||||
);
|
||||
const MDNS_BINDING_NAME = "dns_sd_bindings.node";
|
||||
|
||||
async function build () {
|
||||
async function build() {
|
||||
// Run tsc
|
||||
spawnSync(`tsc --project ${ROOT_PATH} \
|
||||
--outDir ${BUILD_PATH}`
|
||||
, spawnOptions);
|
||||
spawnSync(
|
||||
`tsc --project ${ROOT_PATH}
|
||||
--outDir ${BUILD_PATH}`,
|
||||
spawnOptions
|
||||
);
|
||||
|
||||
/**
|
||||
* Native app manifest
|
||||
* https://mdn.io/Native_manifests#Native_messaging_manifests
|
||||
*/
|
||||
const manifest = {
|
||||
"name": meta.__applicationName
|
||||
, "description": ""
|
||||
, "type": "stdio"
|
||||
, "allowed_extensions": [ EXTENSION_ID ]
|
||||
name: meta.__applicationName,
|
||||
description: "",
|
||||
type: "stdio",
|
||||
allowed_extensions: [EXTENSION_ID]
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -109,63 +107,80 @@ async function build () {
|
||||
if (argv.package || argv.usePkg) {
|
||||
// Need a minimal package.json for pkg.
|
||||
const pkgManifest = {
|
||||
bin: "main.js"
|
||||
, pkg: {
|
||||
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"
|
||||
assets: "../../node_modules/castv2/lib/cast_channel.proto"
|
||||
}
|
||||
};
|
||||
|
||||
const executableName = paths.getExecutableName(process.platform);
|
||||
const executablePath = paths.getExecutablePath(process.platform, argv.arch);
|
||||
const executablePath = paths.getExecutablePath(
|
||||
process.platform,
|
||||
argv.arch
|
||||
);
|
||||
|
||||
// Write pkg manifest
|
||||
fs.writeFileSync(path.join(BUILD_PATH, "src/package.json")
|
||||
, JSON.stringify(pkgManifest))
|
||||
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-${paths.pkgPlatformMap[process.platform]}-${argv.arch}`
|
||||
, "--output", path.join(BUILD_PATH, executableName)
|
||||
path.join(BUILD_PATH, "src"),
|
||||
"--target",
|
||||
`node12-${paths.pkgPlatformMap[process.platform]}-${argv.arch}`,
|
||||
"--output",
|
||||
path.join(BUILD_PATH, executableName)
|
||||
]);
|
||||
|
||||
fs.copySync(path.join(MDNS_BINDING_PATH, MDNS_BINDING_NAME)
|
||||
, path.join(BUILD_PATH, MDNS_BINDING_NAME));
|
||||
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 = !argv.package && argv.usePkg
|
||||
? path.join(paths.DIST_PATH, executableName)
|
||||
: path.join(executablePath, executableName);
|
||||
manifest.path =
|
||||
!argv.package && argv.usePkg
|
||||
? path.join(paths.DIST_PATH, executableName)
|
||||
: path.join(executablePath, executableName);
|
||||
} else {
|
||||
let launcherPath = path.join(BUILD_PATH
|
||||
, meta.__applicationExecutableName);
|
||||
let launcherPath = path.join(
|
||||
BUILD_PATH,
|
||||
meta.__applicationExecutableName
|
||||
);
|
||||
const modulesDir = path.join(ROOT_PATH, "node_modules");
|
||||
|
||||
// Write launcher script
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
launcherPath += ".bat";
|
||||
fs.writeFileSync(launcherPath,
|
||||
`@echo off
|
||||
fs.writeFileSync(
|
||||
launcherPath,
|
||||
`@echo off
|
||||
setlocal
|
||||
set NODE_PATH=${modulesDir}
|
||||
node %~dp0src\\main.js --__name %~n0%~x0 %*
|
||||
endlocal
|
||||
`);
|
||||
`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "linux":
|
||||
case "darwin": {
|
||||
launcherPath += ".sh";
|
||||
fs.writeFileSync(launcherPath,
|
||||
`#!/usr/bin/env sh
|
||||
fs.writeFileSync(
|
||||
launcherPath,
|
||||
`#!/usr/bin/env sh
|
||||
NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0) "$@"
|
||||
`);
|
||||
`
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -173,11 +188,11 @@ NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0)
|
||||
manifest.path = path.join(paths.DIST_PATH, path.basename(launcherPath));
|
||||
}
|
||||
|
||||
|
||||
// Write app manifest
|
||||
fs.writeFileSync(path.join(BUILD_PATH, paths.MANIFEST_NAME)
|
||||
, JSON.stringify(manifest, null, 4));
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(BUILD_PATH, paths.MANIFEST_NAME),
|
||||
JSON.stringify(manifest, null, 4)
|
||||
);
|
||||
|
||||
// Ensure file permissions are correct
|
||||
for (const file of fs.readdirSync(BUILD_PATH)) {
|
||||
@@ -194,19 +209,20 @@ NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0)
|
||||
if (installerName) {
|
||||
// Move installer to dist
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, installerName)
|
||||
, path.join(paths.DIST_PATH, path.basename(installerName))
|
||||
, { overwrite: true });
|
||||
path.join(BUILD_PATH, installerName),
|
||||
path.join(paths.DIST_PATH, path.basename(installerName)),
|
||||
{ overwrite: true }
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Move tsc output and launcher to dist
|
||||
fs.moveSync(BUILD_PATH, paths.DIST_PATH, { overwrite: true });
|
||||
/*
|
||||
spawnSync("npm install --production", {
|
||||
...spawnOptions
|
||||
, cwd: paths.DIST_PATH
|
||||
});
|
||||
*/
|
||||
spawnSync("npm install --production", {
|
||||
...spawnOptions
|
||||
, cwd: paths.DIST_PATH
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
// Remove build directory
|
||||
@@ -217,31 +233,34 @@ NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0)
|
||||
* Takes a platform and returns the path of the created
|
||||
* installer package.
|
||||
*/
|
||||
async function packageApp (platform, arch) {
|
||||
async function packageApp(platform, arch) {
|
||||
const packageFunctionArgs = [
|
||||
arch
|
||||
arch,
|
||||
// platformExecutableName
|
||||
, paths.getExecutableName(platform, arch)
|
||||
paths.getExecutableName(platform, arch),
|
||||
// platformExecutablePath
|
||||
, paths.getExecutablePath(platform, arch)
|
||||
paths.getExecutablePath(platform, arch),
|
||||
// platformManifestPath
|
||||
, paths.getManifestPath(platform, arch, argv.packageType)
|
||||
paths.getManifestPath(platform, arch, argv.packageType)
|
||||
];
|
||||
|
||||
switch (platform) {
|
||||
case "win32": return packageWin32(...packageFunctionArgs);
|
||||
case "darwin": return packageDarwin(...packageFunctionArgs);
|
||||
case "win32":
|
||||
return packageWin32(...packageFunctionArgs);
|
||||
case "darwin":
|
||||
return packageDarwin(...packageFunctionArgs);
|
||||
|
||||
case "linux": {
|
||||
switch (argv.packageType) {
|
||||
case "deb": return packageLinuxDeb(...packageFunctionArgs);
|
||||
case "rpm": return packageLinuxRpm(...packageFunctionArgs);
|
||||
case "deb":
|
||||
return packageLinuxDeb(...packageFunctionArgs);
|
||||
case "rpm":
|
||||
return packageLinuxRpm(...packageFunctionArgs);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default: {
|
||||
console.error("Unsupported target platform");
|
||||
process.exit(1);
|
||||
@@ -262,14 +281,13 @@ async function packageApp (platform, arch) {
|
||||
* Requires the pkgbuild and productbuild command line
|
||||
* utilities. Only possible on macOS.
|
||||
*/
|
||||
function packageDarwin (
|
||||
arch
|
||||
, platformExecutableName
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.pkg`;
|
||||
function packageDarwin(
|
||||
arch,
|
||||
platformExecutableName,
|
||||
platformExecutablePath,
|
||||
platformManifestPath
|
||||
) {
|
||||
const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.pkg`;
|
||||
const componentName = `${meta.__applicationName}_component.pkg`;
|
||||
|
||||
const packagingDir = path.join(__dirname, "../packaging/mac/");
|
||||
@@ -285,30 +303,35 @@ function packageDarwin (
|
||||
fs.ensureDirSync(rootManifestPath, { recursive: true });
|
||||
|
||||
// Move files to root
|
||||
fs.moveSync(path.join(BUILD_PATH, platformExecutableName)
|
||||
, path.join(rootExecutablePath, platformExecutableName));
|
||||
fs.moveSync(path.join(BUILD_PATH, MDNS_BINDING_NAME)
|
||||
, path.join(rootExecutablePath, MDNS_BINDING_NAME));
|
||||
fs.moveSync(path.join(BUILD_PATH, paths.MANIFEST_NAME)
|
||||
, path.join(rootManifestPath, paths.MANIFEST_NAME));
|
||||
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, platformExecutableName),
|
||||
path.join(rootExecutablePath, platformExecutableName)
|
||||
);
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, MDNS_BINDING_NAME),
|
||||
path.join(rootExecutablePath, MDNS_BINDING_NAME)
|
||||
);
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, paths.MANIFEST_NAME),
|
||||
path.join(rootManifestPath, paths.MANIFEST_NAME)
|
||||
);
|
||||
|
||||
// Copy static files to be processed
|
||||
fs.copySync(packagingDir, packagingOutputDir);
|
||||
|
||||
const view = {
|
||||
applicationName: meta.__applicationName
|
||||
, manifestName: paths.MANIFEST_NAME
|
||||
, componentName
|
||||
, packageId: `tf.matt.${meta.__applicationName}`
|
||||
, executablePath: platformExecutablePath
|
||||
, manifestPath: platformManifestPath
|
||||
applicationName: meta.__applicationName,
|
||||
manifestName: paths.MANIFEST_NAME,
|
||||
componentName,
|
||||
packageId: `tf.matt.${meta.__applicationName}`,
|
||||
executablePath: platformExecutablePath,
|
||||
manifestPath: platformManifestPath
|
||||
};
|
||||
|
||||
// Template paths
|
||||
const templatePaths = [
|
||||
path.join(packagingOutputDir, "scripts/postinstall")
|
||||
, path.join(packagingOutputDir, "distribution.xml")
|
||||
path.join(packagingOutputDir, "scripts/postinstall"),
|
||||
path.join(packagingOutputDir, "distribution.xml")
|
||||
];
|
||||
|
||||
// Do templating on static files
|
||||
@@ -317,25 +340,26 @@ function packageDarwin (
|
||||
fs.writeFileSync(templatePath, mustache.render(templateContent, view));
|
||||
}
|
||||
|
||||
|
||||
// Build component package
|
||||
spawnSync(`
|
||||
pkgbuild --root ${rootPath} \
|
||||
--identifier "tf.matt.${meta.__applicationName}" \
|
||||
--version "${meta.__applicationVersion}" \
|
||||
--scripts ${path.join(packagingOutputDir, "scripts")} \
|
||||
${path.join(BUILD_PATH, componentName)}`
|
||||
, spawnOptions);
|
||||
spawnSync(
|
||||
`pkgbuild --root ${rootPath} \
|
||||
--identifier "tf.matt.${meta.__applicationName}" \
|
||||
--version "${meta.__applicationVersion}" \
|
||||
--scripts ${path.join(packagingOutputDir, "scripts")} \
|
||||
${path.join(BUILD_PATH, componentName)}`,
|
||||
spawnOptions
|
||||
);
|
||||
|
||||
// Distribution XML file
|
||||
const distFilePath = path.join(packagingOutputDir, "distribution.xml");
|
||||
|
||||
// Build installer package
|
||||
spawnSync(`
|
||||
productbuild --distribution ${distFilePath} \
|
||||
--package-path ${BUILD_PATH} \
|
||||
${path.join(BUILD_PATH, outputName)}`
|
||||
, spawnOptions);
|
||||
spawnSync(
|
||||
`productbuild --distribution ${distFilePath} \
|
||||
--package-path ${BUILD_PATH} \
|
||||
${path.join(BUILD_PATH, outputName)}`,
|
||||
spawnOptions
|
||||
);
|
||||
|
||||
return outputName;
|
||||
}
|
||||
@@ -347,16 +371,15 @@ function packageDarwin (
|
||||
* structure for package files, copies control file
|
||||
* (packaging/linux/deb/DEBIAN/control) to root, then builds
|
||||
* package from root.
|
||||
* Requires the dpkg-deb command line utility.
|
||||
* Requires the dpkg-deb command line utility.
|
||||
*/
|
||||
function packageLinuxDeb (
|
||||
arch
|
||||
, platformExecutableName
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.deb`;
|
||||
function packageLinuxDeb(
|
||||
arch,
|
||||
platformExecutableName,
|
||||
platformExecutablePath,
|
||||
platformManifestPath
|
||||
) {
|
||||
const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.deb`;
|
||||
|
||||
// Create root
|
||||
const rootPath = path.join(BUILD_PATH, "root");
|
||||
@@ -367,12 +390,18 @@ function packageLinuxDeb (
|
||||
fs.ensureDirSync(rootManifestPath, { recursive: true });
|
||||
|
||||
// Move files to root
|
||||
fs.moveSync(path.join(BUILD_PATH, platformExecutableName)
|
||||
, path.join(rootExecutablePath, platformExecutableName));
|
||||
fs.moveSync(path.join(BUILD_PATH, MDNS_BINDING_NAME)
|
||||
, path.join(rootExecutablePath, MDNS_BINDING_NAME));
|
||||
fs.moveSync(path.join(BUILD_PATH, paths.MANIFEST_NAME)
|
||||
, path.join(rootManifestPath, paths.MANIFEST_NAME));
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, platformExecutableName),
|
||||
path.join(rootExecutablePath, platformExecutableName)
|
||||
);
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, MDNS_BINDING_NAME),
|
||||
path.join(rootExecutablePath, MDNS_BINDING_NAME)
|
||||
);
|
||||
fs.moveSync(
|
||||
path.join(BUILD_PATH, paths.MANIFEST_NAME),
|
||||
path.join(rootManifestPath, paths.MANIFEST_NAME)
|
||||
);
|
||||
|
||||
const controlDir = path.join(__dirname, "../packaging/linux/deb/DEBIAN/");
|
||||
const controlOutputDir = path.join(rootPath, path.basename(controlDir));
|
||||
@@ -383,23 +412,24 @@ function packageLinuxDeb (
|
||||
|
||||
const view = {
|
||||
// Debian package names can't contain underscores
|
||||
packageName: meta.__applicationName.replace(/_/g, "-")
|
||||
, applicationName: meta.__applicationName
|
||||
, applicationVersion: meta.__applicationVersion
|
||||
, author
|
||||
packageName: meta.__applicationName.replace(/_/g, "-"),
|
||||
applicationName: meta.__applicationName,
|
||||
applicationVersion: meta.__applicationVersion,
|
||||
author
|
||||
};
|
||||
|
||||
// Do templating on control file
|
||||
fs.writeFileSync(controlFilePath
|
||||
, mustache.render(
|
||||
fs.readFileSync(controlFilePath).toString()
|
||||
, view));
|
||||
fs.writeFileSync(
|
||||
controlFilePath,
|
||||
mustache.render(fs.readFileSync(controlFilePath).toString(), view)
|
||||
);
|
||||
|
||||
// Build .deb package
|
||||
spawnSync(`
|
||||
dpkg-deb --build ${rootPath} \
|
||||
${path.join(BUILD_PATH, outputName)}`
|
||||
, spawnOptions);
|
||||
spawnSync(
|
||||
`dpkg-deb --build ${rootPath} \
|
||||
${path.join(BUILD_PATH, outputName)}`,
|
||||
spawnOptions
|
||||
);
|
||||
|
||||
return outputName;
|
||||
}
|
||||
@@ -411,48 +441,47 @@ function packageLinuxDeb (
|
||||
* (packaging/linux/rpm/package.spec) to build the package.
|
||||
* Requires the rpmbuild command line utility.
|
||||
*/
|
||||
function packageLinuxRpm (
|
||||
arch
|
||||
, platformExecutableName
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
function packageLinuxRpm(
|
||||
arch,
|
||||
platformExecutableName,
|
||||
platformExecutablePath,
|
||||
platformManifestPath
|
||||
) {
|
||||
const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.rpm`;
|
||||
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.rpm`;
|
||||
|
||||
const specPath = path.join(__dirname
|
||||
, "../packaging/linux/rpm/package.spec");
|
||||
const specPath = path.join(
|
||||
__dirname,
|
||||
"../packaging/linux/rpm/package.spec"
|
||||
);
|
||||
|
||||
const specOutputPath = path.join(BUILD_PATH, path.basename(specPath));
|
||||
|
||||
const view = {
|
||||
packageName: meta.__applicationName
|
||||
, applicationName: meta.__applicationName
|
||||
, applicationVersion: meta.__applicationVersion
|
||||
, executablePath: platformExecutablePath
|
||||
, manifestPath: platformManifestPath
|
||||
, executableName: platformExecutableName
|
||||
, manifestName: paths.MANIFEST_NAME
|
||||
, bindingName: MDNS_BINDING_NAME
|
||||
packageName: meta.__applicationName,
|
||||
applicationName: meta.__applicationName,
|
||||
applicationVersion: meta.__applicationVersion,
|
||||
executablePath: platformExecutablePath,
|
||||
manifestPath: platformManifestPath,
|
||||
executableName: platformExecutableName,
|
||||
manifestName: paths.MANIFEST_NAME,
|
||||
bindingName: MDNS_BINDING_NAME
|
||||
};
|
||||
|
||||
fs.writeFileSync(specOutputPath
|
||||
, mustache.render(
|
||||
fs.readFileSync(specPath).toString()
|
||||
, view));
|
||||
fs.writeFileSync(
|
||||
specOutputPath,
|
||||
mustache.render(fs.readFileSync(specPath).toString(), view)
|
||||
);
|
||||
|
||||
const rpmArchMap = {
|
||||
"x86": "i386"
|
||||
, "x64": "x86_64"
|
||||
};
|
||||
const rpmArchMap = { x86: "i386", x64: "x86_64" };
|
||||
|
||||
spawnSync(`
|
||||
rpmbuild -bb ${specOutputPath} \
|
||||
--define "_distdir ${BUILD_PATH}" \
|
||||
--define "_rpmdir ${BUILD_PATH}" \
|
||||
--define "_rpmfilename ${outputName}" \
|
||||
--target=${rpmArchMap[arch]}-linux`
|
||||
, spawnOptions);
|
||||
spawnSync(
|
||||
`rpmbuild -bb ${specOutputPath} \
|
||||
--define "_distdir ${BUILD_PATH}" \
|
||||
--define "_rpmdir ${BUILD_PATH}" \
|
||||
--define "_rpmfilename ${outputName}" \
|
||||
--target=${rpmArchMap[arch]}-linux`,
|
||||
spawnOptions
|
||||
);
|
||||
|
||||
return outputName;
|
||||
}
|
||||
@@ -464,47 +493,44 @@ function packageLinuxRpm (
|
||||
* script (packaging/win/installer.nsi). Requires the
|
||||
* makensis command line utility.
|
||||
*/
|
||||
function packageWin32 (
|
||||
arch
|
||||
, platformExecutableName
|
||||
, platformExecutablePath
|
||||
, platformManifestPath) {
|
||||
|
||||
const outputName = `${meta.__applicationName}-${
|
||||
meta.__applicationVersion}-${arch}.exe`;
|
||||
function packageWin32(
|
||||
arch,
|
||||
platformExecutableName,
|
||||
platformExecutablePath,
|
||||
platformManifestPath
|
||||
) {
|
||||
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: meta.__applicationName
|
||||
, applicationVersion: meta.__applicationVersion
|
||||
, executableName: platformExecutableName
|
||||
, executablePath: platformExecutablePath
|
||||
, manifestName: paths.MANIFEST_NAME
|
||||
, bindingName: MDNS_BINDING_NAME
|
||||
, winRegistryKey: paths.REGISTRY_KEY
|
||||
, outputName
|
||||
, licensePath: paths.LICENSE_PATH
|
||||
applicationName: meta.__applicationName,
|
||||
applicationVersion: meta.__applicationVersion,
|
||||
executableName: platformExecutableName,
|
||||
executablePath: platformExecutablePath,
|
||||
manifestName: paths.MANIFEST_NAME,
|
||||
bindingName: MDNS_BINDING_NAME,
|
||||
winRegistryKey: paths.REGISTRY_KEY,
|
||||
outputName,
|
||||
licensePath: paths.LICENSE_PATH,
|
||||
|
||||
// Uninstaller keys
|
||||
, registryPublisher: author
|
||||
, registryUrlInfoAbout: homepage
|
||||
registryPublisher: author,
|
||||
registryUrlInfoAbout: homepage
|
||||
};
|
||||
|
||||
// Write templated script to build dir
|
||||
fs.writeFileSync(scriptOutputPath
|
||||
, mustache.render(
|
||||
fs.readFileSync(scriptPath).toString()
|
||||
, view));
|
||||
fs.writeFileSync(
|
||||
scriptOutputPath,
|
||||
mustache.render(fs.readFileSync(scriptPath).toString(), view)
|
||||
);
|
||||
|
||||
spawnSync(`makensis /DARCH=${arch} ${scriptOutputPath}`
|
||||
, spawnOptions);
|
||||
spawnSync(`makensis /DARCH=${arch} ${scriptOutputPath}`, spawnOptions);
|
||||
|
||||
return outputName;
|
||||
}
|
||||
|
||||
|
||||
build().catch(e => {
|
||||
console.log("Build failed", e);
|
||||
process.exit(1);
|
||||
|
||||
@@ -5,24 +5,20 @@ const minimist = require("minimist");
|
||||
|
||||
const paths = require("./lib/paths");
|
||||
|
||||
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
boolean: [ "remove" ]
|
||||
, default: {
|
||||
boolean: ["remove"],
|
||||
default: {
|
||||
remove: false
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const CURRENT_MANIFEST_PATH = path.join(paths.DIST_PATH, paths.MANIFEST_NAME);
|
||||
|
||||
|
||||
if (!fs.existsSync(CURRENT_MANIFEST_PATH) && !argv.remove) {
|
||||
console.error("No manifest in dist/app/ to install.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
const platform = os.platform();
|
||||
const arch = os.arch();
|
||||
|
||||
@@ -30,9 +26,12 @@ switch (platform) {
|
||||
case "darwin":
|
||||
case "linux": {
|
||||
// Manifest location within home directory
|
||||
const destination = path.join(os.homedir(), platform === "linux"
|
||||
? ".mozilla/native-messaging-hosts/"
|
||||
: paths.getManifestPath(platform, arch));
|
||||
const destination = path.join(
|
||||
os.homedir(),
|
||||
platform === "linux"
|
||||
? ".mozilla/native-messaging-hosts/"
|
||||
: paths.getManifestPath(platform, arch)
|
||||
);
|
||||
|
||||
if (argv.remove) {
|
||||
fs.remove(path.join(destination, paths.MANIFEST_NAME));
|
||||
@@ -41,11 +40,13 @@ switch (platform) {
|
||||
|
||||
// Install manifest
|
||||
fs.ensureDirSync(destination);
|
||||
fs.copyFileSync(CURRENT_MANIFEST_PATH
|
||||
, path.join(destination, paths.MANIFEST_NAME));
|
||||
fs.copyFileSync(
|
||||
CURRENT_MANIFEST_PATH,
|
||||
path.join(destination, paths.MANIFEST_NAME)
|
||||
);
|
||||
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
case "win32": {
|
||||
const { Registry } = require("rage-edit");
|
||||
@@ -56,14 +57,10 @@ switch (platform) {
|
||||
break;
|
||||
}
|
||||
|
||||
Registry.set(
|
||||
REGISTRY_PATH
|
||||
, ""
|
||||
, CURRENT_MANIFEST_PATH
|
||||
, "REG_SZ");
|
||||
Registry.set(REGISTRY_PATH, "", CURRENT_MANIFEST_PATH, "REG_SZ");
|
||||
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
console.error("Sorry, this installer does not yet support your OS");
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const { __applicationName
|
||||
, __applicationDirectoryName
|
||||
, __applicationExecutableName } = require("../../package.json");
|
||||
|
||||
const {
|
||||
__applicationName,
|
||||
__applicationDirectoryName,
|
||||
__applicationExecutableName
|
||||
} = require("../../package.json");
|
||||
|
||||
const rootPath = path.join(__dirname, "../../../");
|
||||
|
||||
@@ -15,9 +16,9 @@ exports.LICENSE_PATH = path.join(rootPath, "LICENSE");
|
||||
exports.REGISTRY_KEY = __applicationName;
|
||||
|
||||
exports.pkgPlatformMap = {
|
||||
win32: "win"
|
||||
, darwin: "macos"
|
||||
, linux: "linux"
|
||||
win32: "win",
|
||||
darwin: "macos",
|
||||
linux: "linux"
|
||||
};
|
||||
|
||||
exports.MANIFEST_NAME = `${__applicationName}.json`;
|
||||
@@ -30,7 +31,7 @@ exports.getExecutableName = platform => {
|
||||
case "linux":
|
||||
return __applicationExecutableName;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.getExecutablePath = (platform, arch) => {
|
||||
const EXECUTABLE_PATH_WIN32_X64 = `C:\\Program Files\\${__applicationDirectoryName}\\`;
|
||||
@@ -41,32 +42,42 @@ exports.getExecutablePath = (platform, arch) => {
|
||||
switch (platform) {
|
||||
case "win32":
|
||||
switch (arch) {
|
||||
case "x86": return EXECUTABLE_PATH_WIN32_X86;
|
||||
case "x64": return EXECUTABLE_PATH_WIN32_X64;
|
||||
case "x86":
|
||||
return EXECUTABLE_PATH_WIN32_X86;
|
||||
case "x64":
|
||||
return EXECUTABLE_PATH_WIN32_X64;
|
||||
}
|
||||
break;
|
||||
case "darwin": return EXECUTABLE_PATH_DARWIN;
|
||||
case "linux": return EXECUTABLE_PATH_LINUX;
|
||||
case "darwin":
|
||||
return EXECUTABLE_PATH_DARWIN;
|
||||
case "linux":
|
||||
return EXECUTABLE_PATH_LINUX;
|
||||
}
|
||||
};
|
||||
|
||||
exports.getManifestPath = (platform, arch, linuxPackageType) => {
|
||||
const MANIFEST_PATH_DARWIN = "/Library/Application Support/Mozilla/NativeMessagingHosts/";
|
||||
const MANIFEST_PATH_DARWIN =
|
||||
"/Library/Application Support/Mozilla/NativeMessagingHosts/";
|
||||
const MANIFEST_PATH_LINUX_DEB = "/usr/lib/mozilla/native-messaging-hosts/";
|
||||
const MANIFEST_PATH_LINUX_RPM ="/usr/lib64/mozilla/native-messaging-hosts/";
|
||||
const MANIFEST_PATH_LINUX_RPM =
|
||||
"/usr/lib64/mozilla/native-messaging-hosts/";
|
||||
|
||||
switch (platform) {
|
||||
case "win32":
|
||||
switch (arch) {
|
||||
case "x86":
|
||||
case "x64": return exports.getExecutablePath(platform, arch);
|
||||
case "x64":
|
||||
return exports.getExecutablePath(platform, arch);
|
||||
}
|
||||
break;
|
||||
case "darwin": return MANIFEST_PATH_DARWIN;
|
||||
case "darwin":
|
||||
return MANIFEST_PATH_DARWIN;
|
||||
case "linux":
|
||||
switch (linuxPackageType) {
|
||||
case "deb": return MANIFEST_PATH_LINUX_DEB;
|
||||
case "rpm": return MANIFEST_PATH_LINUX_RPM;
|
||||
case "deb":
|
||||
return MANIFEST_PATH_LINUX_DEB;
|
||||
case "rpm":
|
||||
return MANIFEST_PATH_LINUX_RPM;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
2074
app/package-lock.json
generated
2074
app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user