Skip to content

Commit

Permalink
fix(mas): Cannot create MAS build
Browse files Browse the repository at this point in the history
Close #4048
  • Loading branch information
develar committed Jul 18, 2019
1 parent 0ee226b commit 1acd5b3
Show file tree
Hide file tree
Showing 19 changed files with 1,237 additions and 55 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"chromium-pickle-js": "^0.2.0",
"debug": "^4.1.1",
"ejs": "^2.6.2",
"electron-osx-sign": "0.4.11",
"fs-extra": "^8.1.0",
"hosted-git-info": "^2.7.1",
"iconv-lite": "^0.5.0",
Expand Down
23 changes: 23 additions & 0 deletions packages/app-builder-lib/electron-osx-sign/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2015-2016 Zhuo Lu, Jason Hinkle, et al.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
149 changes: 149 additions & 0 deletions packages/app-builder-lib/electron-osx-sign/flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* @module flat
*/

'use strict'

const path = require('path')

const util = require('./util')
const debuglog = util.debuglog
const debugwarn = util.debugwarn
const execFileAsync = util.execFileAsync
const validateOptsAppAsync = util.validateOptsAppAsync
const validateOptsPlatformAsync = util.validateOptsPlatformAsync
const Identity = require('./util-identities').findIdentitiesAsync
const findIdentitiesAsync = require('./util-identities').findIdentitiesAsync

/**
* This function returns a promise validating all options passed in opts.
* @function
* @param {Object} opts - Options.
* @returns {Promise} Promise.
*/
function validateFlatOptsAsync (opts) {
if (opts.pkg) {
if (typeof opts.pkg !== 'string') return Promise.reject(new Error('`pkg` must be a string.'))
if (path.extname(opts.pkg) !== '.pkg') return Promise.reject(new Error('Extension of output package must be `.pkg`.'))
} else {
debugwarn('No `pkg` passed in arguments, will fallback to default inferred from the given application.')
opts.pkg = path.join(path.dirname(opts.app), path.basename(opts.app, '.app') + '.pkg')
}

if (opts.install) {
if (typeof opts.install !== 'string') return Promise.reject(new Error('`install` must be a string.'))
} else {
debugwarn('No `install` passed in arguments, will fallback to default `/Applications`.')
opts.install = '/Applications'
}

return Promise.all([
validateOptsAppAsync(opts),
validateOptsPlatformAsync(opts),
])
}

/**
* This function returns a promise flattening the application.
* @function
* @param {Object} opts - Options.
* @returns {Promise} Promise.
*/
function flatApplicationAsync (opts) {
const args = [
'--component', opts.app, opts.install,
'--sign', opts.identity.name,
opts.pkg
]
if (opts.keychain) {
args.unshift('--keychain', opts.keychain)
}
if (opts.scripts) {
args.unshift('--scripts', opts.scripts)
}

debuglog('Flattening... ' + opts.app)
return execFileAsync('productbuild', args)
.thenReturn(undefined)
}

/**
* This function is exported and returns a promise flattening the application.
* @function
* @param {Object} opts - Options.
* @returns {Promise} Promise.
*/
module.exports.flatAsync = function (opts) {
return validateFlatOptsAsync(opts)
.then(function () {
let promise
if (opts.identity) {
debuglog('`identity` passed in arguments.')
if (opts['identity-validation'] === false || opts.identity instanceof Identity) {
return Promise.resolve()
}
promise = findIdentitiesAsync(opts, opts.identity)
} else {
debugwarn('No `identity` passed in arguments...')
if (opts.platform === 'mas') {
debuglog('Finding `3rd Party Mac Developer Installer` certificate for flattening app distribution in the Mac App Store...')
promise = findIdentitiesAsync(opts, '3rd Party Mac Developer Installer:')
} else {
debuglog('Finding `Developer ID Application` certificate for distribution outside the Mac App Store...')
promise = findIdentitiesAsync(opts, 'Developer ID Installer:')
}
}
return promise
.then(function (identities) {
if (identities.length > 0) {
// Provisioning profile(s) found
if (identities.length > 1) {
debugwarn('Multiple identities found, will use the first discovered.')
} else {
debuglog('Found 1 identity.')
}
opts.identity = identities[0]
} else {
// No identity found
return Promise.reject(new Error('No identity found for signing.'))
}
})
})
.then(function () {
// Pre-flat operations
})
.then(function () {
debuglog('Flattening application...', '\n',
'> Application:', opts.app, '\n',
'> Package output:', opts.pkg, '\n',
'> Install path:', opts.install, '\n',
'> Identity:', opts.identity, '\n',
'> Scripts:', opts.scripts)
return flatApplicationAsync(opts)
})
.then(function () {
// Post-flat operations
debuglog('Application flattened.')
})
}

/**
* This function is exported with normal callback implementation.
* @function
* @param {Object} opts - Options.
* @param {RequestCallback} cb - Callback.
*/
module.exports.flat = function (opts, cb) {
module.exports.flatAsync(opts)
.then(function () {
debuglog('Application flattened, saved to: ' + opts.app)
if (cb) cb()
})
.catch(function (err) {
debuglog('Flat failed:')
if (err.message) debuglog(err.message)
else if (err.stack) debuglog(err.stack)
else debuglog(err)
if (cb) cb(err)
})
}
35 changes: 35 additions & 0 deletions packages/app-builder-lib/electron-osx-sign/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
interface BaseSignOptions {
app: string
identity?: string
platform?: string
keychain?: string
}

interface SignOptions extends BaseSignOptions {
binaries?: Array<string>
entitlements?: string
"entitlements-inherit"?: string
"gatekeeper-assess"?: boolean
ignore?: string
"pre-auto-entitlements"?: boolean
"pre-embed-provisioning-profile"?: boolean
"provisioning-profile"?: string
"requirements"?: string
"type"?: string
version?: string
"identity-validation"?: boolean
}

export function sign(opts: SignOptions, callback: (error: Error) => void): void

export function signAsync(opts: SignOptions): Promise<any>

interface FlatOptions extends BaseSignOptions {
install?: string
pkg?: string
scripts?: string
}

export function flat(opts: FlatOptions, callback: (error: Error) => void): void

export function flatAsync(opts: FlatOptions): Promise<any>
47 changes: 47 additions & 0 deletions packages/app-builder-lib/electron-osx-sign/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @module electron-osx-sign
*/

'use strict'

const sign = require('./sign')
const flat = require('./flat')

/**
* This function is a normal callback implementation.
* @param {Object} opts - Options.
* @param {RequestCallback} cb - Callback.
*/
module.exports = sign.sign // Aliasing

/**
* This function is a normal callback implementation.
* @function
* @param {Object} opts - Options.
* @param {RequestCallback} cb - Callback.
*/
module.exports.sign = sign.sign

/**
* This function returns a promise signing the application.
* @function
* @param {mixed} opts - Options.
* @returns {Promise} Promise.
*/
module.exports.signAsync = sign.signAsync

/**
* This function is exported with normal callback implementation.
* @function
* @param {Object} opts - Options.
* @param {RequestCallback} cb - Callback.
*/
module.exports.flat = flat.flat

/**
* This function is exported and returns a promise flattening the application.
* @function
* @param {Object} opts - Options.
* @returns {Promise} Promise.
*/
module.exports.flatAsync = flat.flatAsync
Loading

0 comments on commit 1acd5b3

Please sign in to comment.