Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade md-cli #257

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions md-cli/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node

const { ProcessManager } = require(`@wll8/process-manager`);
const getPort = require(`get-port`)
const {
portIsOk,
handleSpace,
colors,
spawn,
parseArgv,
} = require(`./util.js`)

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