App build output naming consistency

This commit is contained in:
hensm
2019-03-05 19:15:08 +00:00
parent 45908a09e1
commit 1d4337cc7a
2 changed files with 70 additions and 27 deletions

View File

@@ -38,6 +38,33 @@ const argv = minimist(process.argv.slice(2), {
} }
}); });
const supportedTargets = [
"win-x64"
, "macos-x64"
, "linux-x64"
];
const supportedPlatforms = [];
const supportedArchs = [];
for (const target of supportedTargets) {
const [ platform, arch ] = target.split("-");
supportedPlatforms.push(platform);
supportedArchs.push(arch);
}
if (!supportedPlatforms.includes(pkgPlatform[argv.platform])) {
console.error("Unsupported target platform");
process.exit(1);
}
if (!supportedArchs.includes(argv.arch)) {
console.error("Unsupported target arch");
process.exit(1);
}
const ROOT_PATH = path.join(__dirname, ".."); const ROOT_PATH = path.join(__dirname, "..");
const SRC_PATH = path.join(ROOT_PATH, "src"); const SRC_PATH = path.join(ROOT_PATH, "src");
const BUILD_PATH = path.join(ROOT_PATH, "build"); const BUILD_PATH = path.join(ROOT_PATH, "build");
@@ -140,7 +167,7 @@ async function build () {
* to dist. * to dist.
*/ */
if (argv.package) { if (argv.package) {
const installerName = await packageApp(argv.platform); const installerName = await packageApp(argv.platform, argv.arch);
if (installerName) { if (installerName) {
// Move installer to dist // Move installer to dist
fs.moveSync( fs.moveSync(
@@ -168,11 +195,12 @@ async function build () {
/** /**
* Takes a platform and returns the path of the created * Takes a platform and returns the path of the created
* install package. * installer package.
*/ */
function packageApp (platform) { function packageApp (platform, arch) {
const packageFunctionArgs = [ const packageFunctionArgs = [
executableName[platform] // platformExecutableName arch
, executableName[platform] // platformExecutableName
, executablePath[platform] // platformExecutablePath , executablePath[platform] // platformExecutablePath
, manifestPath[platform] // platformManifestPath , manifestPath[platform] // platformManifestPath
]; ];
@@ -198,7 +226,8 @@ function packageApp (platform) {
default: default:
console.log("Cannot build installer package for this platform"); console.error("Unsupported target platform");
process.exit(1);
} }
} }
@@ -216,11 +245,12 @@ function packageApp (platform) {
* utilities. Only possible on macOS. * utilities. Only possible on macOS.
*/ */
function packageDarwin ( function packageDarwin (
platformExecutableName arch
, platformExecutableName
, platformExecutablePath , platformExecutablePath
, platformManifestPath) { , platformManifestPath) {
const installerName = `${applicationName}.pkg`; const outputName = `${applicationName}-${applicationVersion}-${arch}.pkg`;
const componentName = `${applicationName}_component.pkg`; const componentName = `${applicationName}_component.pkg`;
const packagingDir = path.join(__dirname, "../packaging/mac/"); const packagingDir = path.join(__dirname, "../packaging/mac/");
@@ -283,10 +313,10 @@ function packageDarwin (
spawnSync( spawnSync(
`productbuild --distribution ${distFilePath} ` `productbuild --distribution ${distFilePath} `
+ `--package-path ${BUILD_PATH} ` + `--package-path ${BUILD_PATH} `
+ `${path.join(BUILD_PATH, installerName)}` + `${path.join(BUILD_PATH, outputName)}`
, { shell: true }); , { shell: true });
return installerName; return outputName;
} }
/** /**
@@ -299,25 +329,27 @@ function packageDarwin (
* Requires the dpkg-deb command line utility. * Requires the dpkg-deb command line utility.
*/ */
function packageLinuxDeb ( function packageLinuxDeb (
platformExecutableName arch
, platformExecutableName
, platformExecutablePath , platformExecutablePath
, platformManifestPath) { , platformManifestPath) {
const installerName = `${applicationName}.deb`; const outputName = `${applicationName}-${applicationVersion}-${arch}.deb`;
// Create root // Create root
const rootPath = path.join(BUILD_PATH, "root"); const rootPath = path.join(BUILD_PATH, "root");
const rootExecutablePath = path.join(rootPath, platformExecutablePath); const rootExecutablePath = path.join(rootPath, platformExecutablePath);
const rootManifestPath = path.join(rootPath const rootManifestPath = path.join(rootPath, platformManifestPath);
, platformManifestPath);
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, platformExecutableName) fs.moveSync(
path.join(BUILD_PATH, platformExecutableName)
, path.join(rootExecutablePath, platformExecutableName)); , path.join(rootExecutablePath, platformExecutableName));
fs.moveSync(path.join(BUILD_PATH, manifestName) fs.moveSync(
path.join(BUILD_PATH, manifestName)
, path.join(rootManifestPath, manifestName)); , path.join(rootManifestPath, manifestName));
@@ -344,10 +376,10 @@ function packageLinuxDeb (
// Build .deb package // Build .deb package
spawnSync( spawnSync(
`dpkg-deb --build ${rootPath} ` `dpkg-deb --build ${rootPath} `
+ `${path.join(BUILD_PATH, installerName)}` + `${path.join(BUILD_PATH, outputName)}`
, { shell: true}); , { shell: true});
return installerName; return outputName;
} }
/** /**
@@ -358,10 +390,13 @@ function packageLinuxDeb (
* Requires the rpmbuild command line utility. * Requires the rpmbuild command line utility.
*/ */
function packageLinuxRpm ( function packageLinuxRpm (
platformExecutableName arch
, platformExecutableName
, platformExecutablePath , platformExecutablePath
, platformManifestPath) { , platformManifestPath) {
const outputName = `${applicationName}-${applicationVersion}-${arch}.rpm`;
const specPath = path.join(__dirname const specPath = path.join(__dirname
, "../packaging/linux/rpm/package.spec"); , "../packaging/linux/rpm/package.spec");
@@ -382,15 +417,21 @@ function packageLinuxRpm (
fs.readFileSync(specPath).toString() fs.readFileSync(specPath).toString()
, view)); , view));
const archMap = {
"x86": "i386"
, "x64": "x86_64"
};
// TODO: Use argv.arch // TODO: Use argv.arch
spawnSync( spawnSync(
`rpmbuild -bb ${specOutputPath} ` `rpmbuild -bb ${specOutputPath} `
+ `--define "_distdir ${BUILD_PATH}" ` + `--define "_distdir ${BUILD_PATH}" `
+ `--define "_rpmdir ${BUILD_PATH}" ` + `--define "_rpmdir ${BUILD_PATH}" `
+ `--target=x86_64-linux` + `--define "_rpmfilename ${outputName}" `
+ `--target=${archMap[arch]}-linux`
, { shell: true }); , { shell: true });
return glob.sync("**/*.rpm", { cwd: BUILD_PATH })[0]; return outputName;
} }
/** /**
@@ -401,14 +442,16 @@ function packageLinuxRpm (
* makensis command line utility. * makensis command line utility.
*/ */
function packageWin32 ( function packageWin32 (
platformExecutableName arch
, platformExecutablePath) { , platformExecutableName
, platformExecutablePath
, platformManifestPath) {
const outputName = `${applicationName}-${applicationVersion}-${arch}.exe`;
const scriptPath = path.join(__dirname, "../packaging/win/installer.nsi"); const scriptPath = path.join(__dirname, "../packaging/win/installer.nsi");
const scriptOutputPath = path.join(BUILD_PATH, path.basename(scriptPath)); const scriptOutputPath = path.join(BUILD_PATH, path.basename(scriptPath));
const outFile = "installer.exe";
const view = { const view = {
applicationName applicationName
, applicationVersion , applicationVersion
@@ -416,7 +459,7 @@ function packageWin32 (
, executablePath: platformExecutablePath , executablePath: platformExecutablePath
, manifestName , manifestName
, winRegistryKey: WIN_REGISTRY_KEY , winRegistryKey: WIN_REGISTRY_KEY
, outFile , outputName
}; };
// Write templated script to build dir // Write templated script to build dir
@@ -434,7 +477,7 @@ function packageWin32 (
console.error(output.stderr); console.error(output.stderr);
} }
return outFile; return outputName;
} }

View File

@@ -4,7 +4,7 @@
!define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\{{winRegistryKey}}" !define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\{{winRegistryKey}}"
Name "{{applicationName}} v{{applicationVersion}}" Name "{{applicationName}} v{{applicationVersion}}"
OutFile "{{outFile}}" OutFile "{{outputName}}"
InstallDir "{{executablePath}}" InstallDir "{{executablePath}}"
RequestExecutionLevel user RequestExecutionLevel user