forked from webcatalog/webcatalog-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdist.js
137 lines (124 loc) · 3.9 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
/* 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));
}
});
});
console.log(`Machine: ${process.platform}`);
let targets;
switch (process.platform) {
case 'darwin': {
targets = Platform.MAC.createTarget(['zip', 'dmg'], Arch.x64, Arch.arm64);
break;
}
case 'win32': {
targets = Platform.WINDOWS.createTarget(['nsis'], Arch.x64);
break;
}
default:
case 'linux': {
targets = Platform.LINUX.createTarget(['AppImage', 'tar.gz'], Arch.x64, Arch.arm64);
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'],
},
mac: {
category: 'public.app-category.utilities',
hardenedRuntime: true,
gatekeeperAssess: false,
darkModeSupport: true,
entitlements: 'build-resources/entitlements.mac.plist',
entitlementsInherit: 'build-resources/entitlements.mac.plist',
},
linux: {
category: 'Utility',
packageCategory: 'utils',
},
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);
});