-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ts
107 lines (89 loc) · 2.57 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
import * as readlineSync from 'readline-sync';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import * as archiver from 'archiver';
import { Options, packager } from '@electron/packager';
const [, , platformArg, buildPathArg] = process.argv;
let platformOption: string | undefined;
let pathOption: string;
if (!platformArg) {
platformOption = readlineSync.question(
`select platform. all - for all platforms or win32, darwin, linux. (empty will default to current platform)${os.EOL}`,
);
} else {
if (platformArg !== 'CURRENT_OS') {
platformOption = platformArg;
}
}
if (!buildPathArg) {
pathOption = readlineSync.question(
`select output folder. (empty will default to home dir)${os.EOL}`,
);
} else {
pathOption = buildPathArg;
}
process.on('unhandledRejection', (error) => {
throw error;
});
(async (): Promise<void> => {
const options: Options = {
dir: './',
tmpdir: false,
icon: './icons/icon.png',
arch: 'x64',
ignore: [
/.git/,
/.vscode/,
/.idea/,
/node_modules\/api/,
/node_modules\/app/,
],
overwrite: true,
win32metadata: {
ProductName: 'KolpaqueClientElectron',
InternalName: 'KolpaqueClientElectron',
FileDescription: 'KolpaqueClientElectron',
OriginalFilename: 'KolpaqueClientElectron.exe',
},
asar: true,
prune: true,
out: undefined,
};
let platforms;
if (platformOption === 'all') {
platforms = ['win32', 'darwin', 'linux'];
} else {
platforms = [platformOption];
}
if (!pathOption) {
pathOption = os.homedir();
}
if (!fs.existsSync(pathOption)) {
throw new Error('bad_path');
}
pathOption = path.join(pathOption, 'KolpaqueClientElectron');
// eslint-disable-next-line no-console
console.log(options);
for (const platform of platforms) {
const appPaths: string[] = await packager({
...options,
platform,
out: pathOption,
});
for (const appPath of appPaths) {
const archivePath = await new Promise<string>((resolve) => {
const folderName = path.basename(appPath);
const archivePath = path.join(pathOption, `${folderName}.zip`);
const archiveStream = fs.createWriteStream(archivePath);
const archive = archiver('zip');
archive.directory(appPath, folderName);
archive.finalize();
archiveStream.on('close', () => resolve(archivePath));
archive.pipe(archiveStream);
});
// eslint-disable-next-line no-console
console.log('archiving_done', appPath, archivePath);
}
}
})();