码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] How to write a Javascript libarary

时间:2016-03-06 19:23:10      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

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());
        })
    });
});

 

[Javascript] How to write a Javascript libarary

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4756412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!