Creating a command line
- Tools: commander
const program = require('commander'); // Introduce commander program.version (pkg.version) // You can use --version to get the version number program.command (' your command ').description(' description ') .action((... Args) => {// what you want to do});Copy the code
Create a command line menu
- Tools: inquirer
const inquirer = require('inquirer'); Inquirer. Prompt ({type: 'input', type name: 'tittle', // name message: "New tittle", / / hint}). Then ((answers) = > {/ / can then operate});Copy the code
Published to the NPM
- package.json
- Name must be a unique value
- Bin Issues subsequent commands
- Files Files used by the command line
- The main file entry for the main program
- You need to add shebang to the CLI file
- #! /usr/bin/env node
-
Add executable permissions to the project file by pointing to chmod +x xxx.js
-
Use NRM use NPM to switch the NPM source to the original source
-
NPM adduser Logs in to the NPM
-
NPM released the publish