This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverDeploy.js
50 lines (48 loc) · 1.52 KB
/
serverDeploy.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
const { spawn } = require("child_process");
const fs = require("fs");
const path = require("path");
async function deployNewServer(config) {
return new Promise((resolve, reject) => {
fs.readFile(path.join(process.env.HOME, config.envVars), (err, data) => {
if (err) {
console.error(err);
return;
}
const parameters = data
.toString()
.split(/\r?\n/)
.filter(p => p);
const params = parameters.reduce(
(result, param) => [...result, "-e", param],
[]
);
if (config.logLevel === "verbose") {
console.log(params);
}
const workingDir = path.join(process.cwd(), config.serverDir);
const child = spawn("now", ["--public", ...params], {
cwd: workingDir
});
child.stdout.on("data", spawnData => {
const serverNameExpression = new RegExp(
`.*${config.serverPrefix}-.*.now.sh$`
);
let dataString = spawnData.toString();
if (dataString.match(serverNameExpression)) {
resolve(dataString);
}
console.log("data =>", spawnData.toString());
});
child.stderr.on("data", childErr => {
const errorMessage = childErr.toString();
console.log("new message =>", errorMessage);
const errorRegex = /.*Error!.*/;
if (errorMessage.match(errorRegex)) {
reject(childErr);
}
});
child.on("close", () => console.log("uploading server has finished."));
});
});
}
module.exports = deployNewServer;