-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-publish.mjs
103 lines (87 loc) · 2.53 KB
/
build-publish.mjs
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
import { execSync } from 'child_process';
import * as fs from 'fs';
import ncp from 'ncp';
import { tmpdir } from 'os';
import { join } from 'path';
const buildDir = join(tmpdir(), 'netled-build');
console.log(`Build directory: ${buildDir}`);
if (fs.existsSync(buildDir)) {
console.log('Removing existing build folder')
fs.rmSync(buildDir, { recursive: true, force: true });
}
console.log('Creating build folder');
fs.mkdirSync(buildDir);
console.log('Building server')
execSync('npm run --prefix ./server build', { stdio: 'inherit' });
console.log('Building web');
execSync('npm run --prefix ./web build', { stdio: 'inherit' });
//*/
console.log('Copy server to build');
console.log('-- dist');
await new Promise((res, rej) => {
ncp('./server/dist', `${buildDir}/dist`, e => {
if (e) {
rej();
} else {
res();
}
});
});
console.log('-- package.json');
await new Promise((res, rej) => {
ncp('./server/package.json', `${buildDir}/package.json`, e => {
if (e) {
rej();
} else {
res();
}
});
});
console.log('-- package-lock.json');
await new Promise((res, rej) => {
ncp('./server/package-lock.json', `${buildDir}/package-lock.json`, e => {
if (e) {
rej();
} else {
res();
}
});
});
console.log('-- node_module');
await new Promise((res, rej) => {
ncp('./server/node_modules', `${buildDir}/node_modules`, { dereference: true /* Because of core */ }, e => {
if (e) {
console.error('Error copying node_modules', e);
rej();
} else {
res();
}
});
});
//We can't yet enable this because it re-symlinks core and then for some reason, removes all the dependencies
// console.log('Pruning node_modules')
// execSync('npm prune --omit=dev', { cwd: buildDir, stdio: 'inherit' });
console.log('Copy web to build');
await new Promise((res, rej) => {
ncp('./web/dist', `${buildDir}/dist/.web`, e => {
if (e) {
rej();
} else {
res();
}
});
});
console.log('Copy Dockerfile');
await new Promise((res, rej) => {
ncp('./Dockerfile', `${buildDir}/Dockerfile`, e => {
if (e) {
rej();
} else {
res();
}
});
});
console.log('Building docker image');
await execSync('docker build -t joshkrak/netled .', { cwd: buildDir, stdio: 'inherit' });
console.log('Publishing docker image');
await execSync('docker push joshkrak/netled', { stdio: 'inherit' });