mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 02:29:59 +00:00
Fix install-manifest script + create product archive from component pkg
This commit is contained in:
@@ -5,43 +5,21 @@ const path = require("path");
|
|||||||
const { spawnSync } = require("child_process");
|
const { spawnSync } = require("child_process");
|
||||||
const { exec: pkgExec } = require("pkg");
|
const { exec: pkgExec } = require("pkg");
|
||||||
|
|
||||||
|
const { executableName
|
||||||
|
, executablePath
|
||||||
|
, manifestName
|
||||||
|
, manifestPath
|
||||||
|
, pkgPlatform
|
||||||
|
, DIST_DIR_PATH } = require("./lib/paths");
|
||||||
|
|
||||||
const argv = require("minimist")(process.argv.slice(2));
|
const argv = require("minimist")(process.argv.slice(2));
|
||||||
|
|
||||||
|
|
||||||
const MANIFEST_NAME = "fx_cast_bridge.json";
|
|
||||||
|
|
||||||
const BUILD_DIR_PATH = path.join(__dirname, "../build");
|
const BUILD_DIR_PATH = path.join(__dirname, "../build");
|
||||||
const DIST_DIR_PATH = path.join(__dirname, "../../dist/app");
|
|
||||||
|
|
||||||
try {
|
// Make directories
|
||||||
// Make directories
|
fs.ensureDirSync(BUILD_DIR_PATH);
|
||||||
fs.mkdirSync(BUILD_DIR_PATH);
|
fs.ensureDirSync(DIST_DIR_PATH, { recursive: true });
|
||||||
fs.mkdirSync(DIST_DIR_PATH, { recursive: true });
|
|
||||||
} catch (err) {}
|
|
||||||
|
|
||||||
|
|
||||||
const executableName = {
|
|
||||||
win32: "bridge.exe"
|
|
||||||
, darwin: "bridge"
|
|
||||||
, linux: "bridge"
|
|
||||||
};
|
|
||||||
|
|
||||||
const executablePath = {
|
|
||||||
win32: "C:\\Program Files\\fx_cast\\"
|
|
||||||
, darwin: "/Library/Application Support/fx_cast/"
|
|
||||||
, linux: "/opt/fx_cast/"
|
|
||||||
};
|
|
||||||
|
|
||||||
const manifestPath = {
|
|
||||||
darwin: "/Library/Application Support/Mozilla/NativeMessagingHosts/"
|
|
||||||
, linux: "/usr/lib/mozilla/native-messaging-hosts/"
|
|
||||||
};
|
|
||||||
|
|
||||||
const pkgPlatform = {
|
|
||||||
win32: "win"
|
|
||||||
, darwin: "macos"
|
|
||||||
, linux: "linux"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
async function build () {
|
async function build () {
|
||||||
@@ -51,14 +29,14 @@ async function build () {
|
|||||||
spawnSync(`babel src -d ${BUILD_DIR_PATH} --copy-files `
|
spawnSync(`babel src -d ${BUILD_DIR_PATH} --copy-files `
|
||||||
, { shell: true });
|
, { shell: true });
|
||||||
|
|
||||||
// Add build platform's executable path to the manifest
|
// Add either installed path or dist path to app manifest
|
||||||
const manifest = {
|
const manifest = JSON.parse(fs.readFileSync(manifestName, "utf8"));
|
||||||
...(JSON.parse(fs.readFileSync(MANIFEST_NAME, "utf8")))
|
manifest.path = argv.package
|
||||||
, path: path.join(executablePath[platform], executableName[platform])
|
? path.join(executablePath[platform], executableName[platform])
|
||||||
};
|
: path.join(DIST_DIR_PATH, executableName[platform]);
|
||||||
|
|
||||||
// Write manifest
|
// Write manifest
|
||||||
fs.writeFileSync(path.join(BUILD_DIR_PATH, MANIFEST_NAME)
|
fs.writeFileSync(path.join(BUILD_DIR_PATH, manifestName)
|
||||||
, JSON.stringify(manifest, null, 4));
|
, JSON.stringify(manifest, null, 4));
|
||||||
|
|
||||||
|
|
||||||
@@ -97,8 +75,8 @@ async function build () {
|
|||||||
, { overwrite: true });
|
, { overwrite: true });
|
||||||
} else {
|
} else {
|
||||||
// Move binary / app manifest
|
// Move binary / app manifest
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, MANIFEST_NAME)
|
fs.moveSync(path.join(BUILD_DIR_PATH, manifestName)
|
||||||
, path.join(DIST_DIR_PATH, MANIFEST_NAME)
|
, path.join(DIST_DIR_PATH, manifestName)
|
||||||
, { overwrite: true });
|
, { overwrite: true });
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, executableName[platform])
|
fs.moveSync(path.join(BUILD_DIR_PATH, executableName[platform])
|
||||||
, path.join(DIST_DIR_PATH, executableName[platform])
|
, path.join(DIST_DIR_PATH, executableName[platform])
|
||||||
@@ -113,6 +91,9 @@ async function buildInstaller (platform) {
|
|||||||
switch (platform) {
|
switch (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 installerPath = path.join(BUILD_DIR_PATH, installerName);
|
||||||
|
const componentPath = path.join(BUILD_DIR_PATH, componentName);
|
||||||
|
|
||||||
// Create pkgbuild root
|
// Create pkgbuild root
|
||||||
const rootPath = path.join(BUILD_DIR_PATH, "root");
|
const rootPath = path.join(BUILD_DIR_PATH, "root");
|
||||||
@@ -122,21 +103,31 @@ async function buildInstaller (platform) {
|
|||||||
, manifestPath[platform]);
|
, manifestPath[platform]);
|
||||||
|
|
||||||
// Create install locations
|
// Create install locations
|
||||||
fs.mkdirSync(rootExecutablePath, { recursive: true });
|
fs.ensureDirSync(rootExecutablePath, { recursive: true });
|
||||||
fs.mkdirSync(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_DIR_PATH, executableName[platform])
|
||||||
, path.join(rootExecutablePath, executableName[platform]));
|
, path.join(rootExecutablePath, executableName[platform]));
|
||||||
fs.moveSync(path.join(BUILD_DIR_PATH, MANIFEST_NAME)
|
fs.moveSync(path.join(BUILD_DIR_PATH, manifestName)
|
||||||
, path.join(rootManifestPath, MANIFEST_NAME));
|
, path.join(rootManifestPath, manifestName));
|
||||||
|
|
||||||
// Build installer package
|
// Build component package
|
||||||
spawnSync(
|
spawnSync(
|
||||||
`pkgbuild --root ${rootPath} `
|
`pkgbuild --root ${rootPath} `
|
||||||
+ `--identifier "tf.matt.fx_cast_bridge" `
|
+ `--identifier "tf.matt.fx_cast_bridge" `
|
||||||
+ `--version "0.0.1" `
|
+ `--version "0.0.1" `
|
||||||
+ `${path.join(BUILD_DIR_PATH, installerName)}`
|
+ `${componentPath}`
|
||||||
|
, { shell: true });
|
||||||
|
|
||||||
|
// Distribution XML file
|
||||||
|
const distFilePath = path.join(__dirname, "../distribution.xml");
|
||||||
|
|
||||||
|
// Build installer package
|
||||||
|
spawnSync(
|
||||||
|
`productbuild --distribution ${distFilePath} `
|
||||||
|
+ `--package-path ${componentPath} `
|
||||||
|
+ `${installerPath}`
|
||||||
, { shell: true });
|
, { shell: true });
|
||||||
|
|
||||||
return installerName;
|
return installerName;
|
||||||
|
|||||||
@@ -1,69 +1,55 @@
|
|||||||
const fs = require('fs');
|
const fs = require("fs-extra");
|
||||||
const os = require('os');
|
const os = require("os");
|
||||||
const path = require('path');
|
const path = require("path");
|
||||||
|
|
||||||
const argv = require('minimist')(process.argv.slice(2));
|
const { executableName
|
||||||
const mkdirpSync = require('mkdirp').sync;
|
, executablePath
|
||||||
|
, manifestName
|
||||||
|
, manifestPath
|
||||||
|
, DIST_DIR_PATH } = require("./lib/paths");
|
||||||
|
|
||||||
const MANIFEST_NAME = 'fx_cast_bridge.json';
|
const argv = require("minimist")(process.argv.slice(2));
|
||||||
const MANIFEST_PATH = path.resolve(__dirname, '../../dist/app', MANIFEST_NAME);
|
|
||||||
|
|
||||||
const WIN_REGISTRY_KEY = 'fx_cast_bridge';
|
|
||||||
|
|
||||||
let destination = argv.destination;
|
const CURRENT_MANIFEST_PATH = path.join(DIST_DIR_PATH, manifestName);
|
||||||
|
const WIN_REGISTRY_KEY = "fx_cast_bridge";
|
||||||
|
|
||||||
switch (os.type()) {
|
|
||||||
case 'Darwin': {
|
if (!fs.existsSync(CURRENT_MANIFEST_PATH)) {
|
||||||
if (!destination) {
|
console.error("No manifest in dist/app/ to install");
|
||||||
const root = argv.root || process.env.HOME;
|
process.exit(1);
|
||||||
destination = path.resolve(
|
}
|
||||||
path.join(
|
|
||||||
root
|
const platform = os.platform();
|
||||||
, 'Library/Application Support/Mozilla/NativeMessagingHosts'
|
|
||||||
)
|
switch (platform) {
|
||||||
);
|
case "darwin":
|
||||||
}
|
case "linux": {
|
||||||
|
const destination = path.join(os.homedir(), manifestPath[platform]);
|
||||||
|
|
||||||
|
fs.ensureDirSync(destination);
|
||||||
|
fs.copyFileSync(CURRENT_MANIFEST_PATH
|
||||||
|
, path.join(destination, manifestName));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
};
|
||||||
|
|
||||||
case 'Linux': {
|
case "win32": {
|
||||||
if (!destination) {
|
const regedit = require("regedit");
|
||||||
const root = argv.root || `${process.env.HOME}/.`;
|
|
||||||
destination = root.endsWith('/.')
|
|
||||||
? `${root}mozilla/native-messaging-hosts/`
|
|
||||||
: path.join(root, 'mozilla/native-messaging-hosts/');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'Windows_NT': {
|
|
||||||
const regedit = require('regedit');
|
|
||||||
const destinationManifestPath = path.join(destination, MANIFEST_NAME)
|
|
||||||
|| MANIFEST_PATH;
|
|
||||||
|
|
||||||
regedit.putValue({
|
regedit.putValue({
|
||||||
'HKEY_CURRENT_USER\\SOFTWARE\\Mozilla\\NativeMessagingHosts': {
|
"HKEY_CURRENT_USER\\SOFTWARE\\Mozilla\\NativeMessagingHosts": {
|
||||||
[WIN_REGISTRY_KEY]: {
|
[WIN_REGISTRY_KEY]: {
|
||||||
value: destinationManifestPath
|
value: CURRENT_MANIFEST_PATH
|
||||||
, type: 'REG_DEFAULT'
|
, type: "REG_DEFAULT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.error('Sorry, this installer does not yet support your OS');
|
console.error("Sorry, this installer does not yet support your OS");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destination) {
|
|
||||||
mkdirpSync(destination);
|
|
||||||
fs.copyFileSync(
|
|
||||||
MANIFEST_PATH
|
|
||||||
, path.join(destination, MANIFEST_NAME)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
29
app/bin/lib/paths.js
Normal file
29
app/bin/lib/paths.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
exports.DIST_DIR_PATH = path.join(__dirname, "../../../dist/app");
|
||||||
|
|
||||||
|
exports.executableName = {
|
||||||
|
win32: "bridge.exe"
|
||||||
|
, darwin: "bridge"
|
||||||
|
, linux: "bridge"
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.executablePath = {
|
||||||
|
win32: "C:\\Program Files\\fx_cast\\"
|
||||||
|
, darwin: "/Library/Application Support/fx_cast/"
|
||||||
|
, linux: "/opt/fx_cast/"
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.manifestName = "fx_cast_bridge.json";
|
||||||
|
|
||||||
|
exports.manifestPath = {
|
||||||
|
darwin: "/Library/Application Support/Mozilla/NativeMessagingHosts/"
|
||||||
|
, linux: ".mozilla/native-messaging-hosts/"
|
||||||
|
, win32: "C:\\Program Files\\fx_cast\\"
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.pkgPlatform = {
|
||||||
|
win32: "win"
|
||||||
|
, darwin: "macos"
|
||||||
|
, linux: "linux"
|
||||||
|
};
|
||||||
17
app/distribution.xml
Normal file
17
app/distribution.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<installer-gui-script minSpecVersion="1">
|
||||||
|
<title>fx_cast Bridge</title>
|
||||||
|
<domains enable_anywhere="false" enable_currentUserHome="true" enable_localSystem="true" />
|
||||||
|
<pkg-ref id="tf.matt.fx_cast_bridge"/>
|
||||||
|
<options customize="never" require-scripts="false"/>
|
||||||
|
<choices-outline>
|
||||||
|
<line choice="default">
|
||||||
|
<line choice="tf.matt.fx_cast_bridge"/>
|
||||||
|
</line>
|
||||||
|
</choices-outline>
|
||||||
|
<choice id="default"/>
|
||||||
|
<choice id="tf.matt.fx_cast_bridge" visible="false">
|
||||||
|
<pkg-ref id="tf.matt.fx_cast_bridge"/>
|
||||||
|
</choice>
|
||||||
|
<pkg-ref id="tf.matt.fx_cast_bridge" version="0.0.1" onConclusion="none">fx_cast_bridge.pkg</pkg-ref>
|
||||||
|
</installer-gui-script>
|
||||||
Reference in New Issue
Block a user