npm包开发(whale-makelink)

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

猜你喜欢

转载自www.cnblogs.com/jingwhale/p/10699446.html