-
Notifications
You must be signed in to change notification settings - Fork 0
/
appbuild.js
67 lines (51 loc) · 1.49 KB
/
appbuild.js
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
import { spawn } from 'node:child_process';
import { readdir, mkdir, copyFile } from 'node:fs/promises';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const copyDir = async (src, dest) => {
await mkdir(dest, { recursive: true });
const entries = await readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
entry.isDirectory()
? await copyDir(srcPath, destPath)
: await copyFile(srcPath, destPath);
}
};
const run = ({ command, args, options, name }) => {
return new Promise((resolve, reject) => {
const taskProcess = spawn(command, args, options);
taskProcess.stdout.on('data', (data) => {
console.log(`${name}: ${data}`);
});
taskProcess.on('close', resolve);
taskProcess.on('error', reject);
});
};
const build = async () => {
const command = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const tasks = [
{
command,
args: ['run', 'build:client'],
name: 'client',
},
{
command,
args: ['run', 'build:server'],
name: 'server',
},
];
await Promise.all(tasks.map(run));
await copyDir(
join(__dirname, 'apps/server/dist'),
join(__dirname, 'appbuild')
);
await copyDir(
join(__dirname, 'apps/client/dist'),
join(__dirname, 'appbuild/static')
);
};
build().catch(console.error);