node实现创建package.json

131 阅读1分钟

node怎么创建package.json

// 输入 输出 模块
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)
})