-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.ts
77 lines (62 loc) · 2.18 KB
/
release.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
/* eslint-disable */
import archiver from 'archiver';
import { map } from 'bluebird';
import fs from 'fs';
import minimist from 'minimist';
import packager, { Options, PlatformOption, TargetArch } from 'electron-packager';
import path from 'path';
interface Args extends minimist.ParsedArgs {
arch?: TargetArch;
platform?: PlatformOption;
shouldZip?: boolean;
}
async function zip(srcPath: string) {
const theZipper = archiver('zip', { zlib: { level: 9 } }); // level 9 uses max compression
const outputZipFilePath = `${srcPath}.zip`;
const output = fs.createWriteStream(outputZipFilePath);
theZipper
.directory(srcPath, false)
.pipe(output)
.on('finish', () => {
console.log(`Finished zipping ${outputZipFilePath}`);
})
.on('error', (err) => {
console.error(`Failed to zip file with source path ${srcPath} -- err: ${err}`);
});
await theZipper.finalize();
}
/* General release command: 'ts-node release.ts'
* For a specific target: 'ts-node release.ts --platform=... --arch=... --shouldZip=...'
*/
async function pack(args: Args) {
const packageOptions: Options = {
dir: __dirname, // source dir
name: 'dawn',
icon: './icons/pieicon',
asar: true,
out: path.resolve('./dawn-packaged') // output to subdirectory
};
Object.keys(args).forEach((key: string) => {
packageOptions[key] = args[key];
});
// platform is either 'darwin', 'linux', or 'win32'
packageOptions.platform = args.platform ?? 'all';
console.log('Packaging for: ', packageOptions.platform);
const appPaths: Array<string | boolean> = await packager(packageOptions);
// Should zip the packages for each platform by default
const shouldZip = args.shouldZip ?? true;
if (!shouldZip) {
return;
}
// If appPath is a boolean, then we assume package for platform already exists, so no need to do anything
const appPathsToZip = appPaths.filter((appPath) => typeof appPath == 'string') as string[];
map(
appPathsToZip,
async (appPath: string) => {
console.log(`Zipping ${appPath}`);
await zip(appPath);
},
{ concurrency: appPaths.length }
);
}
pack(minimist(process.argv.slice(2))).then(() => console.log('Packaging Done'));