fix(cli): More suitable service detection method (#169)

This commit is contained in:
xw 2022-08-04 10:26:40 +08:00 committed by GitHub
parent f0fd26beb0
commit 19d87ce67b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View File

@ -25,20 +25,18 @@ new Promise(async () => {
}).map(([key, val]) => `${key}=${val}`).join(` `)
const cliArg = [handleSpace(`${__dirname}/node_modules/mockm/run.js`), `--log-line`, line]
spawn(`node`, cliArg)
setTimeout(async () => {
console.log(``)
console.log(`doocs/md-cli v${require(`./package.json`).version}`)
console.log(``)
try {
if(await portIsOk(port) === true) {
throw new Error(`服务 ${port} 初始化失败`)
}
let oldTime = Date.now()
console.log(`服务启动中...`)
console.log(`doocs/md-cli v${require(`./package.json`).version}`)
let timer = setInterval(async () => {
if((await portIsOk(port)) !== true) { // 服务启动成功
clearInterval(timer)
console.log(`服务已启动:`)
console.log(`打开链接 ${colors.green(`http://127.0.0.1:${port}/md/`)} 即刻使用吧~`)
} catch (error) {
console.error(`启动错误 ${error}`)
} else if(Date.now() - oldTime > 10 * 1e3) {
clearInterval(timer)
console.log(`服务 ${port} 初始化失败, 请重试.`)
process.exit()
}
console.log(``)
}, 3*1e3);
}, 1e3);
}).catch(err => console.log(err))

View File

@ -1,6 +1,6 @@
{
"name": "@doocs/md-cli",
"version": "0.0.4",
"version": "0.0.5",
"description": "✍ 一款高度简洁的微信 Markdown 编辑器:支持 Markdown 所有基础语法、色盘取色、一键复制并粘贴到公众号后台、多图上传、一键下载文档、自定义 CSS 样式、一键重置等特性",
"main": "index.js",
"scripts": {