forked from stimulant/ampm
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart.cjs
More file actions
57 lines (48 loc) · 1.36 KB
/
start.cjs
File metadata and controls
57 lines (48 loc) · 1.36 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
#! /usr/bin/env node
// Run ampm under nodemon. It watches changes to ampm-restart.json so that ampm
// can restart itself. It also restarts on crash.
// Really should be using nodemon as a module, but:
// https://github.com/stimulant/ampm/issues/12
const path = require("path");
const child_process = require("child_process");
const fs = require("fs");
var configFiles = process.argv[2] || "ampm.json";
var configFile = path.resolve(configFiles.split(",")[0]);
var appPath = path.dirname(configFile);
var restartFile = path.join(appPath, "ampm-restart.json");
var stateFile = path.join(appPath, "ampm-state.json");
var mode = process.argv[3] || "default";
var server = path.join(__dirname, "server.cjs");
if (!fs.existsSync(restartFile)) {
fs.writeFileSync(restartFile, "");
}
if (!fs.existsSync(stateFile)) {
fs.writeFileSync(stateFile, "{}");
}
var args = [
"--verbose",
"--exitcrash",
"--watch",
configFile,
"--watch",
restartFile,
"--ignore",
"logs",
"--ignore",
stateFile,
server,
configFiles,
mode,
];
// If there are arguments beyond the config file and mode, pass them to nodemon.
process.argv.slice(4).forEach(function (a, i) {
args.splice(args.length - 3, 0, a);
});
function start() {
var ampm = child_process.spawn("nodemon", args, {
stdio: "inherit",
shell: process.platform === "win32",
});
ampm.on("close", start);
}
start();