-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployLocal.js
More file actions
76 lines (61 loc) · 1.72 KB
/
deployLocal.js
File metadata and controls
76 lines (61 loc) · 1.72 KB
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
import http from 'http';
import { promises as fs } from 'fs';
import servatron from 'servatron/http.js';
import chokidar from 'chokidar';
import debounce from 'debounce';
import { spawn } from 'child_process';
function exec (command, cwd) {
return new Promise((resolve, reject) => {
const [cmd, ...args] = command.split(' ');
const childProcess = spawn(cmd, args, { cwd, stdio: 'inherit' });
childProcess.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Command "${command}" exited with code ${code}`));
}
});
childProcess.on('error', (error) => {
reject(error);
});
});
}
async function copyFiles(srcDestPairs) {
for (const [src, dest] of srcDestPairs) {
await fs.cp(src, dest, { errorOnExist: false, force: true, recursive: true });
}
}
async function build(entrypoint, destination = '') {
await exec('npm run build', entrypoint);;
await copyFiles([[`${entrypoint}/dist`, `dist/${destination}`]]);
}
async function buildAll () {
console.log('building...');
await build(
'packages/deriv-browser-client'
);
build(
'packages/dashboard',
);
build(
'packages/example1',
'example1',
);
build(
'packages/example2',
'example2',
);
}
await fs.rm('dist', { recursive: true, force: true });
if (process.argv[2] === '--watch' || process.argv[2] === '-w') {
chokidar.watch(`packages/*/src/**/*`, { ignoreInitial: false }).on('all', debounce(buildAll, 100));
const staticHandler = servatron({
directory: './dist',
spa: true,
spaIndex: 'index.html'
});
http.createServer(staticHandler).listen(8000);
console.log('Listening on', 'http://localhost:8000');
} else {
buildAll();
}