-
Notifications
You must be signed in to change notification settings - Fork 560
/
after_sign_hook.js
85 lines (75 loc) · 2.44 KB
/
after_sign_hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');
module.exports = async function (params) {
// Only notarize the app on Mac OS only.
if (process.platform !== 'darwin') {
return;
}
const appStoreConnectKeyPath = path.join(
process.env.HOME,
'.configure',
'simplenote-electron',
'secrets',
'app_store_connect_api_key.p8'
);
const envPath = path.join(
process.env.HOME,
'.a8c-apps/simplenote-electron.env'
);
if (fs.existsSync(envPath)) {
dotenv.config({ path: envPath });
} else {
// eslint-disable-next-line no-console
console.log(
`No env file found at ${envPath}. Looking for required env vars individually...`
);
let errors = [];
if (process.env.APP_STORE_CONNECT_API_KEY_KEY_ID === undefined) {
errors.push(
'APP_STORE_CONNECT_API_KEY_KEY_ID value not found in env. Please set it.'
);
}
if (process.env.APP_STORE_CONNECT_API_KEY_ISSUER_ID === undefined) {
errors.push(
'APP_STORE_CONNECT_API_KEY_ISSUER_ID value not found in env. Please set it.'
);
}
if (fs.existsSync(appStoreConnectKeyPath) === false) {
errors.push(
`Key file not found at ${appStoreConnectKeyPath}. Please add it.`
);
}
if (errors.length > 0) {
throw new Error(
`Could not begin signing macOS build. Errors: ${errors.join('\n')}`
);
} else {
console.log('All required env vars found. Moving on...');
}
}
// Same appId in electron-builder.
let appId = 'com.automattic.simplenote';
let appPath = params.appOutDir
? path.join(
params.appOutDir,
`${params.packager.appInfo.productFilename}.app`
)
: params.artifactPaths[0].replace(new RegExp('.blockmap'), '');
if (!fs.existsSync(appPath)) {
throw new Error(`Cannot find application at: ${appPath}`);
}
console.log(`Notarizing ${appId} found at ${appPath}`); // eslint-disable-line no-console
try {
const electron_notarize = require('@electron/notarize');
await electron_notarize.notarize({
appPath: appPath,
appleApiKey: appStoreConnectKeyPath,
appleApiKeyId: process.env.APP_STORE_CONNECT_API_KEY_KEY_ID,
appleApiIssuer: process.env.APP_STORE_CONNECT_API_KEY_ISSUER_ID,
});
} catch (error) {
throw new Error(`Notarization failed with error:\n${error}`);
}
console.log(`Done notarizing ${appId}`); // eslint-disable-line no-console
};