npm包開發(whale-makelink)
阿新 • • 發佈:2019-04-13
改變 error: 工具 ima 登錄 targe get type con
whale-makelink是一個npm工具,是強業務的工具,可以將當前工程目錄下的工程文件夾,在README中生成工程的鏈接地址。Demo。
一、npm init
使用npm init生成package.json
{ "name": "whale-makelink", "version": "1.0.3", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" },"keywords": [], "author": "[email protected]", "license": "ISC" }
二、自定義命令
2.1、在package.json的bin下定義一個對象,這裏makelink就是需要的命令,內容交給index.js
{ "name": "whale-makelink", "version": "1.0.3", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" },"bin": { "makelink": "./index.js" }, "keywords": [], "author": "[email protected]", "license": "ISC" }
2.2、在index.js中添加‘#!/usr/bin/env node‘
#!/usr/bin/env node const path = require(‘path‘); const makelink = require(‘./makelink‘); const pathName = path.resolve(__dirname, ‘../..‘); const srcFile= pathName + ‘/README.md‘; makelink(srcFile,pathName);
三、發布npm包
3.1、註冊
npm官網註冊,並且通過郵件驗證後,才能發npm包。
3.2、登錄
npm login
輸入用戶名、密碼和郵箱。
3.3、發布
npm publish
3.4、版本更新
1)、變更版本號-自動改變版本
npm version <update_type>
update_type為patch, minor, or major其中之一,分別表示補丁,小改,大改
若是patch,變為1.0.1 若是minor,變為1.1.0 若是major,變為2.0.0
2)、發布
npm publish
3.5、發布出錯
1)、驗證郵箱
2)、修正npm源
npm config get registry npm config set registry=http://registry.npmjs.org
四、項目地址
五、npm whale-makelink
npm包開發(whale-makelink)