Author libraries in ES6 for Node. By design this does not include browser support. If you also need browser support use the starter that inspired this one.
- Author in ES6 (even the unit tests)
- Export as ES5 & UMD
- Mocha-Chai-Sinon testing stack
- Code Coverage with istanbul
Update the metadata about the project, including the name in the LICENSE
and the package.json
information.
Write your code in src
. The primary file is index.js
(although the filename
can be changed).
Run gulp build
to compile the source into a distributable format.
Put your unit tests in test/unit
. The gulp
command runs the tests.
gulp
- Lint the library and tests, then run the unit testsgulp build
- Lint then build the librarygulp coverage
- Checks your code for quality, style, security and test coverage.
This library is set up to integrate with Code Climate. If you've never used Code Climate, then you might be wondering why it's useful. There are two reasons:
- It consumes code coverage reports, and provides a coverage badge for the README
- It provides interesting stats on your library, if you're into that kinda thing
Either of these items on the list can simply be ignored if you're uninterested in them. Or you can pull Code Climate out entirely from the starter and not worry about it. To do that, update the relevant Gulp tasks and the Travis build.
Follow these steps to set up Code Climate in your new repository.
- Create an account at Code Climate, then login
- Go to
https://codeclimate.com/github/{{ github_user }}/{{ repo_name }}
. Click add. - Next, head to the homepage of
https://codeclimate.com
. Hover over the name of the newly-added repository and click 'Settings' (it appears on hover) - Grab your token from the
Test Coverage
section. The token in the example code that they provide is your token. - Go to
https://travis-ci.org/{{ github_user }}/{{ repo_name }}/settings/env_vars
- Add your token as an environment variable
That's it! Reports are generated from the master branch, so the first report will be generated after your next commit to master.
This starter eslint to lint your source and tests. To change the rules, edit the .eslintrc
and test/.eslintrc
.
An example of how to consume this module as is would be something like the following.
npm install guesstimate-graph-simulator --save
touch consumer.js
Now edit consumer.js to include the following code
var MyLibrary = require('guesstimate-graph-simulator');
console.log(MyLibrary.mainFn());
console.log(MyLibrary.multiply(5,5));
Now run it
node consumer.js
And output should be the following
hello
25
You're authoring a library that exports a single file, and that one file exports a single variable.
You can always use this starter as inspiration, but it works best for smaller libraries. If you're building a full-scale webapp, you will likely need many more changes to the build system.
This starter is, to a certain extent, easily customizable. To make changes, find what you're looking to do below and follow the instructions.
The primary source file for the library is src/index.js
. Only the files that this file imports will be included in the final build. To change the name of this entry file:
- Rename the file
- Update the value of
entryFileName
inpackage.json
underto5BoilerplateOptions
- Update
main
inpackage.json
- Update
main
inpackage.json
MyLibrary
is the name of the variable exported from this starter. You can change this by following these steps:
- Ensure that the variable you're exporting exists in your scripts
- Update the value of
exportVarName
inpackage.json
underto5BoilerplateOptions
- Update the globals array in the
test/.jshintrc
file - Check that the unit tests have been updated to reference the new value
- Ensure that your entry file does not export anything
- Set the property of
exportVarName
inpackage.json
to benull
- Remove the variable name from the globals array in
test/.jshintrc
In the simplest case, you just need to install the module and use it in your scripts. If you want to access the module itself in your unit test files, you will need to set up the test environment to support the module. To do this:
- Load the module in the test setup file. Attach any exported variables to global object if you'll be using them in your tests.
- Update both
.jshintrc
files to include any new global variable that you have added - Add those same global variables to the
mochaGlobals
array inpackage.json
underto5BoilerplateOptions