Add .deb package building

This commit is contained in:
hensm
2018-11-29 06:38:57 +00:00
parent ffa2a84793
commit e7d1a27895
5 changed files with 109 additions and 53 deletions

View File

@@ -16,10 +16,12 @@ const { executableName
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
boolean: [ "package" ] boolean: [ "package" ]
, string: [ "platform" ] , string: [ "platform", "packageType" ]
, default: { , default: {
platform: os.platform() platform: os.platform()
, package: false , package: false
// Linux package type (deb/rpm)
, packageType: "deb"
} }
}); });
@@ -27,6 +29,7 @@ const BUILD_PATH = path.join(__dirname, "../build");
// Clean // Clean
fs.removeSync(BUILD_PATH);
fs.removeSync(DIST_PATH); fs.removeSync(DIST_PATH);
// Make directories // Make directories
@@ -77,7 +80,7 @@ async function build () {
]); ]);
if (argv.package) { if (argv.package) {
const installerName = await buildInstaller(argv.platform); const installerName = await package(argv.platform);
// Move installer to dist // Move installer to dist
fs.moveSync(path.join(BUILD_PATH, installerName) fs.moveSync(path.join(BUILD_PATH, installerName)
@@ -97,30 +100,48 @@ async function build () {
fs.removeSync(BUILD_PATH); fs.removeSync(BUILD_PATH);
} }
async function buildInstaller (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);
const packagingDir = path.join(__dirname, "../packaging/macos/"); function package (platform) {
switch (platform) {
case "darwin":
return packageDarwin();
case "linux":
switch (argv.packageType) {
case "deb":
return packageLinuxDeb();
case "rpm":
return packageLinuxRpm();
}
case "win32":
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 // Create pkgbuild root
const rootPath = path.join(BUILD_PATH, "root"); const rootPath = path.join(BUILD_PATH, "root");
const rootExecutablePath = path.join(rootPath const rootExecutablePath = path.join(rootPath
, executablePath[platform]); , executablePath["darwin"]);
const rootManifestPath = path.join(rootPath const rootManifestPath = path.join(rootPath
, manifestPath[platform]); , manifestPath["darwin"]);
// 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[platform]) fs.moveSync(path.join(BUILD_PATH, executableName["darwin"])
, path.join(rootExecutablePath, executableName[platform])); , path.join(rootExecutablePath, executableName["darwin"]));
fs.moveSync(path.join(BUILD_PATH, manifestName) fs.moveSync(path.join(BUILD_PATH, manifestName)
, path.join(rootManifestPath, manifestName)); , path.join(rootManifestPath, manifestName));
@@ -130,7 +151,7 @@ async function buildInstaller (platform) {
+ `--identifier "tf.matt.fx_cast_bridge" ` + `--identifier "tf.matt.fx_cast_bridge" `
+ `--version "0.0.1" ` + `--version "0.0.1" `
+ `--scripts ${path.join(packagingDir, "scripts")} ` + `--scripts ${path.join(packagingDir, "scripts")} `
+ `${componentPath}` + `${path.join(BUILD_PATH, componentName)}`
, { shell: true }); , { shell: true });
// Distribution XML file // Distribution XML file
@@ -140,21 +161,51 @@ async function buildInstaller (platform) {
spawnSync( spawnSync(
`productbuild --distribution ${distFilePath} ` `productbuild --distribution ${distFilePath} `
+ `--package-path ${BUILD_PATH} ` + `--package-path ${BUILD_PATH} `
+ `${installerPath}` + `${path.join(BUILD_PATH, installerName)}`
, { shell: true }); , { shell: true });
return installerName; return installerName;
};
case "win32": }
case "linux":
// TODO: installers
default: function packageLinuxDeb () {
console.log("Cannot build installer package for this platform"); 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 => { build().catch(e => {
console.log("Build failed", e); console.log("Build failed", e);
process.exit(1); process.exit(1);

View File

@@ -17,9 +17,9 @@ exports.executablePath = {
exports.manifestName = "fx_cast_bridge.json"; exports.manifestName = "fx_cast_bridge.json";
exports.manifestPath = { exports.manifestPath = {
darwin: "/Library/Application Support/Mozilla/NativeMessagingHosts/" win32: "C:\\Program Files\\fx_cast\\"
, linux: ".mozilla/native-messaging-hosts/" , darwin: "/Library/Application Support/Mozilla/NativeMessagingHosts/"
, win32: "C:\\Program Files\\fx_cast\\" , linux: "/usr/lib/mozilla/native-messaging-hosts/"
}; };
exports.pkgPlatform = { exports.pkgPlatform = {

View File

@@ -0,0 +1,5 @@
Package: fx-cast-bridge
Version: 0.0.1
Priority: optional
Architecture: amd64
Description: fx_cast Bridge application