Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer --app-version from package.json #449

Merged
merged 14 commits into from
Aug 19, 2016
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
test/work
.DS_Store
.nyc_output
npm-debug.log
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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' +
Expand Down
3 changes: 3 additions & 0 deletions test/ci/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
# Setup ~/.wine by running a command
./node_modules/.bin/wine hostname
;;
esac
1 change: 1 addition & 0 deletions test/fixtures/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"main": "main.js",
"version": "4.99.101",
"productName": "MainJS",
"dependencies": {
"run-series": "^1.1.1"
Expand Down
31 changes: 31 additions & 0 deletions test/mac.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down