-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (28 loc) · 891 Bytes
/
server.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
const fs = require("fs");
const childProcess = require('child_process')
console.log("Starting(server.js)");
//check if there is changes
const gitVer = childProcess.execSync('git rev-parse HEAD').toString();
console.log("gitVer:", gitVer);
let isNewVer = true;
if (fs.existsSync(".gitver")) {
const oldgitVer = fs.readFileSync(".gitver").toString();
if (oldgitVer === gitVer) {
isNewVer = false;
}
}
fs.writeFileSync(".gitver", gitVer);
if (isNewVer) {
try {
console.log("building...");
const result = childProcess.execSync('npm run build');
console.log(result.toString('utf8'));
} catch (e) {
console.log("build(err):", e);
return;
}
}
console.log("starting...");
const program = childProcess.spawn("npm", ["run", "start"], { shell: true });
program.stdout.pipe(process.stdout);
program.stderr.pipe(process.stderr);