forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
74 lines (66 loc) · 1.71 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
// must be imported first to set env variables
import './scripts/set-env';
import { build } from 'vite';
import * as configs from './vite.configs';
import { mkdir } from 'fs/promises';
import { getBrowser, isDev, releaseTarget, releaseType } from './scripts/util';
import colorLog from 'scripts/log';
import { exec } from 'child_process';
import { emptydirSync } from 'fs-extra';
import createDistributable from 'scripts/create-distributable';
/**
* Try to make a directory, dont error if the directory exists
*
* @param str - path to directory to try to make
*/
async function trymkdir(str: string) {
try {
await mkdir(str);
} catch (err) {
if (
!err ||
typeof err !== 'object' ||
!('code' in err) ||
err.code !== 'EEXIST'
) {
throw new Error('Something went wrong making build folder');
}
}
}
async function main() {
await trymkdir('build');
const folder = `build/${getBrowser()}`;
await trymkdir(folder);
emptydirSync(folder);
const scripts = [
build(configs.buildStart),
build(configs.buildBackground),
build(configs.buildContent),
];
await Promise.all(scripts);
if (isDev() && releaseTarget === 'safari') {
await new Promise((resolve) => {
setTimeout(resolve, 10000);
});
}
if (releaseTarget === 'safari' && !isDev()) {
colorLog('Compiling safari extension', 'info');
await new Promise<void>((resolve, reject) => {
exec('bash safari.sh', (err, stdout, stderr) => {
if (err) {
colorLog(err, 'error');
colorLog(stdout, 'info');
colorLog(stderr, 'error');
reject();
return;
}
colorLog('Successfully compiled safari extension', 'success');
resolve();
});
});
}
if (releaseType === 'dist') {
await createDistributable();
}
}
main();