diff --git a/.gitignore b/.gitignore index 2212de3c..8b704b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules test/work .DS_Store .nyc_output +npm-debug.log diff --git a/.travis.yml b/.travis.yml index a3e899e0..e950735b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,7 @@ branches: env: global: # coveralls token - secure: hG3cs8/tOGTa8IPewVuahcp1f8gwsk/rX7ReUBPag6cdZdJpkbjzxp8R97mhhCrFOP/fvX8zAbCelXvvhME/mjZTFgzSNHLBL/SJreHP5m2B1yxXkroiQFu1qwewvzzKmfcs5W1CD8J8WbJuBk9zozDQG9c1OxTaK87tBGh1xik= + - secure: hG3cs8/tOGTa8IPewVuahcp1f8gwsk/rX7ReUBPag6cdZdJpkbjzxp8R97mhhCrFOP/fvX8zAbCelXvvhME/mjZTFgzSNHLBL/SJreHP5m2B1yxXkroiQFu1qwewvzzKmfcs5W1CD8J8WbJuBk9zozDQG9c1OxTaK87tBGh1xik= + # prevent wine popup dialogs about installing additional packages + - WINEDLLOVERRIDES="mscoree,mshtml=" + - WINEDEBUG="-all" diff --git a/NEWS.md b/NEWS.md index 37c1c680..c31caf8c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ ## Unreleased +### Added + +* The `package.json` `version` property is the default app version if `--app-version` is unspecified (#449) + ## [7.6.0] - 2016-08-14 ### Added diff --git a/docs/api.md b/docs/api.md index 30f9561e..cdbc5742 100644 --- a/docs/api.md +++ b/docs/api.md @@ -85,7 +85,7 @@ The human-readable copyright line for the app. Maps to the `LegalCopyright` meta *String* -The release version of the application. Maps to the `ProductVersion` metadata property on Windows, and `CFBundleShortVersionString` on OS X. +The release version of the application. By default the `version` property in the `package.json` is used but it can be overridden with this argument. If neither are provided, the version of Electron will be used. Maps to the `ProductVersion` metadata property on Windows, and `CFBundleShortVersionString` on OS X. ##### `asar` diff --git a/index.js b/index.js index 51d05729..a3135ed4 100644 --- a/index.js +++ b/index.js @@ -48,9 +48,10 @@ function validateList (list, supported, name) { return list } -function getNameAndVersion (opts, dir, cb) { +function getMetadata (opts, dir, cb) { var props = [] if (!opts.name) props.push(['productName', 'name']) + if (!opts['app-version']) props.push('version') if (!opts.version) props.push(['dependencies.electron', 'devDependencies.electron']) // Name and version provided, no need to infer @@ -77,6 +78,12 @@ function inferNameAndVersionFromInstalled (packageName, opts, result, cb) { debug('Inferring application name from productName or name in package.json') opts.name = result.values.productName } + + if (result.values.version) { + debug('Inferring app-version from version in package.json') + opts['app-version'] = result.values.version + } + if (result.values[`dependencies.${packageName}`]) { resolve(packageName, { basedir: path.dirname(result.source[`dependencies.${packageName}`].src) @@ -223,7 +230,7 @@ module.exports = function packager (opts, cb) { debug(`Target Platforms: ${platforms.join(', ')}`) debug(`Target Architectures: ${archs.join(', ')}`) - getNameAndVersion(opts, path.resolve(process.cwd(), opts.dir) || process.cwd(), function (err) { + getMetadata(opts, path.resolve(process.cwd(), opts.dir) || process.cwd(), function (err) { if (err) { err.message = 'Unable to determine application name or Electron version. ' + 'Please specify an application name and Electron version.\n\n' + diff --git a/test/ci/before_install.sh b/test/ci/before_install.sh index d71bed76..93c5570b 100755 --- a/test/ci/before_install.sh +++ b/test/ci/before_install.sh @@ -24,5 +24,8 @@ case "$TRAVIS_OS_NAME" in -in codesign.csr -out codesign.cer openssl pkcs12 -export -in codesign.cer -inkey codesign.key -out codesign.p12 -password pass:12345 security import codesign.p12 -k ~/Library/Keychains/login.keychain -P 12345 -T /usr/bin/codesign + npm install wine-darwin@1.9.17-1 + # Setup ~/.wine by running a command + ./node_modules/.bin/wine hostname ;; esac diff --git a/test/fixtures/basic/package.json b/test/fixtures/basic/package.json index 942e4d9a..5fe25727 100644 --- a/test/fixtures/basic/package.json +++ b/test/fixtures/basic/package.json @@ -1,5 +1,6 @@ { "main": "main.js", + "version": "4.99.101", "productName": "MainJS", "dependencies": { "run-series": "^1.1.1" diff --git a/test/mac.js b/test/mac.js index 7283ac10..e71b0917 100644 --- a/test/mac.js +++ b/test/mac.js @@ -189,6 +189,33 @@ function createAppVersionTest (baseOpts, appVersion, buildVersion) { } } +function createAppVersionInferenceTest (baseOpts) { + return function (t) { + t.timeoutAfter(config.timeout) + + var plistPath + + waterfall([ + function (cb) { + packager(baseOpts, cb) + }, function (paths, cb) { + plistPath = path.join(paths[0], baseOpts.name + '.app', 'Contents', 'Info.plist') + fs.stat(plistPath, cb) + }, function (stats, cb) { + t.true(stats.isFile(), 'The expected Info.plist file should exist') + fs.readFile(plistPath, 'utf8', cb) + }, function (file, cb) { + var obj = plist.parse(file) + t.equal(obj.CFBundleVersion, '4.99.101', 'CFBundleVersion should reflect package.json version') + t.equal(obj.CFBundleShortVersionString, '4.99.101', 'CFBundleShortVersionString should reflect package.json version') + cb() + } + ], function (err) { + t.end(err) + }) + } +} + function createAppCategoryTypeTest (baseOpts, appCategoryType) { return function (t) { t.timeoutAfter(config.timeout) @@ -602,6 +629,10 @@ module.exports = function (baseOpts) { test('app and build version test', createAppVersionTest(baseOpts, '1.1.0', '1.1.0.1234')) util.teardown() + util.setup() + test('infer app version from package.json test', createAppVersionInferenceTest(baseOpts)) + util.teardown() + util.setup() test('app version test', createAppVersionTest(baseOpts, '1.1.0')) util.teardown()