一、準備作業 自定義終端
1.1 第一步:
新建一個檔案夾,命名為:my-cli
1.2 第二步:
在該目錄初始化一個包管理檔案:npm init -y
注意:該檔案的入口檔案(即main配置項)需配置為:"main": "index.js",
1.3 第三步:
然后在該目錄下新建一個 index.js檔案,并輸入以下內容:
#! /usr/bin/env node
console.log('hello cli');
這句代碼的意思是:在當前的電腦環境中查找node,用找到的node來執行當前檔案
1.4第四步
在package.json檔案中,新增bin配置項,具體配置資訊如下:
"bin": {
"xxx": "index.js"
},
上面代碼的意思是指定 xxx 運行的是那個檔案
xxx代表的是以后你運行的全域命令,比如 node --version ,則xxx為node
1.5 第五步:npm link
該命令的作用是,將bin配置項和系統的環境變數做一個鏈接,做一個鏈接之后,會將我們的 xxx 配置到環境變數中,之后輸入 xxx 即可執行我們的index.js 檔案
第六步:測驗,輸入xxx 如果能輸出 hello cli,則代表配置成功,
二、core
三、發布到NPM
3.1 完善我們的package.json
新增 keywords關鍵字配置,
該關鍵字會在npm官網搜索時作為搜索依據,

新增 Homepage 關鍵字配置,
該關鍵字設定的是自己的主頁地址:點擊可以前往自己的主頁,

新增 Repository 關鍵字配置,
該關鍵字設定的是npm包的倉庫地址,

具體配置資訊如下:
{
"name": "super-vue-cli",
"version": "1.2.2",
"description": "This is vue cli tools",
"main": "index.js",
"bin": {
"sucli": "index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"bookbook",
"pengsir",
"vue",
"cli"
],
"author": "bookbook",
"license": "MIT",
"homepage": "https://github.com/penggang-home",
"repository": {
"type": "git",
"url": "https://gitee.com/penggang-home/cli"
},
"dependencies": {
"commander": "^7.2.0",
"download-git-repo": "^3.0.2",
"ejs": "^3.1.6",
"open": "^8.0.5"
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/278132.html
標籤:區塊鏈
上一篇:英語四級考試模擬訓練翻譯真題筆記
下一篇:對稱加密和非對稱加密
