Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.
/ init-module Public archive

🍬 Add some sugar to the npm init command.

License

Notifications You must be signed in to change notification settings

ungoldman/init-module

Repository files navigation

NO LONGER MAINTAINED

This is a public archive. Use at your own risk.

🖖


init-module

Add some sugar to the npm init command.

npm travis style downloads

npm init allows you to configure a few things and works from a few defaults. init-module is meant to take it a bit further, making all package.json properties editable, adding more defaults to npm config that will autopopulate when you run npm init -y, and allowing you to use npm init as a package.json editor.

Install

npm i -g init-module

Usage

npm allows you to configure an init module that will be loaded by the npm init command to override the default prompts. The init-module program is intended to be used in this manner.

npm set init-module $(init-module --path)

Once you've set the above config property, init-module will simply extend the default npm init command.

npm init

Configuration (npm init)

These defaults are already available to npm init without init-module.

Author Name: init-author-name

  • Default: ""
  • Type: String

The value npm init should use by default for the package author's name.

npm set init-author-name="Your Name"

Author Email: init-author-email

  • Default: ""
  • Type: String

The value npm init should use by default for the package author's email.

npm set init-author-email="[email protected]"

Author URL: init-author-url

  • Default: ""
  • Type: String

The value npm init should use by default for the package author's homepage.

npm set init-author-url="http://yoursite.com"

License init-license

  • Default: "ISC"
  • Type: String

The value npm init should use by default for the package license.

npm set init-license="BSD-2-Clause"

The license name must be a valid SPDX license expression. See https://spdx.org/licenses for more info.

Version init-version

  • Default: "1.0.0"
  • Type: semver

The value that npm init should use by default for the package version number, if not already set in package.json.

npm set init-version="1.0.0"

Configuration (init-module)

These defaults require init-module in order to be available in npm init.

Start Script: init-scripts-start

  • Default: null
  • Type: String

The command to use when running npm start.

npm set init-scripts-start="node ."

Test Script: init-scripts-test

  • Default: 'echo "Error: no test specified" && exit 1'
  • Type: String

The command to use when running npm test.

npm set init-scripts-test="standard"

Example

Here's an example of the init-* contents of my global .npmrc file.

init-author-email = "[email protected]"
init-author-name = "Nate Goldman"
init-author-url = "http://ungoldman.com/"
init-license = "ISC"
init-module = "/Users/ng/dev/github/init-module/init-module.js"
init-scripts-start = "node ."
init-scripts-test = "standard"
init-version = "1.0.0"

All configuration above can be set with npm set, which is just a shortcut for npm config set. You can also edit your .npmrc manually if you prefer (npm config edit will open your global .npmrc file with your default editor).

Running npm init in an empty directory with the above configuration, I get the following:

~/my-module $ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (my-module)
version: (1.0.0-alpha)
description: A fine module indeed.
entry point: (index.js)
test command: (standard)
start command: (node .)
git repository: https://github.com./ungoldman/my-module.git
keywords: my, module
author name: (Nate Goldman)
author email: ([email protected])
author url: (http://ungoldman.com)
license: (ISC)
private: (false) true
About to write to /Users/ng/dev/github/init-module/my-module/package.json:

{
  "name": "my-module",
  "version": "1.0.0-alpha",
  "description": "A fine module indeed.",
  "main": "index.js",
  "scripts": {
    "start": "node .",
    "test": "standard"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com./ungoldman/my-module.git"
  },
  "keywords": [
    "my",
    "module"
  ],
  "author": "Nate Goldman <[email protected]> (http://ungoldman.com)",
  "license": "ISC",
  "private": true,
  "bugs": {
    "url": "https://github.com./ungoldman/my-module/issues"
  },
  "homepage": "https://github.com./ungoldman/my-module#readme"
}


Is this ok? (yes)

Note that with init-module, running npm init again will allow you to edit all of the above properties, unlike the stock npm init behavior.

name: (my-module)
version: (1.0.0-alpha)
description: (A fine module indeed.)
entry point: (index.js)
test command: (standard && tape test/*.js | tap-spec)
git repository: (git+https://github.com./ungoldman/my-module.git)
keywords: (my, module)
author name: (Nate Goldman)
author email: ([email protected])
author url: (http://ungoldman.com)
license: (ISC)
private: (true)

The "yes" option (force)

Running npm init -y in an empty directory with the example configuration above yields the following package.json:

{
  "name": "my-module",
  "version": "1.0.0-alpha",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "standard && tape test/*.js | tap-spec"
  },
  "author": "Nate Goldman <[email protected]> (http://ungoldman.com)",
  "license": "ISC"
}

Contributing

Contributions welcome! Please read the contributing guidelines first.

See also

License

ISC

About

🍬 Add some sugar to the npm init command.

Resources

License

Stars

Watchers

Forks

Packages

No packages published