Skip to content

Commit 99a4313

Browse files
committed
Trim PR to more minimal example
1 parent 115c98c commit 99a4313

File tree

4 files changed

+37
-98
lines changed

4 files changed

+37
-98
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ If you can't use GitHub, you can use other providers:
55
- [Complete electron-updater HTTP example](https://gist.github.com/iffy/0ff845e8e3f59dbe7eaf2bf24443f104)
66
- [Complete electron-updater from gitlab.com private repo example](https://gist.github.com/Slauta/5b2bcf9fa1f6f6a9443aa6b447bcae05)
77

8-
**NOTE:** If you want to run through this whole process, you will need to fork this repo on GitHub and replace all instances of `iffy` with your GitHub username before doing the following steps.
8+
**NOTE:** If you want to run through this whole process, either fork this repo or [start your own from a template](https://github.com/iffy/electron-updater-example/generate). Then replace all instances of `iffy` with your GitHub username before doing the following steps.
99

1010
1. For macOS, you will need a code-signing certificate.
1111

1212
Install Xcode (from the App Store), then follow [these instructions](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW6) to make sure you have a "Developer ID Application" certificate. If you'd like to export the certificate (for automated building, for instance) [you can](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW7). You would then follow [these instructions](https://www.electron.build/code-signing).
1313

1414
This example application is set up to perform code-signing and notarization on Mac OS provided that a `Developer ID
1515
Application` certificate is installed in the default keychain. The following environment variables are important for the signing process:
16+
1617
- `CSC_IDENTITY_AUTO_DISCOVERY` - controls whether `electron-builder` tries to sign the application; default is `true`, set to `false` to skip signing
17-
- `APPLEID` - the Apple ID to use for notarization (required for signing).
18-
- `APPLEIDPASS` - the password to use with the specified Apple ID for notarization (required for signing). Apple recommends setting up an app-specific password to safeguard the Apple ID password (see [Apple Support](https://support.apple.com/en-us/HT204397)) for more information.
18+
- `APPLE_ID` - the Apple ID to use for notarization (required for signing).
19+
- `APPLE_ID_PASSWORD` - the password to use with the specified Apple ID for notarization (required for signing). Apple recommends setting up an app-specific password to safeguard the Apple ID password (see [Apple Support](https://support.apple.com/en-us/HT204397)) for more information.
20+
21+
To enable code-signing and notarization:
22+
23+
export CSC_IDENTITY_AUTO_DISCOVERY="true"
24+
export APPLE_ID="<your Apple ID>"
25+
export APPLE_ID_PASSWORD="<your Apple Password>"
1926

2027
2. Adjust `package.json` if needed.
2128

@@ -51,7 +58,7 @@ If you can't use GitHub, you can use other providers:
5158

5259
[Environment]::SetEnvironmentVariable("GH_TOKEN","<YOUR_TOKEN_HERE>","User")
5360

54-
Make sure to restart IDE/Terminal to inherit latest env variable.
61+
Make sure to restart your IDE/Terminal to inherit latest env variable.
5562

5663
5. Publish for your platform with:
5764

@@ -65,7 +72,7 @@ If you can't use GitHub, you can use other providers:
6572

6673
...
6774
"scripts": {
68-
"publish": "build --mac --win -p always"
75+
"publish": "electron-builder --mac --win -p always"
6976
},
7077
...
7178

build/entitlements.mac.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>com.apple.security.cs.debugger</key>
6-
<true/>
75
<key>com.apple.security.cs.allow-jit</key>
86
<true/>
97
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>

build/notarize.js

Lines changed: 19 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,30 @@
11
const { notarize } = require('electron-notarize');
22
const path = require('path');
3-
const fs = require('fs');
4-
const jsYaml = require('js-yaml');
5-
6-
function findPackageJsonPath() {
7-
let dirName = process.cwd();
8-
9-
while(dirName) {
10-
const packageJsonFilePath = path.join(dirName, 'package.json');
11-
if (fs.existsSync(packageJsonFilePath)) {
12-
return packageJsonFilePath;
13-
} else if (dirName === '/') {
14-
break;
15-
}
16-
dirName = path.dirname(dirName);
17-
}
18-
return undefined;
19-
}
20-
21-
function getAppId(context) {
22-
// Try to get the appId from the packager
23-
const config = context.packager.info._configuration;
24-
if (config && config.appId) {
25-
console.log('Found appId in packager');
26-
return config.appId;
27-
}
28-
29-
// Try to get the appId from the builder-effective-config.yml file
30-
const builderEffectiveConfigPath = path.join(context.outDir, 'builder-effective-config.yaml');
31-
if (fs.existsSync(builderEffectiveConfigPath)) {
32-
const builderEffectiveConfigText = fs.readFileSync(builderEffectiveConfigPath);
33-
const builderEffectiveConfig = jsYaml.load(builderEffectiveConfigText);
34-
if (builderEffectiveConfig['appId']) {
35-
console.log('Found appId in %s', builderEffectiveConfigPath);
36-
return builderEffectiveConfig['appId'];
37-
}
38-
}
39-
40-
// Try to get the appId from the package.json file
41-
const packageJsonFilePath = findPackageJsonPath();
42-
if (packageJsonFilePath) {
43-
try {
44-
const packageJson = require(packageJsonFilePath);
45-
if (packageJson['build'] && packageJson['build']['appId']) {
46-
console.log('Found appId in %s', packageJsonFilePath);
47-
return packageJson['build']['appId'];
48-
}
49-
} catch (err) {
50-
// swallow the error
51-
console.log('Failed to read %s: %s', packageJsonFilePath, err);
52-
}
53-
}
54-
55-
// finally, check the APP_ID environment variable
56-
if (process.env.APP_ID) {
57-
console.log('Found appId in APP_ID environment variable');
58-
return process.env.APP_ID;
59-
}
60-
throw new Error('Unable to find the application ID');
61-
}
623

634
exports.default = async function notarizing(context) {
64-
const { electronPlatformName } = context;
65-
if (electronPlatformName !== 'darwin' || process.env.CSC_IDENTITY_AUTO_DISCOVERY === 'false') {
5+
if (context.electronPlatformName !== 'darwin' || process.env.CSC_IDENTITY_AUTO_DISCOVERY === 'false') {
6+
console.log("Skipping notarization");
667
return;
678
}
9+
console.log("Notarizing...")
6810

69-
const appId = getAppId(context);
11+
const appBundleId = context.packager.appInfo.info._configuration.appId;
7012
const appName = context.packager.appInfo.productFilename;
71-
const appPath = path.normalize(path.join(context.outDir, 'mac', `${appName}.app`));
72-
console.log('calling notarize for appId = %s with appPath = %s', appId, appPath);
13+
const appPath = path.normalize(path.join(context.appOutDir, `${appName}.app`));
14+
const appleId = process.env.APPLE_ID;
15+
const appleIdPassword = process.env.APPLE_ID_PASSWORD;
16+
if (!appleId) {
17+
console.warn("Not notarizing: Missing APPLE_ID environment variable");
18+
return;
19+
}
20+
if (!appleIdPassword) {
21+
console.warn("Not notarizing: Missing APPLE_ID_PASSWORD environment variable");
22+
return;
23+
}
7324
return notarize({
74-
appBundleId: appId,
75-
appPath: appPath,
76-
appleId: process.env.APPLEID,
77-
appleIdPassword: process.env.APPLEIDPASS,
25+
appBundleId,
26+
appPath,
27+
appleId,
28+
appleIdPassword,
7829
});
7930
};

package.json

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,32 @@
11
{
22
"name": "electron-updater-example",
3-
"version": "0.7.2",
3+
"version": "0.8.1",
44
"main": "main.js",
55
"description": "electron-updater example project",
66
"author": "Matt Haggard",
77
"scripts": {
8-
"publish": "electron-builder -p always",
9-
"publish-linux-docker": "./build/linuxInstallers.sh"
8+
"publish": "electron-builder -p always"
109
},
1110
"devDependencies": {
1211
"electron": "^14.0.1",
1312
"electron-builder": "^22.11.7",
14-
"js-yaml": "^4.1.0"
13+
"electron-notarize": "^1.1.1"
1514
},
1615
"dependencies": {
1716
"electron-log": "^4.4.1",
1817
"electron-updater": "^4.3.9"
1918
},
2019
"build": {
2120
"appId": "com.github.iffy.electronupdaterexample",
22-
"productName": "Electron Updater Example",
23-
"afterSign": "./build.notarize.js",
24-
"directories": {
25-
"output": "dist"
26-
},
27-
"files": [
28-
"!.DS_Store"
29-
],
21+
"afterSign": "./build/notarize.js",
3022
"mac": {
31-
"category": "your.app.category.type",
32-
"target": "default",
33-
"type": "distribution",
34-
"hardenedRuntime": true,
35-
"gatekeeperAsses": false,
36-
"entitlements": "./build/entitlements.mac.plist"
37-
},
38-
"dmg": {
39-
"sign": false
23+
"category": "your.app.category.type"
4024
},
4125
"win": {
4226
"target": "nsis"
4327
},
4428
"nsis": {
45-
"oneClick": false,
46-
"allowToChangeInstallationDirectory": true
29+
"oneClick": false
4730
},
4831
"linux": {
4932
"category": "your.app.category.type",

0 commit comments

Comments
 (0)