-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.ts
58 lines (49 loc) · 2.05 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
import {existsSync, rmdirSync} from "fs";
import {execSync} from "child_process";
import {ArgumentParser} from "merlins-argument-parser";
const args = new ArgumentParser(process.argv.slice(2));
console.log('Checking backend:')
if (existsSync('node_modules')) {
console.log('"node_modules"-folder exists. Skipping installation.')
} else {
execSync('npm i', {stdio: 'inherit'});
console.log('Backend-dependencies installed.');
}
const buildBackend = args.get('rebuild').asBool() || args.get('rebuild-backend').asBool();
if (existsSync('dist') && existsSync('dist/index.js') && !buildBackend) {
console.log('"dist/index.js" exists. Skipping compilation.');
} else {
if (existsSync('dist')) {
rmdirSync('dist', {recursive: true});
}
execSync('npm run build', {stdio: 'inherit'});
console.log('Backend built to "./dist".');
}
console.log('Checking frontend:');
if (!existsSync('frontend')) {
console.log('Frontend folder missing. Please make sure to clone with "--recursive" flag or create empty frontend folder.')
process.exit(0);
}
if (!existsSync('frontend/package.json')) {
console.log('Frontend package.json missing. Recloning frontend...');
execSync('git clone https://github.com/twasi/twasi-shortener-frontend.git .', {
stdio: 'inherit',
cwd: './frontend'
});
}
if (existsSync('frontend/node_modules')) {
console.log('"node_modules"-folder exists. Skipping installation.');
} else {
execSync('npm i', {stdio: 'inherit', cwd: './frontend'});
console.log('Frontend-dependencies installed.');
}
const buildFrontend = args.get('rebuild').asBool() || args.get('rebuild-frontend').asBool();
if (existsSync('frontend/build') && existsSync('frontend/build/index.html') && !buildFrontend) {
console.log('"frontend/build/index.html" exists. Skipping compilation.')
} else {
if (existsSync('frontend/build')) {
rmdirSync('frontend/build', {recursive: true});
}
execSync('npm run build', {stdio: 'inherit', cwd: './frontend'});
console.log('Frontend built to "./frontend/build".')
}