.
├── index.js
└── package.json
第一步:初始化
yarn init -y
第二步:按需安装包
前两步执行完后的package.json
{
"name": "cli-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "",
"dependencies": {
"chalk": "^5.0.1",
"clear": "^0.1.0",
"commander": "^9.4.0",
"download-git-repo": "^3.0.2",
"figlet": "^1.5.2",
"inquirer": "^9.1.0",
"log-symbols": "^5.1.0",
"ora": "^6.1.2"
}
}
第三步:新建index.js
#!/usr/bin/env node
import chalk from 'chalk';
import figlet from 'figlet';
import clear from 'clear';
clear();
console.log(chalk.yellow(figlet.textSync('CLI', { horizontalLayout: 'full' })));
第四步:在package.json添加入口, 名字”CLI“可自定义
{
"bin": {
"CLI": "index.js"
}
}
第五步:执行yarn link
yarn link
成功状态:

第六步:执行CLI

说明cli就创建成功了~