Auto detect platform
This commit is contained in:
Родитель
218f965a95
Коммит
38d24cc8bc
165
index.js
165
index.js
|
@ -52,19 +52,28 @@ function generateHelperAppExecutablePath (opts, helperPath, suffix, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
function signDarwinApplication (opts, callback) {
|
||||
function signApplication (opts, callback) {
|
||||
var operations = []
|
||||
var appFrameworksPath = generateAppFrameworksPath(opts)
|
||||
var childPaths = [
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework'),
|
||||
path.join(appFrameworksPath, 'Mantle.framework', 'Versions', 'A', 'Mantle'),
|
||||
path.join(appFrameworksPath, 'Mantle.framework'),
|
||||
path.join(appFrameworksPath, 'ReactiveCocoa.framework', 'Versions', 'A', 'ReactiveCocoa'),
|
||||
path.join(appFrameworksPath, 'ReactiveCocoa.framework'),
|
||||
path.join(appFrameworksPath, 'Squirrel.framework', 'Versions', 'A', 'Squirrel'),
|
||||
path.join(appFrameworksPath, 'Squirrel.framework')
|
||||
]
|
||||
|
||||
var childPaths
|
||||
if (opts.platform === 'mas') {
|
||||
childPaths = [
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework')
|
||||
]
|
||||
} else if (opts.platform === 'darwin') {
|
||||
childPaths = [
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework'),
|
||||
path.join(appFrameworksPath, 'Mantle.framework', 'Versions', 'A', 'Mantle'),
|
||||
path.join(appFrameworksPath, 'Mantle.framework'),
|
||||
path.join(appFrameworksPath, 'ReactiveCocoa.framework', 'Versions', 'A', 'ReactiveCocoa'),
|
||||
path.join(appFrameworksPath, 'ReactiveCocoa.framework'),
|
||||
path.join(appFrameworksPath, 'Squirrel.framework', 'Versions', 'A', 'Squirrel'),
|
||||
path.join(appFrameworksPath, 'Squirrel.framework')
|
||||
]
|
||||
}
|
||||
|
||||
var helperPath = generateHelperAppPath(opts, 'helper-path', null, callback)
|
||||
if (helperPath) {
|
||||
|
@ -88,8 +97,25 @@ function signDarwinApplication (opts, callback) {
|
|||
}
|
||||
|
||||
if (opts.entitlements) {
|
||||
// TODO: Signing darwin builds with entitlements
|
||||
return callback(new Error('Entitlements not yet supported for darwin.'))
|
||||
if (opts.platform === 'mas') {
|
||||
// Sign with entitlements
|
||||
childPaths.forEach(function (path) {
|
||||
operations.push(function (cb) {
|
||||
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
|
||||
+ '--entitlements "' + opts['entitlements-inherit'] + '" \ '
|
||||
+ '"' + path + '"'
|
||||
, cb)
|
||||
})
|
||||
})
|
||||
operations.push(function (cb) {
|
||||
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
|
||||
+ '--entitlements "' + opts.entitlements + '" \ '
|
||||
+ '"' + opts.app + '"'
|
||||
, cb)
|
||||
})
|
||||
} else if (opts.platform === 'darwin') {
|
||||
// TODO: Signing darwin builds with entitlements
|
||||
}
|
||||
} else {
|
||||
// Otherwise normally
|
||||
childPaths.forEach(function (path) {
|
||||
|
@ -105,78 +131,25 @@ function signDarwinApplication (opts, callback) {
|
|||
, cb)
|
||||
})
|
||||
}
|
||||
|
||||
// Lastly verify codesign
|
||||
operations.push(function (cb) {
|
||||
child.exec('codesign -v --verbose=4 \ '
|
||||
+ '"' + opts.app + '"'
|
||||
, cb)
|
||||
})
|
||||
series(operations, function (err) {
|
||||
if (err) return callback(err)
|
||||
callback()
|
||||
})
|
||||
}
|
||||
|
||||
function signMASApplication (opts, callback) {
|
||||
var operations = []
|
||||
var appFrameworksPath = generateAppFrameworksPath(opts)
|
||||
var childPaths = [
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
|
||||
path.join(appFrameworksPath, 'Electron Framework.framework')
|
||||
]
|
||||
|
||||
var helperPath = generateHelperAppPath(opts, 'helper-path', null, callback)
|
||||
if (helperPath) {
|
||||
var helperExecutablePath = generateHelperAppExecutablePath(opts, helperPath, null, callback)
|
||||
if (helperExecutablePath) childPaths.unshift(helperExecutablePath, helperPath)
|
||||
else return callback(new Error('Missing Electron Helper, stopped.'))
|
||||
}
|
||||
|
||||
var helperEHPath = generateHelperAppPath(opts, 'helper-eh-path', ' EH', callback)
|
||||
if (helperEHPath) {
|
||||
var helperEHExecutablePath = generateHelperAppExecutablePath(opts, helperEHPath, ' EH', callback)
|
||||
if (helperEHExecutablePath) childPaths.unshift(helperEHExecutablePath, helperEHPath)
|
||||
else return callback(new Error('Missing Electron Helper EH, stopped.'))
|
||||
}
|
||||
|
||||
var helperNPPath = generateHelperAppPath(opts, 'helper-np-path', ' NP', callback)
|
||||
if (helperNPPath) {
|
||||
var helperNPExecutablePath = generateHelperAppExecutablePath(opts, helperNPPath, ' NP', callback)
|
||||
if (helperNPExecutablePath) childPaths.unshift(helperNPExecutablePath, helperNPPath)
|
||||
else return callback(new Error('Missing Electron Helper NP, stopped.'))
|
||||
}
|
||||
|
||||
// Sign with entitlements
|
||||
childPaths.forEach(function (path) {
|
||||
if (opts.entitlements) {
|
||||
// Check entitlements
|
||||
operations.push(function (cb) {
|
||||
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
|
||||
+ '--entitlements "' + opts['entitlements-inherit'] + '" \ '
|
||||
+ '"' + path + '"'
|
||||
, cb)
|
||||
child.exec('codesign -d --entitlements - \ '
|
||||
+ '"' + opts.app + '"'
|
||||
, function (err, stdout, stderr) {
|
||||
if (err) return cb(err)
|
||||
if (!stdout) return cb(new Error('Entitlements failed to be signed.'))
|
||||
cb()
|
||||
})
|
||||
})
|
||||
})
|
||||
operations.push(function (cb) {
|
||||
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
|
||||
+ '--entitlements "' + opts.entitlements + '" \ '
|
||||
+ '"' + opts.app + '"'
|
||||
, cb)
|
||||
})
|
||||
// Lastly verify codesign
|
||||
operations.push(function (cb) {
|
||||
child.exec('codesign -v --verbose=4 \ '
|
||||
+ '"' + opts.app + '"'
|
||||
, cb)
|
||||
})
|
||||
// And check entitlements
|
||||
operations.push(function (cb) {
|
||||
child.exec('codesign -d --entitlements - \ '
|
||||
+ '"' + opts.app + '"'
|
||||
, function (err, stdout, stderr) {
|
||||
if (err) return cb(err)
|
||||
if (!stdout) return cb(new Error('Entitlements failed to be signed.'))
|
||||
cb()
|
||||
})
|
||||
})
|
||||
}
|
||||
series(operations, function (err) {
|
||||
if (err) return callback(err)
|
||||
callback()
|
||||
|
@ -184,14 +157,24 @@ function signMASApplication (opts, callback) {
|
|||
}
|
||||
|
||||
module.exports = function sign (app, opts, cb) {
|
||||
if (!opts) opts = {}
|
||||
opts.app = app
|
||||
if (!opts) opts = {app: app}
|
||||
if (!cb) cb = function () {}
|
||||
if (!opts.app) return cb(new Error('Path to aplication must be specified.'))
|
||||
if (!fs.existsSync(opts.app)) return cb(new Error('Application not found.'))
|
||||
if (!opts.platform || opts.platform === 'darwin') {
|
||||
opts.platform = 'darwin' // fallback to darwin if no platform specified
|
||||
} else if (opts.platform === 'mas') {
|
||||
|
||||
// Match platform if none is provided
|
||||
if (!opts.platform) {
|
||||
var appFrameworksPath = generateAppFrameworksPath(opts)
|
||||
if (!fs.existsSync(path.join(appFrameworksPath, 'Mantle.framework'))
|
||||
&& !fs.existsSync(path.join(appFrameworksPath, 'ReactiveCocoa.framework'))
|
||||
&& !fs.existsSync(path.join(appFrameworksPath, 'Squirrel.framework'))) {
|
||||
// These frameworks do not exist in an Mac App Store version
|
||||
opts.platform = 'mas'
|
||||
} else {
|
||||
opts.platform = 'darwin'
|
||||
}
|
||||
}
|
||||
if (opts.platform === 'mas') {
|
||||
// To sign apps for Mac App Store, an entitlements file is required,
|
||||
// especially for app sandboxing (as well some other services).
|
||||
// Fallback entitlements for sandboxing by default:
|
||||
|
@ -200,11 +183,15 @@ module.exports = function sign (app, opts, cb) {
|
|||
// Further reading: https://developer.apple.com/library/mac/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html
|
||||
if (!opts.entitlements) opts.entitlements = path.join(__dirname, 'mas.default.plist')
|
||||
if (!opts['entitlements-inherit']) opts['entitlements-inherit'] = path.join(__dirname, 'mas.inherit.default.plist')
|
||||
} else if (opts.platform === 'darwin') {
|
||||
// Not necessary to have entitlements for non Mac App Store distribution
|
||||
if (opts.entitlements) return cb(new Error('Unable to sign for darwin platform with entitlements.'))
|
||||
} else {
|
||||
return cb(new Error('Only platform darwin and mas are supported.'))
|
||||
}
|
||||
series([
|
||||
function (cb) {
|
||||
// Checking identity with series for async execution of child process
|
||||
if (!opts.identity) {
|
||||
child.exec('security find-identity', function (err, stdout, stderr) {
|
||||
if (err) return cb(new Error('Error in finding an identity.'))
|
||||
|
@ -212,14 +199,14 @@ module.exports = function sign (app, opts, cb) {
|
|||
var location
|
||||
for (var i = 0, l = lines.length; i < l && !opts.identity; i++) {
|
||||
var line = lines[i]
|
||||
if (opts.platform === 'darwin') {
|
||||
location = line.indexOf('Developer ID Application')
|
||||
if (opts.platform === 'mas') {
|
||||
location = line.indexOf('3rd Party Mac Developer Application')
|
||||
if (location >= 0) {
|
||||
opts.identity = line.substring(location, line.length - 1)
|
||||
break
|
||||
}
|
||||
} else if (opts.platform === 'mas') {
|
||||
location = line.indexOf('3rd Party Mac Developer Application')
|
||||
} else if (opts.platform === 'darwin') {
|
||||
location = line.indexOf('Developer ID Application')
|
||||
if (location >= 0) {
|
||||
opts.identity = line.substring(location, line.length - 1)
|
||||
break
|
||||
|
@ -233,10 +220,6 @@ module.exports = function sign (app, opts, cb) {
|
|||
}
|
||||
], function (err) {
|
||||
if (err) return cb(err)
|
||||
if (opts.platform === 'darwin') {
|
||||
return signDarwinApplication(opts, cb)
|
||||
} else if (opts.platform === 'mas') {
|
||||
return signMASApplication(opts, cb)
|
||||
}
|
||||
return signApplication(opts, cb)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ function createDefaultsTest (release) {
|
|||
t.timeoutAfter(config.timeout)
|
||||
|
||||
var app = util.generateAppPath(release)
|
||||
var opts = Object.create(release)
|
||||
var opts = null // test with no options
|
||||
|
||||
waterfall([
|
||||
function (cb) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче