npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

module-init

v1.5.0

Published

Create a new node module with all the right stuff.

Downloads

79

Readme

module-init

Create a new node module with all the right stuff.

npm travis standard downloads

Overview

module-init is a command-line tool for generating a new node module.

The following list of files are created based on user input:

  • README.md
    • Automatically generates title, description, and some tasteful badges (version, build status, code style).
    • Auto-populates install, usage, contributing, and license sections with relevant info.
  • LICENSE.md
    • Options: Apache-2.0, BSD-3-Clause, CC0-1.0, ISC, MIT, UNLICENSED.
  • CHANGELOG.md
  • CONTRIBUTING.md
    • Optionally generates contributing guidelines based on CONTRIBUTING.md boilerplate.
  • package.json
  • .travis.yml
    • Covers all major node versions in use: 0.10, 0.12, 4, 5, 6.
  • .gitignore
    • Ignores node_modules directory.
  • index.js
    • A blank module entry point file.
  • test/index.js
    • A boilerplate test file using tape.

Optionally runs git init and npm install in the new module directory.

Install

npm install module-init -g

Usage

CLI

$ module-init --help
Usage: module-init [options]
    --dir, -d             specify module directory (default: cwd)
    --version, -v         show version information
    --force, -f           skip prompt and init with defaults
    --help, -h            show help

Example

~ $ module-init -d new-project
? name: new-project
? version: 1.0.0
? description:
? keywords:
? license: ISC
? private: No
? CONTRIBUTING.md: Yes
? linter: standard
? git init: Yes
? npm install: Yes
Initialized empty Git repository in /Users/yourname/new-project/.git/
✓ .gitignore created
✓ .travis.yml created
✓ CHANGELOG.md created
✓ CONTRIBUTING.md created
✓ LICENSE created
✓ README.md created
✓ package.json created
✓ index.js created
✓ test/index.js created
[email protected] node_modules/tape
...
[email protected] node_modules/tap-spec
...
[email protected] node_modules/standard
...
✓ new-project initialized

Node API

module-init can also be required as a regular node module.

Configuration properties from other sources (.gitconfig, current working directory) will not be automatically used as defaults in this mode. All required properties need to be passed in explicitly.

var moduleInit = require('module-init')

var options = {
  pkgName: 'cool-package',          // required
  pkgVersion: '1.0.0',              // required
  usrName: 'Your Name',             // required
  usrEmail: '[email protected]',       // required
  usrGithub: 'githubUsername'       // required
  pkgDescription: 'description',    // optional
  pkgKeywords: 'one, two, three',   // optional
  pkgContributing: true,            // optional, default: true
  pkgLinter: 'standard',            // optional, default: standard
  pkgLicense: 'ISC',                // optional, default: ISC
  private: true,                    // optional, default: false (omitted if false)
  dir: 'project-directory'          // optional: default: cwd
}

moduleInit(options)
  .on('create', function (filename) {
    console.log(`${filename} created`)
    // file created
  })
  .on('warn', function (message) {
    console.log(`warning: ${message}`)
    // something weird but non-critical happened
  })
  .on('err', function (err) {
    console.error(err)
    process.exit(1)
    // something went horribly wrong! stop everything!
  })
  .on('done', function (result) {
    console.log(result) // object containing module metadata
    // done!
  })
  .run() // run the thing

moduleInit returns an event emitter that emits create, warn, err, and done.

moduleInit.on(string, function) works as demonstrated in the example above.

moduleInit.run() runs the initialization process. It also calls moduleInit.validate() internally before proceeding and will emit an err event if required options are missing. Event listeners need to be set before moduleInit.run() is called.

moduleInit.validate() returns an array of missing required options. It returns an empty array if everything's fine. This method is really just for internal use, but is exposed for testing and convenience.

Take a look at bin/cli.js to see how the API is being used by the CLI.

Contributing

Contributions welcome! Please read the contributing guidelines before getting started.

Collaborators

module-init is only possible due to the excellent work of the following collaborators:

See Also

License

ISC