├── .eslintrc ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── bin └── cli.js ├── index.js ├── init-module.js ├── package.json └── test └── index.js /.eslintrc: -------------------------------------------------------------------------------- 1 | "extends": "unstyled" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'stable' 4 | - '0.12' 5 | - '0.10' 6 | sudo: false 7 | cache: 8 | directories: 9 | - node_modules 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # init-module change log 2 | 3 | All notable changes to this project will be documented in this file. 4 | This project adheres to [Semantic Versioning](http://semver.org/). 5 | 6 | ## 1.0.0 7 | 8 | ### Features 9 | 10 | - add `init-scripts-start` 11 | 12 | ## 1.0.0-beta 13 | 14 | - update URLs 15 | - it's a beta 16 | 17 | ## 1.0.0-alpha.3 18 | 19 | - add `init-scripts-test` 20 | - fix keyword default behavior 21 | - fix private default behavior 22 | - fix repository editing behavior 23 | 24 | ## 1.0.0-alpha.2 25 | 26 | - fix private 27 | - add truthiness detector 28 | - add cli path option test 29 | - fix author 30 | - improve docs 31 | - fix keywords 32 | - add default private prompt 33 | - remove npm config dot notation 34 | 35 | ## 1.0.0-alpha.1 36 | 37 | - fix some readme links 38 | 39 | ## 1.0.0-alpha 40 | 41 | - engage 42 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Contributions welcome! 4 | 5 | **Before spending lots of time on something, ask for feedback on your idea first!** 6 | 7 | Please search issues and pull requests before adding something new to avoid duplicating efforts and conversations. 8 | 9 | In addition to improving the project by refactoring code and implementing relevant features, this project welcomes the following types of contributions: 10 | 11 | - **Ideas**: participate in an issue thread or start your own to have your voice heard. 12 | - **Writing**: contribute your expertise in an area by helping expand the included content. 13 | - **Copy editing**: fix typos, clarify language, and generally improve the quality of the content. 14 | - **Formatting**: help keep content easy to read with consistent formatting. 15 | 16 | ## Installing 17 | 18 | Fork and clone the repo, then `npm install` to install all dependencies. 19 | 20 | ## Testing 21 | 22 | Tests are run with `npm test`. Unless you're creating a failing test to increase test coverage or show a problem, please make sure all tests are passing before submitting a pull request. 23 | 24 | ## Code Style 25 | 26 | [![standard][standard-image]][standard-url] 27 | 28 | This repository uses [`standard`][standard-url] to maintain code style and consistency and avoid style arguments. `npm test` runs `standard` so you don't have to! 29 | 30 | [standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg 31 | [standard-url]: https://github.com/feross/standard 32 | [semistandard-image]: https://cdn.rawgit.com/flet/semistandard/master/badge.svg 33 | [semistandard-url]: https://github.com/Flet/semistandard 34 | 35 | --- 36 | 37 | # Collaborating Guidelines 38 | 39 | **This is an OPEN Open Source Project.** 40 | 41 | ## What? 42 | 43 | Individuals making significant and valuable contributions are given commit access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. 44 | 45 | ## Rules 46 | 47 | There are a few basic ground rules for collaborators: 48 | 49 | 1. **No `--force` pushes** or modifying the Git history in any way. 50 | 1. **Non-master branches** ought to be used for ongoing work. 51 | 1. **External API changes and significant modifications** ought to be subject to an **internal pull request** to solicit feedback from other collaborators. 52 | 1. Internal pull requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor. 53 | 1. Contributors should attempt to adhere to the prevailing code style. 54 | 55 | ## Releases 56 | 57 | Declaring formal releases remains the prerogative of the project maintainer. 58 | 59 | ## Changes to this arrangement 60 | 61 | This is an experiment and feedback is welcome! This document may also be subject to pull requests or changes by collaborators where you believe you have something valuable to add or change. 62 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Nate Goldman 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NO LONGER MAINTAINED 2 | 3 | This is a public archive. Use at your own risk. 4 | 5 | 🖖 6 | 7 | --- 8 | 9 | # init-module 10 | 11 | > Add some sugar to the npm init command. 12 | 13 | [![npm][npm-image]][npm-url] 14 | [![travis][travis-image]][travis-url] 15 | [![style][style-image]][style-url] 16 | [![downloads][downloads-image]][npm-url] 17 | 18 | [npm-image]: https://img.shields.io/npm/v/init-module.svg?style=flat-square 19 | [npm-url]: https://www.npmjs.com/package/init-module 20 | [travis-image]: https://img.shields.io/travis/ungoldman/init-module.svg?style=flat-square 21 | [travis-url]: https://travis-ci.org/ungoldman/init-module 22 | [style-image]: https://img.shields.io/badge/code%20style-unstyled-brightgreen.svg?style=flat-square 23 | [style-url]: https://github.com/mapbox/eslint-config-unstyled 24 | [downloads-image]: https://img.shields.io/npm/dm/init-module.svg?style=flat-square 25 | 26 | `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. 27 | 28 | ## Install 29 | 30 | ``` 31 | npm i -g init-module 32 | ``` 33 | 34 | ## Usage 35 | 36 | `npm` allows you to configure an [`init module`](https://docs.npmjs.com/misc/config#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. 37 | 38 | ``` 39 | npm set init-module $(init-module --path) 40 | ``` 41 | 42 | Once you've set the above config property, `init-module` will simply extend the default `npm init` command. 43 | 44 | ``` 45 | npm init 46 | ``` 47 | 48 | ### Configuration (`npm init`) 49 | 50 | These defaults are already available to `npm init` without `init-module`. 51 | 52 | #### Author Name: `init-author-name` 53 | 54 | - Default: "" 55 | - Type: String 56 | 57 | The value `npm init` should use by default for the package author's name. 58 | 59 | ``` 60 | npm set init-author-name="Your Name" 61 | ``` 62 | 63 | #### Author Email: `init-author-email` 64 | 65 | - Default: "" 66 | - Type: String 67 | 68 | The value `npm init` should use by default for the package author's email. 69 | 70 | ``` 71 | npm set init-author-email="your@email.com" 72 | ``` 73 | 74 | #### Author URL: `init-author-url` 75 | 76 | - Default: "" 77 | - Type: String 78 | 79 | The value `npm init` should use by default for the package author's homepage. 80 | 81 | ``` 82 | npm set init-author-url="http://yoursite.com" 83 | ``` 84 | 85 | #### License `init-license` 86 | 87 | - Default: "ISC" 88 | - Type: String 89 | 90 | The value `npm init` should use by default for the package license. 91 | 92 | ``` 93 | npm set init-license="BSD-2-Clause" 94 | ``` 95 | 96 | The license name must be a valid SPDX license expression. See https://spdx.org/licenses for more info. 97 | 98 | #### Version `init-version` 99 | 100 | - Default: "1.0.0" 101 | - Type: semver 102 | 103 | The value that `npm init` should use by default for the package version number, if not already set in `package.json`. 104 | 105 | ``` 106 | npm set init-version="1.0.0" 107 | ``` 108 | 109 | ### Configuration (`init-module`) 110 | 111 | These defaults require `init-module` in order to be available in `npm init`. 112 | 113 | #### Start Script: `init-scripts-start` 114 | 115 | - Default: null 116 | - Type: String 117 | 118 | The command to use when running `npm start`. 119 | 120 | ``` 121 | npm set init-scripts-start="node ." 122 | ``` 123 | 124 | #### Test Script: `init-scripts-test` 125 | 126 | - Default: 'echo "Error: no test specified" && exit 1' 127 | - Type: String 128 | 129 | The command to use when running `npm test`. 130 | 131 | ``` 132 | npm set init-scripts-test="standard" 133 | ``` 134 | 135 | ## Example 136 | 137 | Here's an example of the `init-*` contents of my global `.npmrc` file. 138 | 139 | ``` 140 | init-author-email = "ungoldman@gmail.com" 141 | init-author-name = "Nate Goldman" 142 | init-author-url = "http://ungoldman.com/" 143 | init-license = "ISC" 144 | init-module = "/Users/ng/dev/github/init-module/init-module.js" 145 | init-scripts-start = "node ." 146 | init-scripts-test = "standard" 147 | init-version = "1.0.0" 148 | ``` 149 | 150 | 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). 151 | 152 | Running `npm init` in an empty directory with the above configuration, I get the following: 153 | 154 | ``` 155 | ~/my-module $ npm init 156 | This utility will walk you through creating a package.json file. 157 | It only covers the most common items, and tries to guess sensible defaults. 158 | 159 | See `npm help json` for definitive documentation on these fields 160 | and exactly what they do. 161 | 162 | Use `npm install --save` afterwards to install a package and 163 | save it as a dependency in the package.json file. 164 | 165 | Press ^C at any time to quit. 166 | name: (my-module) 167 | version: (1.0.0-alpha) 168 | description: A fine module indeed. 169 | entry point: (index.js) 170 | test command: (standard) 171 | start command: (node .) 172 | git repository: https://github.com/ungoldman/my-module.git 173 | keywords: my, module 174 | author name: (Nate Goldman) 175 | author email: (ungoldman@gmail.com) 176 | author url: (http://ungoldman.com) 177 | license: (ISC) 178 | private: (false) true 179 | About to write to /Users/ng/dev/github/init-module/my-module/package.json: 180 | 181 | { 182 | "name": "my-module", 183 | "version": "1.0.0-alpha", 184 | "description": "A fine module indeed.", 185 | "main": "index.js", 186 | "scripts": { 187 | "start": "node .", 188 | "test": "standard" 189 | }, 190 | "repository": { 191 | "type": "git", 192 | "url": "git+https://github.com/ungoldman/my-module.git" 193 | }, 194 | "keywords": [ 195 | "my", 196 | "module" 197 | ], 198 | "author": "Nate Goldman (http://ungoldman.com)", 199 | "license": "ISC", 200 | "private": true, 201 | "bugs": { 202 | "url": "https://github.com/ungoldman/my-module/issues" 203 | }, 204 | "homepage": "https://github.com/ungoldman/my-module#readme" 205 | } 206 | 207 | 208 | Is this ok? (yes) 209 | ``` 210 | 211 | 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. 212 | 213 | ``` 214 | name: (my-module) 215 | version: (1.0.0-alpha) 216 | description: (A fine module indeed.) 217 | entry point: (index.js) 218 | test command: (standard && tape test/*.js | tap-spec) 219 | git repository: (git+https://github.com/ungoldman/my-module.git) 220 | keywords: (my, module) 221 | author name: (Nate Goldman) 222 | author email: (ungoldman@gmail.com) 223 | author url: (http://ungoldman.com) 224 | license: (ISC) 225 | private: (true) 226 | ``` 227 | 228 | ### The "yes" option (force) 229 | 230 | Running `npm init -y` in an empty directory with the example configuration above yields the following `package.json`: 231 | 232 | ```json 233 | { 234 | "name": "my-module", 235 | "version": "1.0.0-alpha", 236 | "description": "", 237 | "main": "index.js", 238 | "scripts": { 239 | "test": "standard && tape test/*.js | tap-spec" 240 | }, 241 | "author": "Nate Goldman (http://ungoldman.com)", 242 | "license": "ISC" 243 | } 244 | ``` 245 | 246 | ## Contributing 247 | 248 | Contributions welcome! Please read the [contributing guidelines](CONTRIBUTING.md) first. 249 | 250 | ## See also 251 | 252 | - [`module-init`](https://github.com/ungoldman/module-init) 253 | - [`maintenance-modules`](https://github.com/maxogden/maintenance-modules) 254 | 255 | ## License 256 | 257 | [ISC](LICENSE.md) 258 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var cliclopts = require('cliclopts') 4 | var minimist = require('minimist') 5 | var main = require.resolve('../init-module.js') 6 | 7 | var allowedOptions = [ 8 | { 9 | name: 'path', 10 | abbr: 'p', 11 | help: 'Print the path to the main init-module file', 12 | boolean: true 13 | }, 14 | { 15 | name: 'config', 16 | abbr: 'c', 17 | help: 'Configure npm init defaults', 18 | boolean: true 19 | }, 20 | { 21 | name: 'help', 22 | abbr: 'h', 23 | help: 'Show help', 24 | boolean: true 25 | } 26 | ] 27 | 28 | var opts = cliclopts(allowedOptions) 29 | var argv = minimist(process.argv.slice(2), opts.options()) 30 | 31 | function printUsageAndExit () { 32 | console.log('Usage: init-module [options]') 33 | opts.print() 34 | process.exit() 35 | } 36 | 37 | if (argv.help) { 38 | printUsageAndExit() 39 | } 40 | 41 | if (argv.path) { 42 | console.log(main) 43 | process.exit() 44 | } 45 | 46 | printUsageAndExit() 47 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var initModule = require.resolve('./init-module') 2 | 3 | module.exports = function () { 4 | return initModule 5 | } 6 | -------------------------------------------------------------------------------- /init-module.js: -------------------------------------------------------------------------------- 1 | /* global package, config, yes, dirname, basename */ 2 | 3 | /* 4 | Some things to know: 5 | 6 | init-package-json & promzard inject some variables into this module. 7 | 8 | - `package` is the parsed contents of package.json if it exists 9 | - `config` gives you access to preferences set in npm config 10 | - `yes` is what you get when you run `npm init {--force|-f|--yes|y}` 11 | - `dirname` is the full path of the current directory 12 | - `basename` is the name of the current directory 13 | - `filename` is the full path to package.json in the current directory 14 | - `prompt` is a promzard prompt that behaves a little strangely 15 | - see https://github.com/npm/promzard#prompt for function signature 16 | - looks sync, is actually async, but gets replaced with tokens 17 | - see https://github.com/npm/promzard#sync-vs-async for more on that 18 | 19 | all code below has been adapted from https://github.com/npm/init-package-json 20 | */ 21 | 22 | var fs = require('fs') 23 | var glob = require('glob') 24 | var path = require('path') 25 | var validateLicense = require('validate-npm-package-license') 26 | var validateName = require('validate-npm-package-name') 27 | var npa = require('npm-package-arg') 28 | var semver = require('semver') 29 | 30 | // more popular packages should go here, maybe? 31 | function isTestPkg (p) { 32 | return !!p.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/) 33 | } 34 | 35 | function niceName (n) { 36 | return n.replace(/^node-|[.-]js$/g, '').toLowerCase() 37 | } 38 | 39 | function isTruthy (str) { 40 | var s = str.toLowerCase() 41 | if (s === "true" || 42 | s === "yes" || 43 | s === "y") { 44 | return true 45 | } 46 | return false 47 | } 48 | 49 | function spaceMeansBlank (input) { 50 | if (input === " ") return null 51 | return input 52 | } 53 | 54 | function readDeps (test) { return function (cb) { 55 | fs.readdir('node_modules', function (err, dir) { 56 | if (err) return cb() 57 | var deps = {} 58 | var n = dir.length 59 | if (n === 0) return cb(null, deps) 60 | dir.forEach(function (d) { 61 | if (d.match(/^\./)) return next() 62 | if (test !== isTestPkg(d)) return next() 63 | var dp = path.join(dirname, 'node_modules', d, 'package.json') 64 | fs.readFile(dp, 'utf8', function (err, p) { 65 | if (err) return next() 66 | try { p = JSON.parse(p) } 67 | catch (e) { return next() } 68 | if (!p.version) return next() 69 | if (p._requiredBy) { 70 | if (!p._requiredBy.some(function (req) { return req === '#USER' })) return next() 71 | } 72 | deps[d] = config.get('save-exact') ? 73 | p.version : config.get('save-prefix') + p.version 74 | return next() 75 | }) 76 | }) 77 | function next () { if (--n === 0) return cb(null, deps) } 78 | }) 79 | }} 80 | 81 | // name 82 | 83 | var name = package.name || basename 84 | var spec = npa(name) 85 | var scope = config.get('scope') 86 | 87 | if (scope) { 88 | if (scope.charAt(0) !== '@') scope = '@' + scope 89 | if (spec.scope) { 90 | name = scope + '/' + spec.name.split('/')[1] 91 | } else { 92 | name = scope + '/' + name 93 | } 94 | } 95 | 96 | exports.name = yes ? name : 97 | prompt('name', name, function (data) { 98 | var its = validateName(data) 99 | if (its.validForNewPackages) return data 100 | var errors = (its.errors || []).concat(its.warnings || []) 101 | var err = new Error('Sorry, ' + errors.join(' and ') + '.') 102 | err.notValid = true 103 | return err 104 | }) 105 | 106 | // version 107 | 108 | var version = package.version || 109 | config.get('init-version') || 110 | '1.0.0' 111 | 112 | exports.version = yes ? version : 113 | prompt('version', version, function (version) { 114 | if (semver.valid(version)) return version 115 | var err = new Error('Invalid version: "' + version + '"') 116 | err.notValid = true 117 | return err 118 | }) 119 | 120 | // description 121 | 122 | var desc = package.description || '' 123 | 124 | exports.description = yes ? desc : prompt('description', desc || null) 125 | 126 | // main 127 | 128 | var main = package.main || null 129 | 130 | exports.main = function (cb) { 131 | fs.readdir(dirname, function (err, f) { 132 | if (err) f = [] 133 | 134 | f = f.filter(function (f) { 135 | return f.match(/\.js$/) 136 | }) 137 | 138 | if (f.indexOf('index.js') !== -1) 139 | f = 'index.js' 140 | else if (f.indexOf('main.js') !== -1) 141 | f = 'main.js' 142 | else if (f.indexOf(basename + '.js') !== -1) 143 | f = basename + '.js' 144 | else 145 | f = f[0] 146 | 147 | var index = f || 'index.js' 148 | return cb(null, yes ? index : prompt('entry point', main || index)) 149 | }) 150 | } 151 | 152 | // bin 153 | 154 | if (!package.bin) { 155 | exports.bin = function (cb) { 156 | fs.readdir(path.resolve(dirname, 'bin'), function (err, d) { 157 | // no bins 158 | if (err) return cb() 159 | // just take the first js file we find there, or nada 160 | return cb(null, d.filter(function (f) { 161 | return f.match(/\.js$/) 162 | })[0]) 163 | }) 164 | } 165 | } 166 | 167 | // dependencies 168 | 169 | if (!package.dependencies) { 170 | exports.dependencies = readDeps(false) 171 | } 172 | 173 | // devDependencies 174 | 175 | if (!package.devDependencies) { 176 | exports.devDependencies = readDeps(true) 177 | } 178 | 179 | // scripts 180 | 181 | // MUST have a test script! 182 | 183 | exports.scripts = function (cb) { 184 | fs.readdir(path.join(dirname, 'node_modules'), function (err, deps) { 185 | // error is fine 186 | setupScripts(deps || [], cb) 187 | }) 188 | } 189 | 190 | function setupScripts (deps, cb) { 191 | var scripts = package.scripts || {} 192 | var notest = 'echo "Error: no test specified" && exit 1' 193 | var startCmd = scripts.start || config.get('init-scripts-start') || null 194 | var testCmd = scripts.test || config.get('init-scripts-test') || notest 195 | 196 | scripts.start = yes ? startCmd : prompt('start command', startCmd, spaceMeansBlank) 197 | scripts.test = yes ? testCmd : prompt('test command', testCmd, spaceMeansBlank) 198 | 199 | return cb(null, scripts) 200 | } 201 | 202 | // repository 203 | 204 | var repo = package.repository 205 | 206 | exports.repository = function (cb) { 207 | if (repo) return cb(null, yes ? repo : prompt('git repository', repo.url || repo)) 208 | 209 | fs.readFile('.git/config', 'utf8', function (err, gitconfig) { 210 | if (err || !gitconfig) { 211 | return cb(null, yes ? '' : prompt('git repository')) 212 | } 213 | 214 | gitconfig = gitconfig.split(/\r?\n/) 215 | var i = gitconfig.indexOf('[remote "origin"]') 216 | 217 | if (i !== -1) { 218 | var u = gitconfig[i + 1] 219 | if (!u.match(/^\s*url =/)) u = gitconfig[i + 2] 220 | if (!u.match(/^\s*url =/)) u = null 221 | else u = u.replace(/^\s*url = /, '') 222 | } 223 | 224 | if (u && u.match(/^git@github.com:/)) { 225 | u = u.replace(/^git@github.com:/, 'https://github.com/') 226 | } 227 | 228 | return cb(null, yes ? u : prompt('git repository', u)) 229 | }) 230 | } 231 | 232 | // keywords 233 | 234 | var keywords = package.keywords || [] 235 | 236 | 237 | 238 | exports.keywords = yes ? 239 | keywords.length ? keywords : null : 240 | prompt('keywords', keywords.join(', '), function (s) { 241 | if (!s) return undefined 242 | if (Array.isArray(s)) s = s.join(' ') 243 | if (typeof s !== 'string') return s 244 | return s.split(/[\s,]+/) 245 | }) 246 | 247 | // author 248 | 249 | var author = package.author || { 250 | "name" : config.get('init-author-name'), 251 | "email" : config.get('init-author-email'), 252 | "url" : config.get('init-author-url') 253 | } 254 | 255 | exports.author = yes ? author : 256 | { 257 | "name" : prompt('author name', author.name, spaceMeansBlank), 258 | "email" : prompt('author email', author.email, spaceMeansBlank), 259 | "url" : prompt('author url', author.url, spaceMeansBlank) 260 | } 261 | 262 | // license 263 | 264 | var license = package.license || 265 | config.get('init-license') || 266 | 'ISC' 267 | 268 | exports.license = yes ? license : prompt('license', license, function (data) { 269 | var its = validateLicense(data) 270 | if (its.validForNewPackages) return data 271 | var errors = (its.errors || []).concat(its.warnings || []) 272 | var err = new Error('Sorry, ' + errors.join(' and ') + '.') 273 | err.notValid = true 274 | return err 275 | }) 276 | 277 | // directories 278 | 279 | // ignore directories since it doesn't get used by anything 280 | exports.directories = null 281 | 282 | // private 283 | 284 | var isPrivate = package.private || null 285 | 286 | exports.private = yes ? isPrivate : prompt('private', isPrivate ? 'true' : 'false', function (bool) { 287 | if (isTruthy(bool)) return true 288 | else return null 289 | }) 290 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "init-module", 3 | "description": "Add some sugar to the npm init command.", 4 | "version": "1.0.0", 5 | "author": "Nate Goldman (http://ungoldman.com/)", 6 | "bin": { 7 | "init-module": "./bin/cli.js" 8 | }, 9 | "bugs": { 10 | "url": "https://github.com/ungoldman/init-module/issues" 11 | }, 12 | "dependencies": { 13 | "cliclopts": "^1.1.1", 14 | "glob": "^7.0.0", 15 | "minimist": "^1.2.0", 16 | "npm-package-arg": "^4.1.0", 17 | "semver": "^5.1.0", 18 | "validate-npm-package-license": "^3.0.1", 19 | "validate-npm-package-name": "^2.2.2" 20 | }, 21 | "devDependencies": { 22 | "eslint": "^1.10.3", 23 | "eslint-config-unstyled": "^1.1.0", 24 | "tap-spec": "^4.0.2", 25 | "tape": "^4.0.0" 26 | }, 27 | "homepage": "https://github.com/ungoldman/init-module", 28 | "keywords": [ 29 | "helper", 30 | "init", 31 | "package", 32 | "package.json", 33 | "prompt", 34 | "start", 35 | "wizard", 36 | "wizerd" 37 | ], 38 | "license": "ISC", 39 | "main": "index.js", 40 | "repository": { 41 | "type": "git", 42 | "url": "git+https://github.com/ungoldman/init-module.git" 43 | }, 44 | "scripts": { 45 | "test": "npm run test:lint && npm run test:unit", 46 | "test:lint": "eslint .", 47 | "test:unit": "tape test/*.js | tap-spec" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var exec = require('child_process').exec 3 | var correctPath = require.resolve('../init-module.js') 4 | 5 | test('cli: path option', function (t) { 6 | exec('./bin/cli.js --path', function (err, stdout, stderr) { 7 | t.error(err, 'no error') 8 | t.error(stderr, 'no stderr') 9 | t.equals(stdout.replace('\n',''), correctPath, 'returned correct path') 10 | t.end() 11 | }) 12 | }) 13 | --------------------------------------------------------------------------------