How to Write an Open Source JavaScript Library

Jalal Azimi

@TehranJs
  1. NPM

  2. Git

  3. Test

  4. 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 --save

Manage 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 true

or

Publish to NPM

npm install tehranjs

Releasing to Git

Tagging

Git has the ability to tag specific points in history as being important

$ git tag 1.0.0
$ git push --tags

npm-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 --tags

See 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-dev

after 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 test

Automatic Releasing

Semantic release CLI

$ npm i -g semantic-release-cli

setup automated semver compliant package publishing

Setup Semantic release CLI

Write conventional commits

Commitizen

$ pm install -g commitizen

Code Coverage

Istanbul

$ npm install -g istanbul

Yet 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