generated from electron-react-boilerplate/electron-react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.ts
162 lines (146 loc) · 4.63 KB
/
build.ts
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
import '@johnlindquist/kit';
import fsExtra from 'fs-extra';
import { external, include } from './src/main/shims';
import { Arch, Platform, build } from 'electron-builder';
import type { Configuration, PackagerOptions } from 'electron-builder';
import packageJson from './package.json';
let platform: 'linux' | 'mac' | 'win';
let arch: 'arm64' | 'x64';
let publish: 'always' | 'never' | undefined;
if (process.argv.length <= 2) {
if (process.platform === 'darwin') {
platform = 'mac';
} else if (process.platform === 'win32') {
platform = 'win';
} else if (process.platform === 'linux') {
platform = 'linux';
} else {
throw new Error(`Unsupported platform: ${process.platform}`);
}
arch = process.arch as 'arm64' | 'x64';
publish = undefined;
} else {
platform = (await arg('platform')) as 'linux' | 'mac' | 'win';
arch = (await arg('arch')) as 'arm64' | 'x64';
publish = (await arg('publish')) as 'always' | 'never' | undefined;
}
const electronVersion = packageJson.devDependencies.electron.replace('^', '');
const onlyModules = include();
console.log(`🛠️ Building for ${platform} ${arch} ${publish} using ${electronVersion}`);
console.log(`Will only build: ${onlyModules}`);
const asarUnpack = ['assets/**/*'];
const dirFiles = (await fsExtra.readdir('.', { withFileTypes: true })).filter(
(dir) =>
!(
dir.name.startsWith('out') ||
dir.name.startsWith('node_modules') ||
dir.name.startsWith('release') ||
dir.name.startsWith('assets') ||
dir.name.startsWith('package.json')
),
);
4;
const files = dirFiles
.filter((file) => file.isDirectory())
.map((dir) => `!${dir.name}/**/*`)
.concat(dirFiles.filter((file) => file.isFile()).map((file) => `!${file.name}`));
console.log({ files });
const config: Configuration = {
appId: 'app.scriptkit', // Updated appId from package.json
artifactName: '${productName}-macOS-${version}-${arch}.${ext}',
productName: 'Script Kit', // Updated productName from package.json
directories: {
output: './release',
buildResources: 'build',
},
asar: false,
asarUnpack,
// afterSign: platform === 'mac' ? afterSign : undefined,
files,
nsis: {
oneClick: false,
perMachine: false,
allowToChangeInstallationDirectory: true,
shortcutName: 'Script Kit',
},
mac: {
notarize: true,
icon: 'assets/icons/mac/icon.icns',
category: 'public.app-category.productivity', // Keep as is or update based on package.json if needed
hardenedRuntime: true,
entitlements: 'assets/entitlements.mac.plist',
gatekeeperAssess: true,
extendInfo: {
CFBundleDocumentTypes: [
{
CFBundleTypeName: 'Folders',
CFBundleTypeRole: 'Viewer',
LSHandlerRank: 'Alternate',
LSItemContentTypes: ['public.folder', 'com.apple.bundle', 'com.apple.package', 'com.apple.resolvable'],
},
{
CFBundleTypeName: 'UnixExecutables',
CFBundleTypeRole: 'Shell',
LSHandlerRank: 'Alternate',
LSItemContentTypes: ['public.unix-executable'],
},
],
},
},
win: {
icon: 'assets/icon.png',
artifactName: '${productName}-Windows-${version}-${arch}.${ext}',
},
linux: {
icon: 'assets/icons/mac/icon.icns',
category: 'Development',
executableName: 'scriptkit',
artifactName: '${productName}-Linux-${version}-${arch}.${ext}',
},
protocols: [
{
name: 'kit',
schemes: ['kit'],
},
],
publish: {
provider: 'github',
owner: 'johnlindquist',
repo: 'kitapp',
releaseType: 'prerelease',
},
};
let targets: PackagerOptions['targets'];
const archFlag = Arch[arch as 'x64' | 'arm64'];
switch (platform) {
case 'mac':
targets = Platform.MAC.createTarget(['dmg', 'zip'], archFlag);
break;
case 'win':
targets = Platform.WINDOWS.createTarget(['nsis'], archFlag);
break;
case 'linux':
targets = Platform.LINUX.createTarget(['AppImage', 'deb', 'rpm'], archFlag);
break;
default:
throw new Error(`Unsupported platform: ${platform}`);
}
console.log('Building with config');
try {
const uninstallDeps = external();
console.log(`Removing external dependencies: ${uninstallDeps.join(', ')} before @electron/rebuild kicks in`);
console.log(process.platform, process.arch, process.cwd());
if (uninstallDeps.length > 0) {
const pkg = await fsExtra.readJson('package.json');
console.log(`Optional dependencies before: ${JSON.stringify(pkg.optionalDependencies, null, 2)}`);
}
const result = await build({
config,
publish,
targets,
});
console.log('Build result', result);
} catch (e) {
console.error('Build failed', e);
process.exit(1);
}