This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdist.js
124 lines (110 loc) · 3.88 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
/* 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));
}
});
});
const arch = process.env.TEMPLATE_ARCH || 'x64';
if ((['x64', 'arm64'].indexOf(arch) < 0)) {
console.log(`${process.platform} ${arch} is not supported.`);
}
// 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
const targets = Platform.MAC.createTarget(['zip', 'dmg'], Arch.universal);
const opts = {
targets,
config: {
appId: 'com.webcatalog.chromeless',
productName: 'Chromeless',
asar: true,
asarUnpack: [
'**/build/chromeless-helper/**/*',
'**/build/chromeless-helper-browser-instances/**/*',
'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',
},
mac: {
category: 'public.app-category.utilities',
hardenedRuntime: true,
gatekeeperAssess: false,
darkModeSupport: true,
entitlements: 'build-resources/entitlements.mac.plist',
entitlementsInherit: 'build-resources/entitlements.mac.plist',
},
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.chromeless',
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);
});