Skip to content

Commit 5dec24f

Browse files
authored
chore: upgrade md-cli to v0.0.6 (#257)
* fix: Update the command line parameter passing method * chore: Upgrade mockm * chore: Only use mockm with md-cli * chore: Update the version number of md-cli * feat: Optimize process management * fix: Optimize space paths
1 parent 0af8054 commit 5dec24f

12 files changed

+10256
-18950
lines changed

md-cli/index.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env node
22

3+
const { ProcessManager } = require(`@wll8/process-manager`);
34
const getPort = require(`get-port`)
45
const {
5-
portIsOk,
66
handleSpace,
77
colors,
8-
spawn,
98
parseArgv,
109
} = require(`./util.js`)
1110

@@ -22,21 +21,18 @@ new Promise(async () => {
2221
testPort,
2322
replayPort,
2423
'--config': handleSpace(`${__dirname}/mm.config.js`),
25-
}).map(([key, val]) => `${key}=${val}`).join(` `)
26-
const cliArg = [handleSpace(`${__dirname}/node_modules/mockm/run.js`), `--log-line`, line]
27-
spawn(`node`, cliArg)
28-
let oldTime = Date.now()
29-
console.log(`服务启动中...`)
24+
}).map(([key, val]) => `${key}=${val}`)
25+
const cliArg = [handleSpace(`${__dirname}/node_modules/mockm/run.js`), `--log-line`, ...line]
3026
console.log(`doocs/md-cli v${require(`./package.json`).version}`)
31-
let timer = setInterval(async () => {
32-
if((await portIsOk(port)) !== true) { // 服务启动成功
33-
clearInterval(timer)
27+
console.log(`服务启动中...`)
28+
const cp = new ProcessManager(cliArg)
29+
cp.on(`stdout`, (info = ``) => {
30+
if(info.match(`:${port}/`)) {
3431
console.log(`服务已启动:`)
3532
console.log(`打开链接 ${colors.green(`http://127.0.0.1:${port}/md/`)} 即刻使用吧~`)
36-
} else if(Date.now() - oldTime > 10 * 1e3) {
37-
clearInterval(timer)
38-
console.log(`服务 ${port} 初始化失败, 请重试.`)
33+
}
34+
if(info.match(`Port is occupied`)) {
3935
process.exit()
4036
}
41-
}, 1e3);
37+
})
4238
}).catch(err => console.log(err))

0 commit comments

Comments
 (0)