Last active
February 16, 2021 15:14
-
-
Save christarnowski/e2d3af7697d67661f1877ad8ef82faaf to your computer and use it in GitHub Desktop.
A set of files required for making notarization work for Electron Builder on macOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
See https://christarnowski.com/making-notarization-work-on-macos-for-electron-apps-built-with-electron-builder for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<!-- https://github.com/electron/electron-notarize#prerequisites --> | |
<key>com.apple.security.cs.allow-jit</key> | |
<true/> | |
<key>com.apple.security.cs.allow-unsigned-executable-memory</key> | |
<true/> | |
<key>com.apple.security.cs.allow-dyld-environment-variables</key> | |
<true/> | |
<!-- https://github.com/electron-userland/electron-builder/issues/3940 --> | |
<key>com.apple.security.cs.disable-library-validation</key> | |
<true/> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {notarize} = require("electron-notarize"); | |
exports.default = async function notarizing(context) { | |
const {electronPlatformName, appOutDir} = context; | |
if (electronPlatformName !== "darwin") { | |
return; | |
} | |
const appName = context.packager.appInfo.productFilename; | |
return await notarize({ | |
appBundleId: process.env.APP_BUNDLE_ID, | |
appPath: `${appOutDir}/${appName}.app`, | |
appleId: process.env.APPLE_ID, | |
appleIdPassword: process.env.APPLE_ID_PASSWORD, | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {FileContentsTransformer, replaceFileContents} from "./common"; | |
const ELECTRON_NOTARIZE_INDEX_PATH = "build/node_modules/electron-notarize/lib/index.js"; | |
async function main() { | |
const transformer: FileContentsTransformer = (content: string) => { | |
return content.replace( | |
"spawn('zip', ['-r', '-y', zipPath, path.basename(opts.appPath)]", | |
"spawn('ditto', ['-c', '-k', '--sequesterRsrc', '--keepParent', path.basename(opts.appPath), zipPath]" | |
); | |
}; | |
await replaceFileContents(ELECTRON_NOTARIZE_INDEX_PATH, transformer); | |
} | |
// noinspection JSIgnoredPromiseFromCall | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {promises as fsp} from "fs"; | |
export type FileContentsTransformer = (content: string) => string; | |
export async function replaceFileContents(path: string, transformer: FileContentsTransformer) { | |
let fh: fsp.FileHandle | null = null; | |
let content: string = ""; | |
try { | |
fh = await fsp.open(path, "r"); | |
if (fh) { | |
content = (await fh.readFile()).toString(); | |
} | |
} finally { | |
if (fh) { | |
await fh.close(); | |
} | |
} | |
try { | |
fh = await fsp.open(path, "w"); | |
if (fh) { | |
await fh.writeFile(transformer(content)); | |
} | |
} finally { | |
if (fh) { | |
await fh.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment