Coder Social home page Coder Social logo

module-init's Introduction

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 Node.js 4 and 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:

bcomnesGitHub/bcomnes
FletGitHub/Flet
paulcpedersonGitHub/paulcpederson
ungoldmanGitHub/ungoldman

See Also

License

ISC

module-init's People

Contributors

bcomnes avatar flet avatar jamescostian avatar paulcpederson avatar scottcorgan avatar ungoldman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

module-init's Issues

make npm install step optional

I'd like to stop the npm install step from being automatic and prompt for it instead as it often takes a long time just to install tape, tap-spec, and standard, and I'd rather run npm install myself afterwards sometimes.

Example workflow:

? name: derp
? version: 1.0.0
? description:
? keywords:
? license: ISC
? contributing: Yes
? linter: standard
Initialized empty Git repository in /Users/ng/dev/github/module-init/derp/.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
? npm install: (Y/n) n
✓ derp initialized

This would speed things up quite a bit for me, especially when working on low bandwidth connections.

Want to run it by the regular contributors/maintainers (@Flet @bcomnes @paulcpederson) before I do it in case this is a blocker for anyone

initiate a module that uses ES2015 with transpilation

Is there any interest in adding another option to module-init to initialize a module structured to be written in ES2015 and using transpilation by babel?

This little boilerplate seems to cover the standard practices for transpiled packages: https://github.com/vinniegarcia/es6-module-starter - it includes a lot of extra non-ES2015 stuff that is not pertinent, but you get the idea.

The biggest structural change is all code being in /src and being transpiled to /dist, with the package.json pointing to dist/index.js for the "main" attribute.

The the directory layout may be different enough to warrant a totally separate CLI package (module-init-next??), but it could also be achieved here with enough work (separate templates directory?).

I guess it depends on @ngoldman's vision for this module. Any thoughts?

should be more modular

This whole project could be broken down quite a bit. I want to to use init-module for package.json setup, as that hooks into npm init and works much better and more simply than the method used in here, then create other files based on info in there -- each file could have its own generator module (package-json-to-readme or something). I bet there are already a lot of those out there.

Error when selecting 'No' for contributing

When prompted:

? contributing: (Y/n)

If I enter y everything works great, but if I use n I get the following error:

[Error: missing required options: pkgContributing]

Include example test in test/index.js

It would be nice to include a simple test in test/index.js instead of being blank.

Maybe as simple as:

var test = require('tape')

test('Example Test', function (t) {
  t.plan(1)
  t.error('No tests defined.')
})

I realize this is complicated by the fact that a module could be standard or semistandard too... :(

Move github.user check to the top

It would be nice to fail quickly if github user does not exist in git config by checking before asking questions. This ensures a user does not need to fill out everything again if they don't have it.

soliciting feedback on some implementation details

@paulcpederson @nikolaswise since you've both expressed interest in using this module when it's stabilized, I thought I'd ask your opinion on some implementation details.

Everything on the table of steps in the readme has been implemented except for the following three:

  • create repo on github
  • travis hook added w/ travisjs
  • npm publish

I'm wondering if these are beyond the scope of the repo or not. I think the second and third hinge on the first.

  • Should module-init create a repo for you? If so:
    • Should it add the Travis-CI hook for you?
    • Should it run npm publish for you?

If it makes sense for module-init to create the repo, all that requires is getting a token from github, which is fairly trivial with ghauth. You'd only need to authenticate with user & pass through a prompt once, then the token would be stored for future inits. That token could also be used for adding the Travis-CI hook with travisjs (I think).

My thought is that it would be nice if it created the repo and did the hook, but publishing a non-functioning module is too much -- that's pretty much just name squatting.

If it makes sense to create the repo, should that be done automatically or should it be a (y/n) prompt? Same question for travis hook & npm publish.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.