build(scripts): detect notarization method from environment variables

This commit is contained in:
Lukas Obermann
2023-10-08 12:34:59 +02:00
parent fb96847335
commit 2b89293a24
+33 -12
View File
@@ -1,5 +1,5 @@
// @ts-check
import { notarize as electronNotarize } from 'electron-notarize'
import { notarize as electronNotarize } from '@electron/notarize'
/**
* @param context {import("electron-builder").AfterPackContext}
@@ -10,16 +10,37 @@ export const notarize = async (context) => {
if (electronPlatformName === 'darwin') {
const appName = context.packager.appInfo.productFilename
console.log(`Notarizing "${appName}.app"...`)
await electronNotarize({
tool: "notarytool",
appPath: `${appOutDir}/${appName}.app`,
appleId: /** @type {string} */ (process.env.APPLEID),
appleIdPassword: /** @type {string} */ (process.env.APPLEIDPASS),
teamId: /** @type {string} */ (process.env.TEAMID),
})
console.log(`Notarization successful`)
if (typeof process.env.APPLEID === "string" && typeof process.env.APPLEIDPASS === "string" && typeof process.env.TEAMID === "string") {
console.log(`Notarizing "${appName}.app" via Apple ID ...`)
await electronNotarize({
tool: "notarytool",
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLEID,
appleIdPassword: process.env.APPLEIDPASS,
teamId: process.env.TEAMID,
})
console.log(`Notarization successful`)
} else if (typeof process.env.APPLEAPIKEY === "string" && typeof process.env.APPLEAPIKEYID === "string" && typeof process.env.APPLEAPIISSUER === "string") {
console.log(`Notarizing "${appName}.app" via App Store Connect API ...`)
await electronNotarize({
tool: "notarytool",
appPath: `${appOutDir}/${appName}.app`,
appleApiKey: process.env.APPLEAPIKEY,
appleApiKeyId: process.env.APPLEAPIKEYID,
appleApiIssuer: process.env.APPLEAPIISSUER,
})
console.log(`Notarization successful`)
} else if (typeof process.env.KEYCHAINPROFILE === "string") {
console.log(`Notarizing "${appName}.app" via Keychain ...`)
await electronNotarize({
tool: "notarytool",
appPath: `${appOutDir}/${appName}.app`,
keychain: process.env.KEYCHAIN,
keychainProfile: process.env.KEYCHAINPROFILE,
})
console.log(`Notarization successful`)
} else {
throw new Error(`Notarization failed: No valid authentication method found in environment. Please provide either APPLEID and APPLEIDPASS, or APPLEAPIKEY, APPLEAPIKEYID and APPLEAPIISSUER, or (optional) KEYCHAIN and KEYCHAINPROFILE.`)
}
}
}