Skip to content

Instantly share code, notes, and snippets.

@phuonghuynh
Created March 17, 2025 19:04
Show Gist options
  • Save phuonghuynh/80a32ffc9ee99ed50fda562bb8ce92c1 to your computer and use it in GitHub Desktop.
Save phuonghuynh/80a32ffc9ee99ed50fda562bb8ce92c1 to your computer and use it in GitHub Desktop.
Electron Builder after sign script to sign+notairze+create-dmg
const signApp = async (context) => {
debug.enable('electron-osx-sign'); // enable debug flag
const opts = {
version: BuildConfig.electronVersion, // electron version
app: appDir,
platform: "darwin",
type: "distribution",
identity: xxx,
ignore: (file) => { // return unneeded signing files
return file.endsWith(".jar")
|| file.endsWith(".icns")
|| file.endsWith(".pak");
},
provisioningProfile: "{required path to your embedded.provisionprofile}",
optionsForFile: (filePath) => {
// All .app that need to access to macOS API required entitilments settings like "Keychain API"
// need to be signed using custom entitlements file, otherwise we can let the framework use default settings.
if (filePath.endsWith("{your .app name}")) {
return {
hardenedRuntime: true,
entitlements: "{custom entitilements file}"
};
}
return null; // default setting for others
},
};
try {
console.log(`sign app using native osxsign npm`);
const {signAsync} = require("@electron/osx-sign");
await signAsync(opts);
console.log(`sign app done`);
}
catch (err) {
console.error(`err: signApp`, err);
throw err;
}
}
const notarizeApp = async (context) => {
debug.enable('electron-notarize');
const conf = {
appBundleId: xxx,
appPath: xxx,
appleId: xxx,
appleIdPassword: xxx,
teamId: xxx,
};
try {
await notarize(conf);
console.log(`notarizeApp done`);
}
catch (err) {
console.error(`err: notarizeApp`, err);
throw err;
}
}
const createDmg = async (context) => {
console.log(`> createDmg mac.app=`, appDir);
for (const target of context.targets) {
console.log(`target=`, target);
if (target.name != 'dmg') {
continue;
}
try {
await target.build(appDir, context.arch);
}
catch (err) {
console.error(`err: createDmg`, err);
throw err;
}
}
}
module.exports = async (context) => {
await signApp(context);
await notarizeApp(context);
await createDmg(context);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment