generator-jsmodule

Generator for scaffolding out a JavaScript module for Node.js or the browser

Usage no npm install needed!

<script type="module">
  import generatorJsmodule from 'https://cdn.skypack.dev/generator-jsmodule';
</script>

README

JavaScript module generator

Build Status

A JavaScript module generator for Yeoman.

Installation

Install Node.js (which comes with npm).

Then globally install Bower, Yo, and this generator.

npm install -g bower yo generator-jsmodule

Make a new directory, and cd into it:

mkdir mymodule && cd $_

Now scaffold out a JS module using the yo command (and optionally passing a name for your module):

yo jsmodule <module-name>

All your dependencies will automatically be installed unless you include the --skip-install option.

Generators

Available generators (to be run in the root directory).

  • jsmodule <module-name> (aka jsmodule:app)
  • jsmodule:browser <module-name>

N.B. You should replace the placeholder GitHub username in the Travis CI build-status paths at the top of the generated README.

jsmodule:app

Generates the boilerplate you need for a simple Node.js module.

Example:

yo jsmodule mymodule

Produces:

.
├── node_modules
│   ├── chai
│   └── mocha
├── test
│   └── test.js
├── .gitignore
├── .jshintrc
├── .travis.yml
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── mymodule.js
└── package.json

jsmodule:browser

Generates the boilerplate you need for a simple client-side JavaScript module.

It setups the Karma test runner to run unit tests in the browser. Unit tests rely on the Mocha test framework and the Chai assertion library.

Example:

yo jsmodule:browser mymodule

Produces:

.
├── components
│   └── chai
├── node_modules
│   └── karma
├── test
│   └── test.js
├── .gitignore
├── .jshintrc
├── .travis.yml
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── bower.json
├── karma.conf.js
├── mymodule.js
└── package.json

Running your module's tests

Run npm test to trigger the tests.

The client-side JS module uses a local installation of Karma. If you install Karma globally, then this is an easy way to automatch your tests during development:

karma start

For further information about configuring Karma, please refer to the Karma website.