mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-09 17:19:59 +00:00
Install scripts, build app with rollup & configurable mirror app id
This commit is contained in:
48
app/scripts/build.js
Normal file
48
app/scripts/build.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
require('@babel/register');
|
||||
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
const rollup = require('rollup');
|
||||
|
||||
const config = require('../rollup/rollup.config').default;
|
||||
|
||||
const MANIFEST_NAME = 'fx_cast_bridge.json';
|
||||
|
||||
async function build() {
|
||||
const {path: executablePath, platform, ...configOptions} = argv;
|
||||
|
||||
const {output: bundleOutputs, ...bundleOptions} = config(configOptions);
|
||||
const bundle = await rollup.rollup(bundleOptions);
|
||||
|
||||
for (const output of bundleOutputs) {
|
||||
await bundle.write(output);
|
||||
fs.chmodSync(output.file, '755');
|
||||
}
|
||||
|
||||
const targetPlatform = platform || os.type();
|
||||
const launcherExt = targetPlatform.toLowerCase().startsWith('win')
|
||||
? 'bat'
|
||||
: 'sh';
|
||||
const launcherName = `launcher.${launcherExt}`;
|
||||
const launcherPath = path.join(__dirname, '../../dist', launcherName);
|
||||
|
||||
fs.copyFileSync(path.join(`src`, launcherName), launcherPath);
|
||||
|
||||
const manifest = {
|
||||
...(JSON.parse(fs.readFileSync(`src/${MANIFEST_NAME}`, 'utf8')))
|
||||
, path: (executablePath || path.resolve(launcherPath))
|
||||
};
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join('../dist/app', MANIFEST_NAME)
|
||||
, JSON.stringify(manifest, null, 4)
|
||||
);
|
||||
}
|
||||
|
||||
build().catch(e => {
|
||||
console.log("Build failed", e);
|
||||
process.exit(1);
|
||||
});
|
||||
69
app/scripts/install-manifest.js
Normal file
69
app/scripts/install-manifest.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
const mkdirpSync = require('mkdirp').sync;
|
||||
|
||||
const MANIFEST_NAME = 'fx_cast_bridge.json';
|
||||
const MANIFEST_PATH = path.resolve(__dirname, '../../dist/app', MANIFEST_NAME);
|
||||
|
||||
const WIN_REGISTRY_KEY = 'fx_cast_bridge';
|
||||
|
||||
let destination = argv.destination;
|
||||
|
||||
switch (os.type()) {
|
||||
case 'Darwin': {
|
||||
if (!destination) {
|
||||
const root = argv.root || process.env.HOME;
|
||||
destination = path.resolve(
|
||||
path.join(
|
||||
root
|
||||
, 'Library/Application Support/Mozilla/NativeMessagingHosts'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'Linux': {
|
||||
if (!destination) {
|
||||
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({
|
||||
'HKEY_CURRENT_USER\\SOFTWARE\\Mozilla\\NativeMessagingHosts': {
|
||||
[WIN_REGISTRY_KEY]: {
|
||||
value: destinationManifestPath
|
||||
, type: 'REG_DEFAULT'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
console.error('Sorry, this installer does not yet support your OS');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (destination) {
|
||||
mkdirpSync(destination);
|
||||
fs.copyFileSync(
|
||||
MANIFEST_PATH
|
||||
, path.join(destination, MANIFEST_NAME)
|
||||
);
|
||||
}
|
||||
21
app/scripts/start-debug.js
Normal file
21
app/scripts/start-debug.js
Normal file
@@ -0,0 +1,21 @@
|
||||
require('@babel/register')({
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-env"
|
||||
, {
|
||||
targets: {
|
||||
node: "current"
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
, plugins: [
|
||||
"@babel/plugin-transform-runtime"
|
||||
, "@babel/plugin-syntax-dynamic-import"
|
||||
, "@babel/plugin-syntax-import-meta"
|
||||
, "@babel/plugin-proposal-class-properties"
|
||||
, "@babel/plugin-proposal-json-strings"
|
||||
]
|
||||
});
|
||||
|
||||
require('../src/js/main');
|
||||
Reference in New Issue
Block a user