zoukankan      html  css  js  c++  java
  • [Javascript] How to write a Javascript libarary

    Create package.json file

    //npm settings
    npm set init-author-name 'username'
    npm set init-author-email 'username@gmail.com'
    npm set init-author-url 'http://username.com'
    npm set save-exact true
    
    //create package.json
    npm init

    Pubish to github and tag it

    git status
    git add -A
    git commit -m "commit message"
    git push
    git tag 1.0.0
    git push --tags

    Publish to npm

    npm publish
    npm info <project_name>

    Release a new version

    1. according to the changes to change the version in package.json
    2. publish to git
    3. publish tag to git
    4. npm publish
    5. npm info

    Publishing a beta version

    1. In package.json: "version": "1.2.0-beta.0",
    2. publish to git
    3. tag it in git
    4. npm publish --tag beta
    5. npm info
    
    //install
    npm install starwars-ns@beta
    npm install starwars-ns@1.2.0-beta.0

    Mocha, chai testing:

    var expect = require('chai').expect;
    var starWars = require('./index');
    
    describe('starwars-names', function() {
        describe('all', function(){
            //check return type
            it('should be an array of strings', function(){
                expect(starWars.all).to.satisfy(isArrayOfString);
                
                function isArrayOfString(array){
                    return array.every(function(item){
                        return typeof item === 'string';
                    });
                }
            });
            
            //ccheck one of the value
            it('should includ Asajj Ventress', function(){
                expect(starWars.all).to.include('Asajj Ventress');
            });
        });
        
        describe('random', function(){
            it('should return one of the starwar names form all', function(){
                expect(starWars.all).to.include(starWars.random());
            })
        });
    });

    semantic-release:

    npm install -g semantic-release-cli //Install
    
    //RUN
    semantic-release-cli setup

    Writing conventional commits with commitizen:

    npm install -D cz-conventional-changelog
    npm install -D commitizen

    Add script:

    "commit": "git-cz"

    Add Config: 

      "czConfig": {
          "path": "node_modules/cz-conventional-changelog"
      },

    Add Badges:

    ![Downloads](https://img.shields.io/npm/dm/angular-md-table.svg)
    ![npm](https://img.shields.io/npm/v/angular-md-table.svg)
    ![node](https://img.shields.io/node/v/angular-md-table.svg)

    http://shields.io/

  • 相关阅读:
    【转载】Allegro Auto Rename器件反标注教程
    FPGA代码设计规范整理
    Cadence Allegro导网表的错误问题解决
    简单玩转Excel排序、筛选、分类汇总与数据透视表功能!
    zt一篇教会你写90%的shell脚本
    zt一篇教会你写90%的shell脚本
    TCP协议理解
    zt 改进TCP,阿里提出高速云网络拥塞控制协议HPCC
    zt TCP的困境与解决方案
    ztGoogle's BBR拥塞控制算法如何对抗丢包
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4756412.html
Copyright © 2011-2022 走看看