/cookiecutter-npm

Personal template for Node.js npm packages with Python cookiecutter

Primary LanguageJavaScriptMIT LicenseMIT

cookiecutter-npm

Richard Wen
rrwen.dev@gmail.com

Personal template for Node.js npm packages with Python cookiecutter.

Build Status GitHub license

Install

  1. Install Python
  2. Install cookiecutter via pip
  3. Install Node.js
pip install cookiecutter

Usage

  1. Create a template for a npm package using the cookiecutter command line interface
  2. Change the directory to the folder with the same name as the template_name input
  3. Update and install the developer dependencies using the npm command
cookiecutter gh:rrwen/cookiecutter-npm
cd <template_name>
npm update --dev
npm run docs

See Implementation for more details.

Developer Notes

Create Github Repository

  1. Ensure git is installed
  2. Change directory to the generated folder cd <template_name>
  3. Initialize the repository
  4. Add the generated files to commit
  5. Create an empty Github repository with the same name as template_name
  6. Pull any changes if the Github repository is not empty
  7. Push the commit from 4. to your created Github repository
git init
git add .
git commit -a -m "Initial commit"
git remote add origin https://github.com/<github_user>/<template_name>.git
git pull origin master --allow-unrelated-histories
git push -u origin master

Useful npm Commands

Edit the basic keys in package.json:

npm init

Install all dependencies in package.json:

npm install

Install a package and add it as a dependency with --save:

npm install --save <package-name>

Uninstall a package and dependency:

npm uninstall --save <package-name>

Update all dependencies in package.json:

npm update --dev

Test the package with tape:

npm test

Implementation

This template uses cookiecutter to create folders and files for npm packages in Node.js.

        cookiecutter              <-- template tool
             |
      cookiecutter.json           <-- template inputs
             |
{{cookiecutter.template_name}}    <-- generated template

The following files will be created inside a folder with the same name as the template_name input:

File Description
tests/test.js A file that uses tape to test the index.js module and logs results into tests/log/ for the package version specified in package.json
.gitignore A Node .gitignore automatically generated from github
.npmignore A file to specify ignoring tests/logs/* and docs/*
.travis.yml A .travis.yml file for automatic builds and tests
LICENSE MIT license file automatically created from github
README.md A readme Markdown file with header, install, usage, and developer notes sections
package.json The npm package.json specifications with tape, moment, istanbul, coveralls, and documentation developer dependencies
index.js The main entry file for the npm package with an exported function consuming an options object