天天看點

npm包開發(whale-makelink)

whale-makelink是一個npm工具,是強業務的工具,可以将目前工程目錄下的項目檔案夾,在README中生成項目的連結位址。Demo。

一、npm init

使用npm init生成package.json

{
  "name": "whale-makelink",
  "version": "1.0.5",
  "description": "Make-link can get all the project folders of the current directory, and generate the project link directory in the readme.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:jingwhale/whale-makelink.git"
  },
  "keywords": [
    "makelink"
  ],
  "author": "[email protected]",
  "license": "ISC"
}      

二、自定義指令

2.1、在package.json的bin下定義一個對象,這裡makelink就是需要的指令,内容交給index.js

{
  "name": "whale-makelink",
  "version": "1.0.5",
  "description": "Make-link can get all the project folders of the current directory, and generate the project link directory in the readme.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:jingwhale/whale-makelink.git"
  },
  "bin": {
    "makelink": "./index.js"
  },
  "keywords": [
    "makelink"
  ],
  "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      

四、更新package.json

更新package.json後,需要先送出到github,再進行版本的更新。

五、版本展示

建立

npm包開發(whale-makelink)

readme中使用

![verion](https://img.shields.io/badge/npm-1.0.8-brightgreen.svg)      

政策

每次代碼更新完畢,在進行版本的更新操作。

六、npm whale-makelink

npm包開發(whale-makelink)
npm包開發(whale-makelink)