Merge pull request #31 from sethlu/ignore-file-path

opts.ignore to filter out undesired file paths for signing
This commit is contained in:
Zhuo Lu 2016-05-01 21:09:12 +08:00
Родитель 829b2a5ef5 37ad13d970
Коммит 408268f4fb
3 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

@ -105,6 +105,11 @@ Signing platform `mas` will look for `3rd Party Mac Developer Application: * (*)
The keychain name.
Default to system default keychain (`login.keychain`).
`ignore` - *String*
Regex or function that signals ignoring a file before signing.
Default to undefined.
`platform` - *String*
Build platform of Electron.

Просмотреть файл

@ -7,4 +7,5 @@ entitlements Path to entitlements file for signing Mac App Store
entitlements-inherit Path to child entitlements file for signing frameworks and bundles of Mac App Store application.
identity Name of certificate to use when signing. Default to retrieve from keychain specified, see below.
keychain The keychain name. Default to system default keychain (`login.keychain`).
ignore Regex that signals ignoring a file before signing. Default to undefined.
platform Build platform of Electron. Allowed values: `darwin`, `mas`. Default to auto detect from application package.

Просмотреть файл

@ -87,9 +87,6 @@ function generateAppFrameworksPath (opts) {
}
function signApplication (opts, callback) {
var operations = []
var appContentsPath = generateAppContentsPath(opts)
function isFileBinary (filePath) {
var buf = fs.readFileSync(filePath)
for (var i = 0, l = buf.length; i < l; i++) {
@ -143,6 +140,19 @@ function signApplication (opts, callback) {
})
}
function ignoreFilePath (opts, filePath) {
if (opts.ignore) {
if (typeof opts.ignore === 'function') {
return opts.ignore(filePath)
} else if (typeof opts.ignore === 'string') {
return filePath.match(opts.ignore)
}
}
return false
}
var operations = []
var appContentsPath = generateAppContentsPath(opts)
var childPaths = []
walkSync(appContentsPath)
if (opts.binaries) childPaths = childPaths.concat(opts.binaries)
@ -158,6 +168,7 @@ function signApplication (opts, callback) {
if (opts.entitlements) {
// Sign with entitlements
childPaths.forEach(function (filePath) {
if (ignoreFilePath(opts, filePath)) return
operations.push(function (cb) {
child.execFile('codesign', args.concat('--entitlements', opts['entitlements-inherit'], filePath), function (err, stdout, stderr) {
if (err) return cb(err)
@ -176,6 +187,7 @@ function signApplication (opts, callback) {
} else {
// Otherwise normally
childPaths.forEach(function (filePath) {
if (ignoreFilePath(opts, filePath)) return
operations.push(function (cb) {
child.execFile('codesign', args.concat(filePath), function (err, stdout, stderr) {
if (err) return cb(err)
@ -275,6 +287,9 @@ function sign (opts, cb) {
if (opts.binaries) {
if (!Array.isArray(opts.binaries)) return cb(new Error('Additional binaries should be an Array.'))
}
if (opts.ignore) {
if (typeof opts.ignore !== 'function' || typeof opts.ignore !== 'string') return cb(new Error('Ignore filter should be either a function or a string.'))
}
series([
function (cb) {
// Checking identity with series for async execution of child process