一、准备工作
mkdir ge-cli
cd ge-cli
npm init -y
code .
二、新建bin目录并在其中新建index.js文件,添加以下信息
#!/usr/bin/env node
console.log("hello ge,welcome your first cli manage!!!");
三、在package.json文件中添加以下信息
{
"name": "ge-cli",
"version": "1.0.0",
"description": "",
"bin": {
"ge-cli": "bin/index.js"
},
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "jesse.kong",
"license": "ISC"
}
最终目录
四、npm发布
npm publish
# 有问题,按照下面步骤解决
npm whoami
# npm config set registry https://registry.npmjs.org/
npm login
# ...
npm publish
npm install ge-cli -g
ge-cli
which ge-cli