├── .gitignore ├── LICENSE ├── README.md ├── bin ├── initialize ├── prompt.js └── usage.txt ├── index.js ├── package.json └── templates ├── LICENSE ├── README.md ├── _.gitignore ├── _.travis.yml ├── index.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | tmp/ 4 | npm-debug.log* 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Yoshua Wuyts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # initialize [![stability][0]][1] 2 | [![NPM version][2]][3] [![Downloads][4]][5] [![js-standard-style][6]][7] 3 | 4 | Create a new repo with sane defaults. Provides all the tools needed to create 5 | a unix style module. 6 | 7 | ## Installation 8 | ```sh 9 | $ npm install -g initialize 10 | ``` 11 | 12 | ## Usage 13 | ```txt 14 | initialize - generate a fresh package 15 | 16 | Usage: initialize [options] 17 | 18 | Options: 19 | -h, --help Output usage information 20 | -v, --version Output version number 21 | -u, --user Override user with organization 22 | -d, --directory Specify output directory 23 | 24 | Examples: 25 | $ initialize # generate package in `./` 26 | $ initialize -d ./dir # generate package in `./dir` 27 | $ initialize -u npm # generate package for `npm` 28 | 29 | Docs: https://github.com/yoshuawuyts/initialize 30 | Bugs: https://github.com/yoshuawuyts/initialize/issues 31 | ``` 32 | 33 | ## .npmrc 34 | Requires npm to be configured: 35 | ```sh 36 | # required 37 | npm config set init.author.name "Your Name" 38 | npm config set init.author.email "me@example.com" 39 | npm config set init.author.github "your-github-handle" 40 | 41 | # optional, defaults to your github 42 | npm config set init.author.url "http://your-site.com/" 43 | ``` 44 | 45 | ## Variables 46 | The following variables are used in the templates: 47 | ```txt 48 | name Name of the package 49 | varName Name of package usable as JS var 50 | description Description of the package 51 | tags Package tags 52 | user Logged in user (github) 53 | realName User's real name 54 | date.year Current year 55 | date.month Current month 56 | date.day Current day 57 | date.date Current date 58 | ``` 59 | 60 | ## See Also 61 | - [initialize-cli][10] 62 | - [initialize-project][11] 63 | - [initialize-subpackage][12] 64 | 65 | ## License 66 | [MIT](https://tldrlegal.com/license/mit-license) 67 | 68 | [0]: https://img.shields.io/badge/stability-stable-brightgreen.svg?style=flat-square 69 | [1]: https://nodejs.org/api/documentation.html#documentation_stability_index 70 | [2]: https://img.shields.io/npm/v/initialize.svg?style=flat-square 71 | [3]: https://npmjs.org/package/initialize 72 | [4]: http://img.shields.io/npm/dm/initialize.svg?style=flat-square 73 | [5]: https://npmjs.org/package/initialize 74 | [6]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 75 | [7]: https://github.com/feross/standard 76 | [10]: http://github.com/yoshuawuyts/initialize-cli 77 | [11]: http://github.com/yoshuawuyts/initialize-project 78 | [12]: http://github.com/yoshuawuyts/initialize-subpackage 79 | -------------------------------------------------------------------------------- /bin/initialize: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const cliclopts = require('cliclopts') 3 | const minimist = require('minimist') 4 | const fs = require('fs') 5 | 6 | const createPkg = require('../') 7 | 8 | const opts = cliclopts([ 9 | { 10 | name: 'help', 11 | abbr: 'h', 12 | boolean: true 13 | }, 14 | { 15 | name: 'version', 16 | abbr: 'v', 17 | boolean: true 18 | }, 19 | { 20 | name: 'directory', 21 | abbr: 'd', 22 | default: './' 23 | } 24 | ]) 25 | 26 | const argv = minimist(process.argv.slice(2), opts.options()) 27 | 28 | // parse options 29 | if (argv.version) { 30 | const version = require('../package.json').version 31 | process.stdout.write('v' + version) 32 | process.exit(0) 33 | } 34 | else if (argv.help) usage(0) 35 | else createPkg(argv) 36 | 37 | // print usage & exit 38 | // num? -> null 39 | function usage (exitCode) { 40 | fs.createReadStream(__dirname + '/usage.txt') 41 | .pipe(process.stdout) 42 | .on('close', process.exit.bind(null, exitCode)) 43 | } 44 | -------------------------------------------------------------------------------- /bin/prompt.js: -------------------------------------------------------------------------------- 1 | const prompt = require('inquirer').prompt 2 | 3 | module.exports = runPrompt 4 | 5 | // create prompt 6 | // (obj, fn) -> null 7 | function runPrompt (opts, cb) { 8 | prompt([ 9 | { 10 | name: 'name', 11 | message: 'Package name', 12 | default: opts.packageName || '' 13 | }, 14 | { 15 | name: 'description', 16 | message: 'Module description' 17 | }, 18 | { 19 | name: 'tags', 20 | message: 'Module tags' 21 | } 22 | ], cb) 23 | } 24 | -------------------------------------------------------------------------------- /bin/usage.txt: -------------------------------------------------------------------------------- 1 | initialize - generate a fresh package 2 | 3 | Usage: initialize [options] 4 | 5 | Options: 6 | -h, --help Output usage information 7 | -v, --version Output version number 8 | -u, --user Override user with organization 9 | -d, --directory Specify output directory 10 | 11 | Examples: 12 | $ initialize # generate package in `./` 13 | $ initialize -d ./dir # generate package in `./dir` 14 | $ initialize -u npm # generate package for `npm` 15 | 16 | Docs: https://github.com/yoshuawuyts/initialize 17 | Bugs: https://github.com/yoshuawuyts/initialize/issues 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const variableName = require('variable-name') 2 | const engine = require('initialize-engine') 3 | const prompt = require('inquirer').prompt 4 | const assign = require('object-assign') 5 | const today = require('dates-of-today') 6 | const gitInit = require('git-init') 7 | const mkdirp = require('mkdirp') 8 | const path = require('path') 9 | const rc = require('rc') 10 | 11 | const opts = { 12 | templates: path.join(__dirname, 'templates'), 13 | pre: [ 14 | runPrompt, 15 | createDir, 16 | getDate, 17 | getUser, 18 | createGit 19 | ], 20 | files: [ 21 | '.gitignore', 22 | '.travis.yml', 23 | 'LICENSE', 24 | 'README.md', 25 | 'index.js', 26 | 'package.json', 27 | 'test.js' 28 | ], 29 | devDependencies: [ 30 | 'dependency-check', 31 | 'istanbul', 32 | 'standard', 33 | 'tape' 34 | ] 35 | } 36 | 37 | module.exports = engine.bind(null, opts) 38 | create.opts = opts 39 | 40 | // create a new package 41 | // obj -> null 42 | function create (argv) { 43 | engine(opts, argv) 44 | } 45 | 46 | // create prompt 47 | // (obj, fn) -> null 48 | function runPrompt (argv, cb) { 49 | const questions = [ 50 | { 51 | name: 'name', 52 | default: '', 53 | message: 'Package name' 54 | }, 55 | { 56 | name: 'description', 57 | message: 'Module description', 58 | default: '', 59 | filter: function (str) { 60 | if (!str) return 61 | return str[0].toUpperCase() + str.slice(1) 62 | } 63 | }, 64 | { 65 | name: 'tags', 66 | default: '', 67 | message: 'Module tags', 68 | filter: function (str) { 69 | str = str || '' 70 | return str.split(',').map(function (str) { 71 | return '"' + str.trim() + '"' 72 | }) 73 | } 74 | } 75 | ] 76 | 77 | prompt(questions, function (res) { 78 | res.varName = variableName(res.name) 79 | assign(argv, res) 80 | cb() 81 | }) 82 | } 83 | 84 | // create specified path 85 | // (obj, fn) -> null 86 | function createDir (argv, next) { 87 | const loc = path.resolve(path.join(argv.d, argv.name)) 88 | mkdirp(loc, function (err) { 89 | if (err) return next(err) 90 | process.chdir(loc) 91 | argv.directory = loc 92 | argv.d = loc 93 | next() 94 | }) 95 | } 96 | 97 | // get the current user if no user was 98 | // specified 99 | // (obj, fn) -> null 100 | function getUser (argv, next) { 101 | if (argv.user) return next() 102 | 103 | const conf = rc('npm') 104 | if (!conf) return next('no npm config found') 105 | 106 | const github = conf['init.author.github'] 107 | if (!github) return next('no init.author.github set') 108 | 109 | const name = conf['init.author.name'] 110 | if (!name) return next('no init.author.name set') 111 | 112 | argv.user = github 113 | argv.realName = name 114 | next() 115 | } 116 | 117 | // get today's dates 118 | // (obj, fn) -> null 119 | function getDate (argv, next) { 120 | argv.date = today() 121 | next() 122 | } 123 | 124 | // create git repository 125 | // (obj, cb) -> null 126 | function createGit (argv, next) { 127 | const path = argv.path 128 | gitInit(path, next) 129 | } 130 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "initialize", 3 | "version": "7.3.1", 4 | "description": "Generate a fresh package", 5 | "main": "index.js", 6 | "bin": "./bin/initialize", 7 | "scripts": { 8 | "test": "node bin/initialize -d ./tmp", 9 | "test:random": "node bin/initialize -d ./tmp/\"$RANDOM\"", 10 | "clean": "rm -rf ./tmp", 11 | "deps": "dependency-check . && dependency-check . --extra --no-dev" 12 | }, 13 | "repository": "yoshuawuyts/initialize", 14 | "preferGlobal": true, 15 | "keywords": [ 16 | "new", 17 | "project", 18 | "cli", 19 | "shell" 20 | ], 21 | "license": "MIT", 22 | "dependencies": { 23 | "cliclopts": "^1.1.1", 24 | "dates-of-today": "^1.0.0", 25 | "git-init": "^1.0.0", 26 | "initialize-engine": "^1.1.0", 27 | "inquirer": "^1.1.2", 28 | "minimist": "^1.1.3", 29 | "mkdirp": "^0.5.1", 30 | "object-assign": "^4.1.0", 31 | "rc": "^1.1.0", 32 | "variable-name": "2.0.0" 33 | }, 34 | "devDependencies": { 35 | "dependency-check": "^2.5.0", 36 | "standard": "^8.0.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /templates/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) {{date.year}} {{realName}} 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /templates/README.md: -------------------------------------------------------------------------------- 1 | # {{name}} [![stability][0]][1] 2 | [![npm version][2]][3] [![build status][4]][5] [![test coverage][6]][7] 3 | [![downloads][8]][9] [![js-standard-style][10]][11] 4 | 5 | {{description}}. 6 | 7 | ## Usage 8 | ```js 9 | const {{varName}} = require('{{name}}') 10 | 11 | {{varName}}() 12 | ``` 13 | 14 | ## API 15 | ### {{varName}} 16 | 17 | ## Installation 18 | ```sh 19 | $ npm install {{name}} 20 | ``` 21 | 22 | ## License 23 | [MIT](https://tldrlegal.com/license/mit-license) 24 | 25 | [0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square 26 | [1]: https://nodejs.org/api/documentation.html#documentation_stability_index 27 | [2]: https://img.shields.io/npm/v/{{name}}.svg?style=flat-square 28 | [3]: https://npmjs.org/package/{{name}} 29 | [4]: https://img.shields.io/travis/{{user}}/{{name}}/master.svg?style=flat-square 30 | [5]: https://travis-ci.org/{{user}}/{{name}} 31 | [6]: https://img.shields.io/codecov/c/github/{{user}}/{{name}}/master.svg?style=flat-square 32 | [7]: https://codecov.io/github/{{user}}/{{name}} 33 | [8]: http://img.shields.io/npm/dm/{{name}}.svg?style=flat-square 34 | [9]: https://npmjs.org/package/{{name}} 35 | [10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 36 | [11]: https://github.com/feross/standard 37 | -------------------------------------------------------------------------------- /templates/_.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | tmp/ 4 | npm-debug.log* 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /templates/_.travis.yml: -------------------------------------------------------------------------------- 1 | node_js: 2 | - "0.12" 3 | - "4" 4 | sudo: false 5 | language: node_js 6 | script: "npm run test:cov" 7 | after_script: "npm i -g codecov.io && cat ./coverage/lcov.info | codecov" 8 | -------------------------------------------------------------------------------- /templates/index.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | 3 | module.exports = {{varName}} 4 | 5 | // {{description}} 6 | // null -> null 7 | function {{varName}} () { 8 | } 9 | -------------------------------------------------------------------------------- /templates/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{name}}", 3 | "version": "1.0.0", 4 | "description": "{{description}}", 5 | "main": "index.js", 6 | "scripts": { 7 | "deps": "dependency-check . && dependency-check . --extra --no-dev", 8 | "test": "standard && npm run deps && NODE_ENV=test node test", 9 | "test:cov": "standard && npm run deps && NODE_ENV=test istanbul cover test.js" 10 | }, 11 | "repository": "{{user}}/{{name}}", 12 | "keywords": [{{{tags}}}], 13 | "license": "MIT", 14 | "dependencies": { 15 | }, 16 | "devDependencies": { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /templates/test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const {{varName}} = require('./') 3 | 4 | test('should assert input types', function (t) { 5 | t.plan(1) 6 | t.throws({{varName}}) 7 | }) 8 | --------------------------------------------------------------------------------