init-author-name=Joe Doe
init-author-email=user@example.com
init-author-url=https://github.com/joe
init-license=MIT
save-exact=true
Log in npm
$ npm adduser
$ npm init
name: (lab) lab-starwars-names
version: (1.0.0)
description: Get random Star Wars names
entry point: (index.js) src/index.js
test command:
git repository: (https://github.com/j1wu/lab.git)
keywords: random star wars
license: (MIT)
all the source code at this point can be found at this commit
A quick test
$ node
> var lib = require('./src/index.js');
undefined
> lib.all
travis.yml (the npm run test command will need to be added manually after the yml file generated)
Note that the -w flag will cause travis CI build to fail, add another npm script "test:single": "mocha src/index.test.js" that drops the -w flag, then update travis.yml, replacing npm run test with npm run test-single
Committing a new feature with committizen
Automatically running tests before commits with ghooks
Install ghooks
$ npm i -D ghooks
Update package.json
"config": {
"ghooks": {
"pre-commit": "npm run test:single"
}
}
Adding badges to README with shields.io
Adding ES6 support
all the source code at this point can be found at this commit
Install dependencies
$ npm i -D babel-cli rimraf # cross platform rm
$ npm i -D babel-preset-es2015 babel-preset-stage-2
Update package.json
"main": "dist/index.js",
"files": [ // what to include in the npm package
"dist",
"README.md"
],
"scripts": {
"prebuild": "rimraf dist",
"build": "babel --copy-files --out-dir dist --ignore *.test.js src"
},
"babel": { // configure babel
"presets": ["es2015", "stage-2"]
}
Update .gitignore to ignore dist directory
Adding ES6 support to tests as well
$ npm i -D babel-register # enable mocha ES6 support
Getting started
npm init set
Log in npm
A quick test
Push to Github repo.
Public to npm
Releasing a version to Github
Tag then push
Super Awesome Initial Release
Releasing a new version to npm
git tag 1.1.0
(git tag 1.1.0-beta.0
if it's a beta version)git push
git push --tags
npm publish
(npm publish --tag beta
if it's a beta version)npm info lab-starwars-names
npm i lab-starwars-names@beta
to install the beta versionnpm i lab-starwars-names@1.1.0-beta.0
to install a specific versionSetting up unit testing with Mocha and Chai
Install mocha and chai
Update package.json
Automating releases with semantic-release
Install semantic-release-cli
travis.yml
(thenpm run test
command will need to be added manually after the yml file generated) Note that the-w
flag will cause travis CI build to fail, add another npm script"test:single": "mocha src/index.test.js"
that drops the-w
flag, then updatetravis.yml
, replacingnpm run test
withnpm run test-single
Committing a new feature with committizen
Automatically running tests before commits with ghooks
Install ghooks
Update package.json
Adding badges to README with shields.io
Adding ES6 support
Install dependencies
Update package.json
Update
.gitignore
to ignore dist directory Adding ES6 support to tests as wellAdd a browser build to an npm module
Install webpack and the loaders
Add
webpack.config.babel.js
Update build script
Install the npm-run-all to bundle 3 different builds into a single build
Getting the umd build via npm cdn
Once the package had been published, the umd build can be accessed via npm cdn! umd.js umd.min.js