How to Write an Open Source JavaScript Library
Jalal Azimi
@TehranJs
-
NPM
-
Git
-
Test
-
Release
Create & Setting up Github
Create Repository

Clone your Repository
Config NPM
install Nodejs

NPM Docs

Create Per-user config file (~/.npmrc)

Create NPMJS.com Account
when your account was created


NPM INIT

Creating the library and adding Dependencies
npm install lodash --saveManage Dependencies
install your Project dependencies
"dependencies": {
"lodash": "^4.16.4"
}package.json
Manage Dependencies
enable save-exact
"dependencies": {
"lodash": "4.16.4"
}npm set save-exact trueor
Publish to NPM


npm install tehranjsReleasing to Git
Tagging
Git has the ability to tag specific points in history as being important
$ git tag 1.0.0
$ git push --tagsnpm-version
If supplied with -m or --message config option, npm will use it as a commit message when creating a version commit
$ npm version [<newversion> | major | minor | patch]$ npm version patch -m "Upgrade to %s for reasons"Finally
$ git push origin master --tagsSee your tags in Github

Draft a new Release

Publish release

Releasing new Version to NPM

Setting up Testing
Install mocha & chai
$ npm install mocha chai --save-devafter write your test file run:
$ mocha index.test.js -w"scripts": {
"test": "mocha index.test.js -w"
}or edit test script in your package.json
$ npm testAutomatic Releasing
Semantic release CLI
$ npm i -g semantic-release-clisetup automated semver compliant package publishing
Setup Semantic release CLI

Write conventional commits
Commitizen
$ pm install -g commitizen
Code Coverage
Istanbul
$ npm install -g istanbulYet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests.
Adding Badges
shields.io


Thank You!
How to Write an Open Source JavaScript Library
By Jalal Azimi
How to Write an Open Source JavaScript Library
- 125