forked from weaigc/bingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-check.js
38 lines (32 loc) · 832 Bytes
/
pre-check.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
const { existsSync } = require('fs');
const { spawn } = require('child_process');
function executeCommand(command) {
return new Promise((resolve, reject) => {
const child = spawn(command, { shell: true });
child.stdout.on('data', (data) => {
console.log(data.toString());
});
child.stderr.on('data', (data) => {
console.error(data.toString());
});
child.on('exit', (code) => {
console.log(`Child process exited with code ${code}`);
resolve();
});
child.on('error', (err) => {
console.error(err);
reject(err);
});
});
}
async function start() {
let exists = false;
try {
exists = existsSync('.next/BUILD_ID');
} catch (e) {}
if (!exists) {
await executeCommand('npm install');
await executeCommand('npm run build');
}
}
start();