Writing library in javascript

oncode / write-an-open-source-js-lib.md

The purpose of this document is to serve as a reference for:

Watch the series at egghead.io, if you haven’t.

  • Introduction to How to Write an Open Source JavaScript Library
  • Setting up GitHub
  • Configuring npm and creating a package.json
  • Creating the library and adding dependencies
  • Pushing to GitHub
  • Publishing to npm
  • Releasing a version to GitHub
  • Releasing a new version to npm
  • Publishing a beta version
  • Setting up Unit Testing with Mocha and Chai
  • Unit Testing with Mocha and Chai
  • Automating Releases with semantic-release
  • Writing conventional commits with commitizen
  • Committing a new feature with commitizen
  • Automatically Releasing with TravisCI
  • Automatically running tests before commits with ghooks
  • Adding code coverage recording with Istanbul
  • Adding code coverage checking
  • Add code coverage reporting
  • Adding badges to your README
  • Adding ES6 Support
  • Adding ES6 Support to Tests using Mocha and Babel
  • Limit Built Branches on Travis
  • Add a browser build to an npm module

Introduction to How to Write an Open Source JavaScript Library

  • micro libraries
    • pros
      • small enough to reason about the code
      • easy to test as there is less code
      • easy to reuse via npm install
      • managing dependencies as there could be too many
      • create a Git repository
      • host it on GitHub
      • create the library
      • publish it to npm
      • create a full test suite for it using
        • karma
        • mocha
        • chai
        • create a GitHub account, if you don’t have one
        • sign in to your account and create a new repository
        • follow the instructions displayed after creating the repository, to push your code to that repository
        • that’s all! GitHub setup is complete

        Configuring npm and creating a package.json

        • install node if not already installed
        • configure npm locally to make publishing a little easier, for example
          • $ npm set init-author-name «Sarbbottam Bandyopadhyay»
          • $ npm set init-author-url «https://sarbbottam.github.io/»
          • $ npm set init-author-email «sarbbottam@gmail.com»
          • $ npm set init-license «MIT»
          • $ cat ~/.npmrc
          • save-exact property, it tells npm to use the exact version of the packages, rather than a version range, while saving dependency to package.json.
          • it safeguards when semver is not followed properly or there’s a mistake in a release.
          • enter username, password, and email when prompted

          Creating the library and adding dependencies

          • create the main file
          • install required dependencies
            • use -S or —save to save it as dependency at package.json
            • use -D or —save-dev to save it as devDependency at package.json
            • create a .gitignore at the root of the project, to list all the ignored files and directories
            • $ git add to stage the changes
              • alternatively $ git add —all to stage all the changes
              • $ git remote -v will display all the available remote and their corresponding url
              • $ npm add-user , if you have not already
              • add package.json/files to whitelist the set of files to be published
              • you can also add .npmignore file to ignore files/directories, that might fall under from whitelist
              • $ npm version , if you have already published to npm
                • patch for bug fix
                • minor for new feature
                • major for breaking changes

                Releasing a version to GitHub

                • add a version tag to git repository
                  • to associate the version released at npm to the corresponding code
                  • released to npm
                  • GitHub will consider the tag as release and will make it available under releases tab
                  • fill out the release form with the tag version

                  Releasing a new version to npm

Оцените статью