NPM Package Generator
an opinionated npm package template
The Opinionated Parts
I follow the below set of rules in all projects, npm-package-generator
ensures all those rules are followed:
- write in
ES2015
,ES2016
&ES2017
syntax, (supports all plugins inBabel
that are consideredlatest
- outputs
npm
ready packages supporing all LTS versions of Node & Browsers - write tests in
ES2017
and run them usingtap
without needing to compile - generate coverage reports without needing to compile
- runs tests on
travis
targeting all LTS versions of Node - uses
.editorconfig
for maintaining consistent coding styles enforced byechint
- uses
standard
to follow JavaScript Standard Style Guide - ignores
./build
folder fromgit
- use the most permissive open source license (currently
ISC
) - follow a preferred folder tree & npm's default expected file naming (see below)
- always expose your package's compiled library modules (see below)
- keep your package lean, only include useful files (compiled & sources) for developers (see
package.json
>files
) - use a standard template for
README
files. - Testing
Folder Tree
/package-name/
├── build
│ ├── browsers (compiled to last 2 versions of top browsers)
│ │ └── index.js
│ ├── node4 (compiled to Node v4) (default export)
│ │ └── index.js
│ ├── node6 (compiled to Node v6)
│ │ └── index.js
│ └── node7 (compiled to Node v7)
│ └── index.js
├── LICENSE
├── package.json
├── README.md
├── src
│ └── index.js
└── test
├── fixtures
└── index.js
/build
: compiled library files, this is the default exposed output./src
: source library files: all common business logic, use this folder for your code
Work in progress...
This is a work in progress, and will likely be in this state forever!
I will be updating this frequently as common practices change over time, or as I learn new trick.
please reach out to share any feedback & contribution!
Install
npm install --only=production --save npm-package-generator
Usage
$ npm-package-generator new my-awesome-package ~/Projects/my-awesome-package
npm-package-generator new <name> [path] [options]
Options:
--help Show help [boolean]
--author, -a Author Name [required] [default: "Ahmad Nassri"]
--description, -d Package Description
--email, -e Author Email [required] [default: "ahmad@ahmadnassri.com"]
--github, -g Github Username [required] [default: "ahmadnassri"]
--website, -w Author Website
[required] [default: "https://www.ahmadnassri.com/"]
--install, -i Install Dependencies? [required] [default: false]
API
generator(options)
options = path: '~/Projects/my-awesome-package' name: 'my-awesome-package' description: 'my-awesome-package' author: 'Ahmad Nassri' email: 'ahmad@nassri.email' website: 'https://www.ahmadnassri.com/' github: 'ahmadnassri' install: false //-> [array of files created]
options
option | description | default |
---|---|---|
name |
package name | |
path |
installation path | |
author |
author name | process.env.NPM_AUTHOR_NAME |
description |
package description | process.env.NPM_PACKAGE_DESCRIPTION |
author |
author name | process.env.NPM_AUTHOR_NAME |
email |
author email | process.env.NPM_AUTHOR_EMAIL |
website |
author website | process.env.NPM_AUTHOR_WEBSITE |
github |
github account | process.env.NPM_GITHUB_USERNAME |
install |
run npm install and update dependencies |
false |
©️ ahmadnassri.com · License: ISC · Github: @ahmadnassri · Twitter: @ahmadnassri