// 输入 输出 模块
let readline = require('readline');
let { fsWrite } = require('../writeRead')
// 创建 输入输出
let rq = readline.createInterface({
// 指定地方
output: process.stdout,
input: process.stdin
})
let cQuestion = function (title) {
return new Promise((reslove, reject) => {
rq.question(title, (ans) => {
reslove(ans)
})
})
}
let ansQuestion = async function() {
let name = await cQuestion('你的包名?')
let msg = await cQuestion('描述:')
let author = await cQuestion('作者:')
let jsonCont = `
{
"name": "${name}",
"version": "1.0.0",
"description": "${msg}",
"main": "main.js",
"author": "${author}",
"license": "ISC",
"dependencies": {
"jsbarcode": "^3.11.0"
},
"devDependencies": {
"moment": "^2.24.0"
}
}
`
await fsWrite('./package.json', jsonCont)
// 创建完执行关闭
rq.close()
}
ansQuestion()
// 监听关闭做退出终端窗口
rq.on('close', () => {
process.exit(0)
})
生成的文件
{
"name": "jmens",
"version": "1.0.0",
"description": "我的第一个node项目",
"main": "main.js",
"author": "jmens",
"license": "ISC",
"dependencies": {
"jsbarcode": "^3.11.0"
},
"devDependencies": {
"moment": "^2.24.0"
}
}
网友评论