电子建设者。如何仅在构建 mac 应用程序时挂钩 afterSign
electron-builder. How to hook afterSign only when building mac app
我有一个处理公证的签名后模块。
我只想在构建mac应用程序时执行它
我的package.json是这样的
"scripts": {
"build:mac": "node .electron-vue/build.js && electron-builder --mac",
"build:win": "node .electron-vue/build.js && electron-builder --win --x64 --ia32",
},
"build": {
"mac": {
"hardenedRuntime": true,
"entitlements": "./notarlization/entitlement.plist",
"entitlementsInherit": "./notarlization/entitlement.plist"
},
"afterSign": "./notarlization/after-sign.js"
}
而我的后签模块是这样的
module.exports = async () => {
if (process.platform === 'darwin') {
console.log(`公証通過申請中...`)
try {
await notarize({
appBundleId,
appPath,
appleId,
appleIdPassword,
ascProvider
})
console.log('公証通過完了')
} catch (error) {
console.log('公証通過失敗: ', error)
}
}
}
实际上,它工作正常。
因为我在 macOS 中构建 mac 应用程序并在 WinOS.
中构建 Win 应用程序
不过我觉得if (process.platform === 'darwin') {}
不太酷。
我想在 package.json 中做这样的事情。
有人知道怎么做吗?
从electron-builder documentation您可以在页面底部看到您可以在mac
配置对象中使用afterSign
“...以及所有常见的特定于平台的选项。”,我认为这是最好的方法。
否则你可以看到其他可用选项
function getBuilderFlags () {
// https://www.electron.build/cli
const winFlags = ['--win', '-w', '--windows']
const macFlags = ['--mac', '-m', '-o', '--macos']
const cmd = process.argv
console.log('Checking cmd arguments:', cmd)
const result = {}
result.isWinOn = cmd.some(flag => winFlags.includes(flag))
result.isMacOn = cmd.some(flag => macFlags.includes(flag))
return result
}
exports.default = async function (context) {
console.log(' start: After Sign Hook')
const flags = getBuilderFlags()
if (flags.isWinOn) {
console.log('processing windows...')
}
if (flags.isMacOn) {
console.log('processing mac...')
}
console.log('finish: After Sign Hook')
}
我有一个处理公证的签名后模块。
我只想在构建mac应用程序时执行它
我的package.json是这样的
"scripts": {
"build:mac": "node .electron-vue/build.js && electron-builder --mac",
"build:win": "node .electron-vue/build.js && electron-builder --win --x64 --ia32",
},
"build": {
"mac": {
"hardenedRuntime": true,
"entitlements": "./notarlization/entitlement.plist",
"entitlementsInherit": "./notarlization/entitlement.plist"
},
"afterSign": "./notarlization/after-sign.js"
}
而我的后签模块是这样的
module.exports = async () => {
if (process.platform === 'darwin') {
console.log(`公証通過申請中...`)
try {
await notarize({
appBundleId,
appPath,
appleId,
appleIdPassword,
ascProvider
})
console.log('公証通過完了')
} catch (error) {
console.log('公証通過失敗: ', error)
}
}
}
实际上,它工作正常。
因为我在 macOS 中构建 mac 应用程序并在 WinOS.
中构建 Win 应用程序不过我觉得if (process.platform === 'darwin') {}
不太酷。
我想在 package.json 中做这样的事情。
有人知道怎么做吗?
从electron-builder documentation您可以在页面底部看到您可以在mac
配置对象中使用afterSign
“...以及所有常见的特定于平台的选项。”,我认为这是最好的方法。
否则你可以看到其他可用选项
function getBuilderFlags () {
// https://www.electron.build/cli
const winFlags = ['--win', '-w', '--windows']
const macFlags = ['--mac', '-m', '-o', '--macos']
const cmd = process.argv
console.log('Checking cmd arguments:', cmd)
const result = {}
result.isWinOn = cmd.some(flag => winFlags.includes(flag))
result.isMacOn = cmd.some(flag => macFlags.includes(flag))
return result
}
exports.default = async function (context) {
console.log(' start: After Sign Hook')
const flags = getBuilderFlags()
if (flags.isWinOn) {
console.log('processing windows...')
}
if (flags.isMacOn) {
console.log('processing mac...')
}
console.log('finish: After Sign Hook')
}