自制 Web Framework 脚手架


文章目录

  • 外部依赖包
    • commander - 命令行参数解析
    • chalk - 文字颜色修改
    • log-symbols - 命令行图标
    • inquirer 命令行交互
    • download-git-repo - Git下载
    • ora 下载loading

外部依赖包

commander - 命令行参数解析

返回目录

chalk - 文字颜色修改

返回目录

log-symbols - 命令行图标

返回目录

inquirer 命令行交互

返回目录

  1. 安装
    npm i -S inquirer
    
  2. 使用
    var inquirer = require('inquirer');
    inquirer
      .prompt([
        /* Pass your questions in here */
      ])
      .then(answers => {
        // Use user feedback for... whatever!!
      })
      .catch(error => {
        if(error.isTtyError) {
          // Prompt couldn't be rendered in the current environment
        } else {
          // Something else when wrong
        }
      });
    

type: (String) Type of the prompt. Defaults: input - Possible values: input, number, confirm, list, rawlist, expand, checkbox, password, editor
name: (String) The name to use when storing the answer in the answers hash. If the name contains periods, it will define a path in the answers hash.
message: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers. Defaults to the value of name (followed by a colon).
default: (String|Number|Boolean|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
choices: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers. Array values can be simple numbers, strings, or objects containing a name (to display in list), a value (to save in the answers hash), and a short (to display after selection) properties. The choices array can also contain a Separator.
validate: (Function) Receive the user input and answers hash. Should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
filter: (Function) Receive the user input and answers hash. Returns the filtered value to be used inside the program. The value returned will be added to the Answers hash.
transformer: (Function) Receive the user input, answers hash and option flags, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
when: (Function, Boolean) Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
pageSize: (Number) Change the number of lines that will be rendered when using list, rawList, expand or checkbox.
prefix: (String) Change the default prefix message.
suffix: (String) Change the default suffix message.
askAnswered: (Boolean) Force to prompt the question if the answer already exists.
loop: (Boolean) Enable list looping. Defaults: true

download-git-repo - Git下载

返回目录

ora 下载loading

你可能感兴趣的:(Node.js,node.js)