Generate native manifest in code

This commit is contained in:
hensm
2018-12-11 21:02:33 +00:00
parent 88a5c68a1b
commit c555d72a0d
2 changed files with 34 additions and 32 deletions

View File

@@ -11,6 +11,8 @@ const { exec: pkgExec } = require("pkg");
const { __applicationName: applicationName const { __applicationName: applicationName
, __applicationVersion: applicationVersion } = require("../package.json"); , __applicationVersion: applicationVersion } = require("../package.json");
const { __extensionId: extensionId } = require("../../ext/package.json");
const { executableName const { executableName
, executablePath , executablePath
, manifestName , manifestName
@@ -47,11 +49,18 @@ async function build () {
spawnSync(`babel src -d ${BUILD_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 // Create app manifest
const manifest = JSON.parse(fs.readFileSync(manifestName, "utf8")); const manifest = {
manifest.path = argv.package "name": applicationName
? path.join(executablePath[argv.platform], executableName[argv.platform]) , "description": ""
: path.join(DIST_PATH, executableName[argv.platform]); , "type": "stdio"
, "allowed_extensions": [ extensionId ]
, "path": argv.package
// Add either installed path or dist path
? path.join(executablePath[argv.platform]
, executableName[argv.platform])
: path.join(DIST_PATH, executableName[argv.platform])
};
// Write manifest // Write manifest
fs.writeFileSync(path.join(BUILD_PATH, manifestName) fs.writeFileSync(path.join(BUILD_PATH, manifestName)
@@ -64,9 +73,8 @@ async function build () {
} }
const pkgInfo = { const pkgManifest = {
name: "bridge" bin: "main.js"
, bin: "main.js"
, pkg: { , pkg: {
// Workaround for pkg asset detection // Workaround for pkg asset detection
// https://github.com/thibauts/node-castv2/issues/46 // https://github.com/thibauts/node-castv2/issues/46
@@ -75,7 +83,7 @@ async function build () {
}; };
fs.writeFileSync(path.join(BUILD_PATH, "package.json") fs.writeFileSync(path.join(BUILD_PATH, "package.json")
, JSON.stringify(pkgInfo)) , JSON.stringify(pkgManifest))
// Package executable // Package executable
await pkgExec([ await pkgExec([
@@ -111,14 +119,14 @@ async function build () {
function package (platform) { function package (platform) {
switch (platform) { switch (platform) {
case "darwin": case "darwin":
return packageDarwin(); return packageDarwin(platform);
case "linux": case "linux":
switch (argv.packageType) { switch (argv.packageType) {
case "deb": case "deb":
return packageLinuxDeb(); return packageLinuxDeb(platform);
case "rpm": case "rpm":
return packageLinuxRpm(); return packageLinuxRpm(platform);
} }
case "win32": case "win32":
@@ -129,7 +137,7 @@ function package (platform) {
} }
} }
function packageDarwin () { function packageDarwin (platform) {
const installerName = `${applicationName}.pkg`; const installerName = `${applicationName}.pkg`;
const componentName = `${applicationName}_component.pkg`; const componentName = `${applicationName}_component.pkg`;
@@ -138,16 +146,16 @@ function packageDarwin () {
// Create pkgbuild root // Create pkgbuild root
const rootPath = path.join(BUILD_PATH, "root"); const rootPath = path.join(BUILD_PATH, "root");
const rootExecutablePath = path.join(rootPath, executablePath["darwin"]); const rootExecutablePath = path.join(rootPath, executablePath[platform]);
const rootManifestPath = path.join(rootPath, manifestPath["darwin"]); const rootManifestPath = path.join(rootPath, manifestPath[platform]);
// Create install locations // Create install locations
fs.ensureDirSync(rootExecutablePath, { recursive: true }); fs.ensureDirSync(rootExecutablePath, { recursive: true });
fs.ensureDirSync(rootManifestPath, { recursive: true }); fs.ensureDirSync(rootManifestPath, { recursive: true });
// Move files to root // Move files to root
fs.moveSync(path.join(BUILD_PATH, executableName["darwin"]) fs.moveSync(path.join(BUILD_PATH, executableName[platform])
, path.join(rootExecutablePath, executableName["darwin"])); , path.join(rootExecutablePath, executableName[platform]));
fs.moveSync(path.join(BUILD_PATH, manifestName) fs.moveSync(path.join(BUILD_PATH, manifestName)
, path.join(rootManifestPath, manifestName)); , path.join(rootManifestPath, manifestName));
@@ -198,20 +206,20 @@ function packageDarwin () {
} }
function packageLinuxDeb () { function packageLinuxDeb (platform) {
const installerName = `${applicationName}.deb`; const installerName = `${applicationName}.deb`;
// Create root // Create root
const rootPath = path.join(BUILD_PATH, "root"); const rootPath = path.join(BUILD_PATH, "root");
const rootExecutablePath = path.join(rootPath, executablePath["linux"]); const rootExecutablePath = path.join(rootPath, executablePath[platform]);
const rootManifestPath = path.join(rootPath, manifestPath["linux"]); const rootManifestPath = path.join(rootPath, manifestPath[platform]);
fs.ensureDirSync(rootExecutablePath, { recursive: true }); fs.ensureDirSync(rootExecutablePath, { recursive: true });
fs.ensureDirSync(rootManifestPath, { recursive: true }); fs.ensureDirSync(rootManifestPath, { recursive: true });
// Move files to root // Move files to root
fs.moveSync(path.join(BUILD_PATH, executableName["linux"]) fs.moveSync(path.join(BUILD_PATH, executableName[platform])
, path.join(rootExecutablePath, executableName["linux"])); , path.join(rootExecutablePath, executableName[platform]));
fs.moveSync(path.join(BUILD_PATH, manifestName) fs.moveSync(path.join(BUILD_PATH, manifestName)
, path.join(rootManifestPath, manifestName)); , path.join(rootManifestPath, manifestName));
@@ -245,7 +253,7 @@ function packageLinuxDeb () {
return installerName; return installerName;
} }
function packageLinuxRpm () { function packageLinuxRpm (platform) {
const specPath = path.join(__dirname const specPath = path.join(__dirname
, "../packaging/linux/rpm/package.spec"); , "../packaging/linux/rpm/package.spec");
@@ -255,9 +263,9 @@ function packageLinuxRpm () {
packageName: applicationName packageName: applicationName
, applicationName , applicationName
, applicationVersion , applicationVersion
, executablePath: executablePath["linux"] , executablePath: executablePath[platform]
, manifestPath: manifestPath["linux"] , manifestPath: manifestPath[platform]
, executableName: executableName["linux"] , executableName: executableName[platform]
, manifestName , manifestName
}; };

View File

@@ -1,6 +0,0 @@
{
"name": "fx_cast_bridge"
, "description": ""
, "type": "stdio"
, "allowed_extensions": [ "fx_cast@matt.tf" ]
}