From e7d1a27895bf36cffb1e8ebba9462116db555b9b Mon Sep 17 00:00:00 2001 From: hensm Date: Thu, 29 Nov 2018 06:38:57 +0000 Subject: [PATCH] Add .deb package building --- app/bin/build.js | 151 ++++++++++++------ app/bin/lib/paths.js | 6 +- app/packaging/linux/deb/DEBIAN/control | 5 + app/packaging/{macos => mac}/distribution.xml | 0 .../{macos => mac}/scripts/postinstall | 0 5 files changed, 109 insertions(+), 53 deletions(-) create mode 100644 app/packaging/linux/deb/DEBIAN/control rename app/packaging/{macos => mac}/distribution.xml (100%) rename app/packaging/{macos => mac}/scripts/postinstall (100%) diff --git a/app/bin/build.js b/app/bin/build.js index 5b0a908..ad21ceb 100644 --- a/app/bin/build.js +++ b/app/bin/build.js @@ -16,10 +16,12 @@ const { executableName const argv = minimist(process.argv.slice(2), { boolean: [ "package" ] - , string: [ "platform" ] + , string: [ "platform", "packageType" ] , default: { platform: os.platform() , package: false + // Linux package type (deb/rpm) + , packageType: "deb" } }); @@ -27,6 +29,7 @@ const BUILD_PATH = path.join(__dirname, "../build"); // Clean +fs.removeSync(BUILD_PATH); fs.removeSync(DIST_PATH); // Make directories @@ -77,7 +80,7 @@ async function build () { ]); if (argv.package) { - const installerName = await buildInstaller(argv.platform); + const installerName = await package(argv.platform); // Move installer to dist fs.moveSync(path.join(BUILD_PATH, installerName) @@ -97,64 +100,112 @@ async function build () { fs.removeSync(BUILD_PATH); } -async function buildInstaller (platform) { + +function package (platform) { switch (platform) { - case "darwin": { - const installerName = "fx_cast_bridge.pkg"; - const componentName = "fx_cast_bridge_default.pkg"; - const installerPath = path.join(BUILD_PATH, installerName); - const componentPath = path.join(BUILD_PATH, componentName); + case "darwin": + return packageDarwin(); - const packagingDir = path.join(__dirname, "../packaging/macos/"); - - // Create pkgbuild root - const rootPath = path.join(BUILD_PATH, "root"); - const rootExecutablePath = path.join(rootPath - , executablePath[platform]); - const rootManifestPath = path.join(rootPath - , manifestPath[platform]); - - // Create install locations - fs.ensureDirSync(rootExecutablePath, { recursive: true }); - fs.ensureDirSync(rootManifestPath, { recursive: true }); - - // Move files to root - fs.moveSync(path.join(BUILD_PATH, executableName[platform]) - , path.join(rootExecutablePath, executableName[platform])); - fs.moveSync(path.join(BUILD_PATH, manifestName) - , path.join(rootManifestPath, manifestName)); - - // Build component package - spawnSync( - `pkgbuild --root ${rootPath} ` - + `--identifier "tf.matt.fx_cast_bridge" ` - + `--version "0.0.1" ` - + `--scripts ${path.join(packagingDir, "scripts")} ` - + `${componentPath}` - , { shell: true }); - - // Distribution XML file - const distFilePath = path.join(packagingDir, "distribution.xml"); - - // Build installer package - spawnSync( - `productbuild --distribution ${distFilePath} ` - + `--package-path ${BUILD_PATH} ` - + `${installerPath}` - , { shell: true }); - - return installerName; - }; + case "linux": + switch (argv.packageType) { + case "deb": + return packageLinuxDeb(); + case "rpm": + return packageLinuxRpm(); + } case "win32": - case "linux": - // TODO: installers + return packageWin32(); default: console.log("Cannot build installer package for this platform"); } } +function packageDarwin () { + const installerName = "fx_cast_bridge.pkg"; + const componentName = "fx_cast_bridge_component.pkg"; + + const packagingDir = path.join(__dirname, "../packaging/mac/"); + + // Create pkgbuild root + const rootPath = path.join(BUILD_PATH, "root"); + const rootExecutablePath = path.join(rootPath + , executablePath["darwin"]); + const rootManifestPath = path.join(rootPath + , manifestPath["darwin"]); + + // Create install locations + fs.ensureDirSync(rootExecutablePath, { recursive: true }); + fs.ensureDirSync(rootManifestPath, { recursive: true }); + + // Move files to root + fs.moveSync(path.join(BUILD_PATH, executableName["darwin"]) + , path.join(rootExecutablePath, executableName["darwin"])); + fs.moveSync(path.join(BUILD_PATH, manifestName) + , path.join(rootManifestPath, manifestName)); + + // Build component package + spawnSync( + `pkgbuild --root ${rootPath} ` + + `--identifier "tf.matt.fx_cast_bridge" ` + + `--version "0.0.1" ` + + `--scripts ${path.join(packagingDir, "scripts")} ` + + `${path.join(BUILD_PATH, componentName)}` + , { shell: true }); + + // Distribution XML file + const distFilePath = path.join(packagingDir, "distribution.xml"); + + // Build installer package + spawnSync( + `productbuild --distribution ${distFilePath} ` + + `--package-path ${BUILD_PATH} ` + + `${path.join(BUILD_PATH, installerName)}` + , { shell: true }); + + return installerName; + +} + +function packageLinuxDeb () { + const installerName = "fx_cast_bridge.deb"; + + const packagingDir = path.join(__dirname, "../packaging/linux/deb"); + + // Create root + const rootPath = path.join(BUILD_PATH, "root"); + const rootExecutablePath = path.join(rootPath + , executablePath["linux"]); + const rootManifestPath = path.join(rootPath + , manifestPath["linux"]); + + fs.ensureDirSync(rootExecutablePath, { recursive: true }); + fs.ensureDirSync(rootManifestPath, { recursive: true }); + + // Move files to root + fs.moveSync(path.join(BUILD_PATH, executableName["linux"]) + , path.join(rootExecutablePath, executableName["linux"])); + fs.moveSync(path.join(BUILD_PATH, manifestName) + , path.join(rootManifestPath, manifestName)); + + // Copy package info to root + fs.copySync(path.join(packagingDir, "DEBIAN") + , path.join(rootPath, "DEBIAN")); + + // Build .deb package + spawnSync( + `dpkg-deb --build ${rootPath} ` + + `${path.join(BUILD_PATH, installerName)}` + , { shell: true}); + + return installerName; +} + +function packageLinuxRpm () {} +function packageWin32 () {} + + build().catch(e => { console.log("Build failed", e); process.exit(1); diff --git a/app/bin/lib/paths.js b/app/bin/lib/paths.js index 3075fc9..3e8a97e 100644 --- a/app/bin/lib/paths.js +++ b/app/bin/lib/paths.js @@ -17,9 +17,9 @@ exports.executablePath = { 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\\" + win32: "C:\\Program Files\\fx_cast\\" + , darwin: "/Library/Application Support/Mozilla/NativeMessagingHosts/" + , linux: "/usr/lib/mozilla/native-messaging-hosts/" }; exports.pkgPlatform = { diff --git a/app/packaging/linux/deb/DEBIAN/control b/app/packaging/linux/deb/DEBIAN/control new file mode 100644 index 0000000..be8d49f --- /dev/null +++ b/app/packaging/linux/deb/DEBIAN/control @@ -0,0 +1,5 @@ +Package: fx-cast-bridge +Version: 0.0.1 +Priority: optional +Architecture: amd64 +Description: fx_cast Bridge application diff --git a/app/packaging/macos/distribution.xml b/app/packaging/mac/distribution.xml similarity index 100% rename from app/packaging/macos/distribution.xml rename to app/packaging/mac/distribution.xml diff --git a/app/packaging/macos/scripts/postinstall b/app/packaging/mac/scripts/postinstall similarity index 100% rename from app/packaging/macos/scripts/postinstall rename to app/packaging/mac/scripts/postinstall