diff --git a/build/config.js b/build/config.js index 19d02e64f..b6a6d10b4 100644 --- a/build/config.js +++ b/build/config.js @@ -4,6 +4,7 @@ 'use strict' const path = require('path') +const childProcess = require('child_process') const appMetadata = require('../package.json') @@ -11,14 +12,23 @@ const repositoryRootPath = path.resolve(__dirname, '..') const buildOutputPath = path.join(repositoryRootPath, 'out') const intermediateAppPath = path.join(buildOutputPath, 'app') const cachePath = path.join(repositoryRootPath, 'cache') -const channel = getChannel() module.exports = { - appMetadata, channel, + appMetadata, getAppVersion, getChannel, repositoryRootPath, buildOutputPath, intermediateAppPath, cachePath } +function getAppVersion () { + let version = appMetadata.version + if (getChannel() === 'dev') { + const result = childProcess.spawnSync('git', ['rev-parse', '--short', 'HEAD'], {cwd: repositoryRootPath}) + const commitHash = result.stdout.toString().trim() + version += '-' + commitHash + } + return version +} + function getChannel () { if (appMetadata.version.match(/dev/) || isBuildingPR()) { return 'dev' diff --git a/build/lib/copy-assets.js b/build/lib/copy-assets.js index b6566fc40..d6aea38a5 100644 --- a/build/lib/copy-assets.js +++ b/build/lib/copy-assets.js @@ -26,7 +26,7 @@ module.exports = function () { } fs.copySync( - path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'png', '1024.png'), + path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.getChannel(), 'png', '1024.png'), path.join(CONFIG.intermediateAppPath, 'resources', 'atom.png') ) } diff --git a/build/lib/package-application.js b/build/lib/package-application.js index 57e91336e..8cc4aeeef 100644 --- a/build/lib/package-application.js +++ b/build/lib/package-application.js @@ -12,13 +12,13 @@ const CONFIG = require('../config') module.exports = async function () { console.log(`Running electron-packager on ${CONFIG.intermediateAppPath}`) const packagedAppPath = await runPackager({ - 'app-version': CONFIG.appMetadata.version, + 'app-version': CONFIG.getAppVersion(), 'arch': process.arch, 'asar': {unpack: buildAsarUnpackGlobExpression()}, - 'build-version': CONFIG.appMetadata.version, + 'build-version': CONFIG.getAppVersion(), 'download': {cache: CONFIG.cachePath}, 'dir': CONFIG.intermediateAppPath, - 'icon': path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'atom.icns'), + 'icon': path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.getChannel(), 'atom.icns'), 'out': CONFIG.buildOutputPath, 'overwrite': true, 'platform': process.platform, @@ -73,19 +73,7 @@ function buildAsarUnpackGlobExpression () { function runPackager (options) { return new Promise((resolve, reject) => { - electronPackager({ - 'app-version': CONFIG.appMetadata.version, - 'arch': process.arch, - 'asar': {unpack: buildAsarUnpackGlobExpression()}, - 'build-version': CONFIG.appMetadata.version, - 'download': {cache: CONFIG.cachePath}, - 'dir': CONFIG.intermediateAppPath, - 'icon': path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'atom.icns'), - 'out': CONFIG.buildOutputPath, - 'overwrite': true, - 'platform': process.platform, - 'version': CONFIG.appMetadata.electronVersion - }, (err, packagedAppPaths) => { + electronPackager(options, (err, packagedAppPaths) => { if (err) { reject(err) throw new Error(err)