Skip to content

Commit

Permalink
Mac App Store platform support + OS X platform improvements
Browse files Browse the repository at this point in the history
- Added: platform `mas` for Mac App Store distribution
- Added: CFBundleIdentifier is now filtered, according to Apple
Documentation
- Fixed: CFBundleIdentifiers for Helper EH and Helper NP, to
maxogden#261
- Moved: `codesign` now with external `electron-osx-sign` module
  • Loading branch information
sethlu committed Feb 15, 2016
1 parent e2cbbcb commit 3fd8096
Show file tree
Hide file tree
Showing 14 changed files with 459 additions and 203 deletions.
11 changes: 8 additions & 3 deletions index.js
Expand Up @@ -20,9 +20,14 @@ var supportedPlatforms = {
// Maps to module ID for each platform (lazy-required if used)
darwin: './mac',
linux: './linux',
mas: './mac', // map to darwin
win32: './win32'
}

function isPlatformMac (platform) {
return platform === 'darwin' || platform === 'mas'
}

function validateList (list, supported, name) {
// Validates list of architectures or platforms.
// Returns a normalized array if successful, or an error message string otherwise.
Expand Down Expand Up @@ -95,7 +100,7 @@ function createSeries (opts, archs, platforms) {
archs.forEach(function (arch) {
platforms.forEach(function (platform) {
// Electron does not have 32-bit releases for Mac OS X, so skip that combination
if (platform === 'darwin' && arch === 'ia32') return
if (isPlatformMac(platform) && arch === 'ia32') return
combinations.push({
platform: platform,
arch: arch,
Expand Down Expand Up @@ -161,11 +166,11 @@ function createSeries (opts, archs, platforms) {
})
}

if (combination.platform === 'darwin') {
if (isPlatformMac(combination.platform)) {
testSymlink(function (result) {
if (result) return checkOverwrite()

console.error('Cannot create symlinks; skipping darwin platform')
console.error('Cannot create symlinks; skipping ' + combination.platform + ' platform')
callback()
})
} else {
Expand Down
67 changes: 59 additions & 8 deletions mac.js
@@ -1,12 +1,12 @@
var path = require('path')
var fs = require('fs')
var child = require('child_process')

var plist = require('plist')
var mv = require('mv')
var ncp = require('ncp').ncp
var series = require('run-series')
var common = require('./common')
var sign = require('electron-osx-sign')

function moveHelpers (frameworksPath, appName, callback) {
function rename (basePath, oldName, newName, cb) {
Expand All @@ -27,6 +27,12 @@ function moveHelpers (frameworksPath, appName, callback) {
})
}

function filterCFBundleIdentifier (identifier) {
// Remove special characters and allow only alphanumeric (A-Z,a-z,0-9), hyphen (-), and period (.)
// Apple documentation: https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070
return identifier.replace(/ /g, '-').replace(/[^a-zA-Z0-9.-]/g, '')
}

module.exports = {
createApp: function createApp (opts, templatePath, callback) {
var appRelativePath = path.join('Electron.app', 'Contents', 'Resources', 'app')
Expand All @@ -36,21 +42,43 @@ module.exports = {
var contentsPath = path.join(tempPath, 'Electron.app', 'Contents')
var frameworksPath = path.join(contentsPath, 'Frameworks')
var appPlistFilename = path.join(contentsPath, 'Info.plist')
var helperPlistFilename = path.join(frameworksPath, 'Electron Helper.app', 'Contents', 'Info.plist')
var appPlist = plist.parse(fs.readFileSync(appPlistFilename).toString())

var helperPlistFilename = path.join(frameworksPath, 'Electron Helper.app', 'Contents', 'Info.plist')
var helperPlist = plist.parse(fs.readFileSync(helperPlistFilename).toString())
var helperEHPlistFilename = path.join(frameworksPath, 'Electron Helper EH.app', 'Contents', 'Info.plist')
var helperEHPlist = plist.parse(fs.readFileSync(helperEHPlistFilename).toString())
var helperNPPlistFilename = path.join(frameworksPath, 'Electron Helper NP.app', 'Contents', 'Info.plist')
var helperNPPlist = plist.parse(fs.readFileSync(helperNPPlistFilename).toString())

// Update plist files
var defaultBundleName = 'com.electron.' + opts.name.toLowerCase().replace(/ /g, '_')
var defaultBundleName = 'com.electron.' + opts.name.toLowerCase()
var appBundleIdentifier = filterCFBundleIdentifier(opts['app-bundle-id'] || defaultBundleName)
var helperBundleIdentifier = filterCFBundleIdentifier(opts['helper-bundle-id'] || appBundleIdentifier + '.helper')

var appVersion = opts['app-version']
var buildVersion = opts['build-version']
var appCategoryType = opts['app-category-type']
var humanReadableCopyright = opts['app-human-readable-copyright']

appPlist.CFBundleDisplayName = opts.name
appPlist.CFBundleIdentifier = opts['app-bundle-id'] || defaultBundleName
appPlist.CFBundleName = opts.name
helperPlist.CFBundleIdentifier = opts['helper-bundle-id'] || defaultBundleName + '.helper'
appPlist.CFBundleDisplayName = opts.name
appPlist.CFBundleIdentifier = appBundleIdentifier

helperPlist.CFBundleName = opts.name
helperPlist.CFBundleDisplayName = opts.name + ' Helper'
helperPlist.CFBundleExecutable = opts.name + ' Helper'
helperPlist.CFBundleIdentifier = helperBundleIdentifier

helperEHPlist.CFBundleName = opts.name + ' Helper EH'
helperEHPlist.CFBundleDisplayName = opts.name + ' Helper EH'
helperEHPlist.CFBundleExecutable = opts.name + ' Helper EH'
helperEHPlist.CFBundleIdentifier = helperBundleIdentifier + '.EH'

helperNPPlist.CFBundleName = opts.name + ' Helper NP'
helperNPPlist.CFBundleDisplayName = opts.name + ' Helper NP'
helperNPPlist.CFBundleExecutable = opts.name + ' Helper NP'
helperNPPlist.CFBundleIdentifier = helperBundleIdentifier + '.NP'

if (appVersion) {
appPlist.CFBundleShortVersionString = appPlist.CFBundleVersion = '' + appVersion
Expand All @@ -73,8 +101,14 @@ module.exports = {
appPlist.LSApplicationCategoryType = appCategoryType
}

if (humanReadableCopyright) {
appPlist.NSHumanReadableCopyright = humanReadableCopyright
}

fs.writeFileSync(appPlistFilename, plist.build(appPlist))
fs.writeFileSync(helperPlistFilename, plist.build(helperPlist))
fs.writeFileSync(helperEHPlistFilename, plist.build(helperEHPlist))
fs.writeFileSync(helperNPPlistFilename, plist.build(helperNPPlist))

var operations = []

Expand All @@ -101,7 +135,23 @@ module.exports = {

if (opts.sign) {
operations.push(function (cb) {
child.exec('codesign --deep --force --sign "' + opts.sign + '" "' + finalAppPath + '"', cb)
sign({
app: finalAppPath,
platform: opts.platform,
// Take argument sign as signing identity:
// Provided in command line --sign, opts.sign will be recognized
// as boolean value true. Then fallback to null for auto discovery,
// otherwise provided signing certificate.
identity: opts.sign === true ? null : opts.sign,
entitlements: opts['sign-entitlements']
}, function (err) {
if (err) {
console.warn('Code sign failed; please retry manually.')
// Though not signed successfully, the application is packed.
// It might have to be signed for another time manually.
}
cb()
})
})
}

Expand All @@ -110,5 +160,6 @@ module.exports = {
common.moveApp(opts, tempPath, callback)
})
})
}
},
filterCFBundleIdentifier: filterCFBundleIdentifier
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"asar": "^0.8.2",
"electron-download": "^1.0.0",
"electron-osx-sign": "^0.1.6",
"extract-zip": "^1.0.3",
"get-package-info": "0.0.2",
"minimist": "^1.1.1",
Expand Down
22 changes: 7 additions & 15 deletions readme.md
Expand Up @@ -113,7 +113,7 @@ packager(opts, function done (err, appPath) { })

`platform` - *String*

Allowed values: *linux, win32, darwin, all*
Allowed values: *darwin, linux, mas, win32, all*

Not required if `all` is used.
Arbitrary combinations of individual platforms are also supported via a comma-delimited string or array of strings.
Expand All @@ -137,15 +137,9 @@ packager(opts, function done (err, appPath) { })

Valid values are listed in [Apple's documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).

The bundle identifier to use in the application's plist (OS X only).

`app-category-type` - *String*
`app-copyright` - *String*

The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory (OS X only).

For example, `app-category-type=public.app-category.developer-tools` will set the application category to *Developer Tools*.

Valid values are listed in [Apple's documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).
Copyright string to use in the app plist. Maps to the `NSHumanReadableCopyright` on OS X.

`app-version` - *String*

Expand Down Expand Up @@ -193,11 +187,7 @@ If the file extension is omitted, it is auto-completed to the correct extension
A pattern which specifies which files to ignore when copying files to create the package(s). Alternatively, this can be a predicate function that, given the file path, returns true if the file should be ignored or false if the file should be kept.

`name` - *String*
The application name. If omitted, it will use the "productName" or "name" of the nearest package.json.

A pattern which specifies which files to ignore when copying files to create the package(s).

`name` - *String*
The application name. If omitted, it will use the "productName" or "name" of the nearest package.json.

`out` - *String*
Expand All @@ -214,9 +204,11 @@ If the file extension is omitted, it is auto-completed to the correct extension

`sign` - *String*

The identity used when signing the package via `codesign`. (Only for the OS X target platform, when XCode is present on the build platform.)
The identity used when signing the package via `codesign`. (Only for the OS X / Mac App Store target platforms, when Xcode is present on the host platform.)

`app-category-type` - *String*
`sign-entitlements` - *String*

The path to entitlements used in signing. (Currently limited to Mac App Store distribution.)

`strict-ssl` - *Boolean*

Expand Down
6 changes: 3 additions & 3 deletions test/basic.js
Expand Up @@ -15,7 +15,7 @@ function generateNamePath (opts) {
// Generates path to verify reflects the name given in the options.
// Returns the Helper.app location on darwin since the top-level .app is already tested for the resources path;
// returns the executable for other OSes
if (opts.platform === 'darwin') {
if (util.isPlatformMac(opts.platform)) {
return path.join(opts.name + '.app', 'Contents', 'Frameworks', opts.name + ' Helper.app')
}

Expand Down Expand Up @@ -49,7 +49,7 @@ function createDefaultsTest (combination) {
resourcesPath = path.join(finalPath, util.generateResourcesPath(opts))
fs.stat(path.join(finalPath, generateNamePath(opts)), cb)
}, function (stats, cb) {
if (opts.platform === 'darwin') {
if (util.isPlatformMac(opts.platform)) {
t.true(stats.isDirectory(), 'The Helper.app should reflect opts.name')
} else {
t.true(stats.isFile(), 'The executable should reflect opts.name')
Expand Down Expand Up @@ -296,7 +296,7 @@ function createInferTest (combination) {
opts.name = packageJSON.productName
fs.stat(path.join(finalPath, generateNamePath(opts)), cb)
}, function (stats, cb) {
if (opts.platform === 'darwin') {
if (util.isPlatformMac(opts.platform)) {
t.true(stats.isDirectory(), 'The Helper.app should reflect productName')
} else {
t.true(stats.isFile(), 'The executable should reflect productName')
Expand Down
2 changes: 1 addition & 1 deletion test/config.json
@@ -1,4 +1,4 @@
{
"timeout": 30000,
"version": "0.28.3"
"version": "0.35.6"
}
13 changes: 13 additions & 0 deletions test/darwin.js
@@ -0,0 +1,13 @@
var path = require('path')

var config = require('./config.json')

var baseOpts = {
name: 'basicTest',
dir: path.join(__dirname, 'fixtures', 'basic'),
version: config.version,
arch: 'x64',
platform: 'darwin'
}

require('./mac')(baseOpts)
2 changes: 1 addition & 1 deletion test/fixtures/basic/package.json
Expand Up @@ -7,6 +7,6 @@
"devDependencies": {
"ncp": "^2.0.0",
"run-waterfall": "^1.1.1",
"electron-prebuilt": "0.36.4"
"electron-prebuilt": "0.35.6"
}
}
3 changes: 2 additions & 1 deletion test/index.js
Expand Up @@ -23,6 +23,7 @@ series([

if (process.platform !== 'win32') {
// Perform additional tests specific to building for OS X
require('./mac')
require('./darwin')
require('./mas')
}
})

0 comments on commit 3fd8096

Please sign in to comment.