快速入门第一个简易脚手架(三)

58 阅读1分钟

一、准备工作

mkdir ge-cli
cd ge-cli
npm init -y
code .

二、新建bin目录并在其中新建index.js文件,添加以下信息

#!/usr/bin/env nodeconsole.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"
}

最终目录

image-20230831000340149.png

四、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