forked from wll8/sys-shim-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
38 lines (37 loc) · 942 Bytes
/
run.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 sleep = time => new Promise(resolve => setTimeout(resolve, time || 1e3))
const { ProcessManager } = require(`@wll8/process-manager`);
const cp = new ProcessManager({
bin: `cmd.exe`,
arg: [
`/c`,
`cd doc && npm run docs:dev`,
],
});
cp.on(`stdout`, (data = ``) => {
const [, url] = data.match(/Network:\s+(.*)\n/) || []
url && runExe(url)
})
cp.on(`close`, () => {
console.log(`close`);
});
async function runExe(url) {
if(global.runing) {
return undefined
}
global.runing = true
const fs = require(`fs`)
const text = fs.readFileSync(`./package.json`, `utf8`)
const textJson = JSON.parse(text)
textJson.page = url
fs.writeFileSync(`./package.json`, JSON.stringify(textJson, null, 2))
await sleep()
const cp = new ProcessManager({
bin: `main.exe`,
autoReStart: false,
});
cp.on(`close`, () => {
process.exit()
});
await sleep()
fs.writeFileSync(`./package.json`, text)
}