This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
/
dist.js
205 lines (186 loc) · 6.16 KB
/
dist.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/* eslint-disable no-console */
const builder = require('electron-builder');
const { notarize } = require('electron-notarize');
const { Arch, Platform } = builder;
const { exec } = require('child_process');
// sometimes, notarization works but *.app does not have a ticket stapled to it
// this ensure the *.app has the notarization ticket
const verifyNotarizationAsync = (filePath) => new Promise((resolve, reject) => {
// eslint-disable-next-line no-console
console.log(`xcrun stapler validate ${filePath.replace(/ /g, '\\ ')}`);
exec(`xcrun stapler validate ${filePath.replace(/ /g, '\\ ')}`, (e, stdout, stderr) => {
if (e instanceof Error) {
reject(e);
return;
}
if (stderr) {
reject(new Error(stderr));
return;
}
if (stdout.indexOf('The validate action worked!') > -1) {
resolve(stdout);
} else {
reject(new Error(stdout));
}
});
});
// run each signing task at once
let codeSigningPromise = Promise.resolve();
const hsmCodeSignAsync = (filePath) => {
codeSigningPromise = codeSigningPromise
.then(() => new Promise((resolve, reject) => {
const {
AZURE_KEY_VAULT_TENANT_ID,
AZURE_KEY_VAULT_CLIENT_ID,
AZURE_KEY_VAULT_CLIENT_SECRET,
AZURE_KEY_VAULT_URI,
AZURE_KEY_VAULT_CERT_NAME,
} = process.env;
console.log('Signing', filePath);
const command = `azuresigntool sign -kvu ${AZURE_KEY_VAULT_URI} -kvc ${AZURE_KEY_VAULT_CERT_NAME} -kvt ${AZURE_KEY_VAULT_TENANT_ID} -kvi ${AZURE_KEY_VAULT_CLIENT_ID} -kvs ${AZURE_KEY_VAULT_CLIENT_SECRET} -tr http://rfc3161timestamp.globalsign.com/advanced -td sha256 '${filePath}'`;
exec(command, { shell: 'powershell.exe' }, (e, stdout, stderr) => {
if (e instanceof Error) {
console.log(stdout);
reject(e);
return;
}
if (stderr) {
reject(new Error(stderr));
return;
}
if (stdout.indexOf('Signing completed successfully') > -1) {
resolve(stdout);
} else {
reject(new Error(stdout));
}
});
}));
return codeSigningPromise;
};
const arch = process.env.TEMPLATE_ARCH || 'x64';
if ((['x64', 'arm64'].indexOf(arch) < 0)) {
console.log(`${process.platform} ${arch} is not supported.`);
}
console.log(`Building for: ${process.platform} ${process.platform !== 'linux' ? 'x64 + arm64' : arch}`);
let targets;
switch (process.platform) {
case 'darwin': {
// use Arch.universal because
// electron-updater 4.3.10 -> 4.5.1 has a bug preventing
// Intel-based Macs from updating if there exists Arch.arm64 builds
// https://github.com/electron-userland/electron-builder/pull/6212
targets = Platform.MAC.createTarget(['zip', 'dmg'], Arch.universal);
break;
}
case 'win32': {
targets = Platform.WINDOWS.createTarget(['nsis'], Arch.arm64, Arch.x64);
break;
}
default:
case 'linux': {
targets = Platform.LINUX.createTarget(['AppImage', 'tar.gz'], Arch[arch]);
break;
}
}
const opts = {
targets,
config: {
appId: 'com.webcatalog.jordan',
productName: 'WebCatalog',
asar: true,
asarUnpack: [
'default-app-icons/**/*',
'**/node_modules/regedit/**/*',
'**/rcedit*.exe',
'**/build/vbs/**/*',
'**/build/**/Shortcut.exe',
'**/build/**/*forked*',
],
files: [
'bin/**/*',
'default-app-icons/**/*',
'!tests/**/*',
'!docs/**/*',
'!catalog/**/*',
'!template/**/*',
// phantomjs binary is up to 50Mb but unused. Remove to bring down app size
'!node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs',
'!node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs.exe',
// heavy demo files
'!node_modules/image-q/demo/**/*',
],
directories: {
buildResources: 'build-resources',
},
protocols: {
name: 'WebCatalog',
schemes: ['webcatalog'],
},
win: {
// https://www.electron.build/configuration/win.html#how-do-delegate-code-signing
sign: (configuration) => hsmCodeSignAsync(configuration.path),
},
mac: {
category: 'public.app-category.utilities',
hardenedRuntime: true,
gatekeeperAssess: false,
darkModeSupport: true,
entitlements: 'build-resources/entitlements.mac.plist',
entitlementsInherit: 'build-resources/entitlements.mac.plist',
requirements: 'build-resources/electron-builder-requirements.txt',
},
linux: {
category: 'Utility',
packageCategory: 'utils',
},
publish: [
{
provider: 'generic',
channel: 'latest',
url: 'https://cdn-2.webcatalog.io/webcatalog',
useMultipleRangeRequest: true,
},
{
provider: 's3',
channel: 'latest',
bucket: 'cdn-2.webcatalog.io',
region: 'us-east-2',
path: '/webcatalog',
},
'github',
],
afterSign: (context) => {
// Only notarize app when forced in pull requests or when releasing using tag
const shouldNotarize = process.platform === 'darwin' && context.electronPlatformName === 'darwin' && process.env.CI_BUILD_TAG;
if (!shouldNotarize) return null;
console.log('Notarizing app...');
// https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
const { appOutDir } = context;
const appName = context.packager.appInfo.productFilename;
const appPath = `${appOutDir}/${appName}.app`;
return notarize({
appBundleId: 'com.webcatalog.jordan',
appPath,
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASSWORD,
})
.then(() => verifyNotarizationAsync(appPath))
.then((notarizedInfo) => {
// eslint-disable-next-line no-console
console.log(notarizedInfo);
});
},
},
};
Promise.resolve()
.then(() => builder.build(opts))
.then(() => {
console.log('build successful');
})
.catch((err) => {
console.log(err);
process.exit(1);
});