├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jshintrc ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── index.js └── templates │ ├── Readme.md │ ├── _package.json │ ├── bin │ └── cmdrexec │ ├── cmds │ └── command.js │ ├── editorconfig │ ├── gitignore │ ├── jshintrc │ ├── lib │ └── component.js │ ├── test │ └── test.js │ └── travis.yml ├── command └── index.js ├── component └── index.js ├── package.json ├── test ├── test-creation.js └── test-load.js └── todo.md /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | temp/ 3 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 4, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "white": true 21 | } 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 Jayson Harshbarger 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # generator-commander [![Build Status](https://secure.travis-ci.org/Hypercubed/generator-commander.png?branch=master)](https://travis-ci.org/Hypercubed/generator-commander) [![NPM version](https://badge.fury.io/js/generator-commander.png)](http://badge.fury.io/js/generator-commander) 2 | 3 | A CLI generator for [Yeoman](http://yeoman.io). 4 | 5 | This generator will create a [Commander.js](https://github.com/visionmedia/commander.js) based command line application using [yo](https://github.com/yeoman/yo) with options to include [autocmdr](https://github.com/Hypercubed/autocmdr) components. 6 | 7 | ## Installation 8 | 9 | Install Yeoman if you haven't done so already. 10 | 11 | $ npm install -g yo 12 | 13 | To install generator-commander: 14 | 15 | $ npm install -g generator-commander 16 | 17 | ## Usage 18 | 19 | At the command-line, `cd` into an empty directory, run this command and initiate the app generator: 20 | 21 | $ yo commander 22 | 23 | This will generate files in the current working directory for a [Commander.js](https://github.com/visionmedia/commander.js) based application. 24 | 25 | To create a commander.js command-component initiate the command generator: 26 | 27 | $ yo commander:command 28 | 29 | This will create a new file in `cmds/` directory of the current working directory. This file can be included in your application by adding 30 | 31 | require('../cmds/.js')(program); 32 | 33 | to your application in the `bin` directory; or optionally install the `autocmdr` components for auto-loading `cmds`. 34 | 35 | ## [autocmdr](https://github.com/Hypercubed/autocmdr) and generator-commander 36 | 37 | [autocmdr](https://github.com/Hypercubed/autocmdr) and generator-commander are brothers. autcmdr is a command line tool for running commands (commands in a commander.js command-component) and a set of libraries for enhancing command line applications. generator-commander is a tool for scaffolding commander.js command-components and command line applications. 38 | 39 | Calling `autocmdr` from a shell will load commands located in the current working directory's `cmds/` folder. New commands can be added to any directory by invoking `yo commander:command `. When running `yo commander` you are given the option of including autocmdr components in your application. See the autocmdr [readme](https://github.com/Hypercubed/autocmdr/blob/master/Readme.md) for a complete workflow and explanation of the available components. 40 | 41 | ## What is Yeoman? 42 | 43 | If you'd like to get to know Yeoman better and meet some of his friends, [Grunt](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started). 44 | 45 | 46 | ## License 47 | 48 | [MIT License](http://en.wikipedia.org/wiki/MIT_License) 49 | 50 | Copyright (c) 2013 J. Harshbarger 51 | [![Gittip donate button](http://badgr.co/gittip/hypercubed.png)](https://www.gittip.com/hypercubed/ "Donate weekly to this project using Gittip") 52 | [![Paypal donate button](http://badgr.co/paypal/donate.png?bg=%23feb13d)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=X7KYR6T9U2NHC "One time donation to this project using Paypal") 53 | -------------------------------------------------------------------------------- /app/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | var path = require('path'); 5 | var yeoman = require('yeoman-generator'); 6 | var cp = require('child_process'); 7 | 8 | var GitHubApi = require('github'); 9 | var github = new GitHubApi({ 10 | version: '3.0.0' 11 | }); 12 | 13 | var CommanderGenerator = module.exports = function CommanderGenerator (args, options) { 14 | yeoman.generators.Base.apply(this, arguments); 15 | 16 | this.argument('name', { type: String, required: false }); 17 | this.name = this.name || path.basename(process.cwd()); 18 | 19 | this.on('end', function () { 20 | this.installDependencies({ skipInstall: options['skip-install'], bower: false }); 21 | }); 22 | 23 | this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json'))); 24 | }; 25 | 26 | util.inherits(CommanderGenerator, yeoman.generators.Base); 27 | 28 | CommanderGenerator.prototype.askFor = function askFor () { 29 | var cb = this.async(); 30 | 31 | // have Yeoman greet the user. 32 | console.log(this.yeoman); 33 | 34 | var prompts = [ 35 | { 36 | name: 'name', 37 | pattern: /^[a-zA-Z0-9\s\-]+$/, 38 | message: 'Name (must be only letters, spaces, or dashes)', 39 | default: this.name, 40 | required: true 41 | }, 42 | { name: 'version', default: '0.0.0', message: 'Version' }, 43 | { name: 'description', default: 'A commander CLI app', message: 'Description' }, 44 | // { name: 'homepage', message: 'Homepage' }, 45 | // { name: 'author', default: '', message: 'Author\'s Name' }, 46 | // { name: 'githubUser', message: 'GitHub username' }, 47 | // { name: 'authorEmail', message: 'Author\'s Email'}, 48 | // { name: 'authorUrl', message: 'Author\'s Homepage' }, 49 | { name: 'license', default: 'MIT', message: 'license' } 50 | ]; 51 | 52 | this.prompt(prompts, function (props) { 53 | util._extend(this, props); 54 | 55 | this.slugname = this._.slugify(props.name); 56 | this.dependencies = '"commander": "~2.0.0"'; 57 | 58 | this.licenseLink = (this.license === 'MIT') ? '[MIT License](http://en.wikipedia.org/wiki/MIT_License)' : this.license; 59 | 60 | this.year = (new Date()).getFullYear(); 61 | 62 | cb(); 63 | }.bind(this)); 64 | }; 65 | 66 | var githubUserInfo = function (name, cb) { 67 | github.user.getFrom({ 68 | user: name 69 | }, function (err, res) { 70 | if (err) { return cb(null); } 71 | cb(JSON.parse(JSON.stringify(res))); 72 | }); 73 | }; 74 | 75 | CommanderGenerator.prototype.githubInfo = function githubInfo () { 76 | var cb = this.async(); 77 | 78 | var prompts = [ 79 | { name: 'githubUser', message: 'GitHub username' } 80 | ]; 81 | 82 | this.prompt(prompts, function (props) { 83 | this.githubUser = props.githubUser; 84 | 85 | console.log(''); 86 | console.log(' Retrieving user information from GitHub. Please wait.'); 87 | githubUserInfo(this.githubUser, function (res) { 88 | if (res) { 89 | console.log(' Retrieved user information from GitHub.'); 90 | this.author = res.name; 91 | this.authorEmail = res.email; 92 | this.authorUrl = res.html_url; 93 | this.repoUrl = this.authorUrl + '/' + this.slugname; 94 | this.bugsUrl = this.repoUrl + '/issues'; 95 | } else { 96 | console.log(' Failed to retrieve user information from GitHub.'); 97 | this.author = ''; 98 | this.authorEmail = ''; 99 | this.authorUrl = 'https://github.com/' + this.githubUser + '/'; 100 | } 101 | 102 | this.repoUrl = this.authorUrl + '/' + this.slugname; 103 | this.bugsUrl = this.repoUrl + '/issues'; 104 | 105 | cb(); 106 | }.bind(this)); 107 | }.bind(this)); 108 | }; 109 | 110 | CommanderGenerator.prototype.userInfo = function userInfo () { 111 | var cb = this.async(); 112 | 113 | var prompts = [ 114 | { name: 'author', message: 'Author\'s Name', default: this.author }, 115 | { name: 'authorEmail', message: 'Author\'s Email', default: this.authorEmail }, 116 | { name: 'authorUrl', message: 'Author\'s Homepage', default: this.authorUrl }, 117 | { name: 'repoUrl', message: 'Repository URL', default: this.repoUrl }, 118 | { name: 'bugsUrl', message: 'Support URL', default: this.bugsUrl } 119 | ]; 120 | 121 | console.log(''); 122 | console.log(' Please confirm the following.'); 123 | this.prompt(prompts, function (props) { 124 | util._extend(this, props); 125 | 126 | console.log(''); 127 | 128 | cb(); 129 | }.bind(this)); 130 | }; 131 | 132 | CommanderGenerator.prototype.askForComponents = function askFor () { 133 | var cb = this.async(); 134 | 135 | var prompts = [ 136 | { 137 | name: 'components', 138 | type: 'checkbox', 139 | message: 'Additional components to install:', 140 | choices: [ 141 | { name: 'Logger (adds a Winston logger, required for config, package, loader, and help components)', value: 'logger' }, 142 | { name: 'Commander loader (automatically loads commands from cmds/ directory)', value: 'loader' }, 143 | { name: 'Autocompletion (adds command line autocompletion)', value: 'completion' }, 144 | { name: 'Package (load reasonable defaults from your application\'s package.json)', value: 'package' }, 145 | { name: 'Config (adds a config command)', value: 'config' }, 146 | { name: 'Help (adds a `did you mean` messege when an unknown command is given)', value: 'help' } 147 | ] 148 | } 149 | ]; 150 | 151 | this.prompt(prompts, function (props) { 152 | this.components = props.components; 153 | 154 | this.dependencies = '"commander": "~2.0.0"'; 155 | if (props.components.length > 0) { 156 | this.dependencies += ',\n "autocmdr": "~0.0.7"'; 157 | } 158 | 159 | var loggerNeeded = props.components.indexOf('config') > -1 || 160 | props.components.indexOf('help') > -1 || 161 | props.components.indexOf('loader') > -1 || 162 | props.components.indexOf('package') > -1; 163 | 164 | if (loggerNeeded && props.components.indexOf('logger') < 0) { 165 | props.components.unshift('logger'); // logger must be first 166 | } 167 | 168 | this.components = props.components 169 | .map(function (d) { return 'require(\'autocmdr/lib/' + d + '\')(program);'; }) 170 | .join('\n'); 171 | 172 | this.logger = props.components.indexOf('logger') > -1; 173 | this.package = props.components.indexOf('package') > -1; 174 | this.help = props.components.indexOf('help') > -1; 175 | 176 | cb(); 177 | }.bind(this)); 178 | }; 179 | 180 | CommanderGenerator.prototype.app = function app () { 181 | var cb = this.async(); // Need to ensure this runs before readme 182 | 183 | this.mkdir('bin'); 184 | 185 | this.template('_package.json', 'package.json'); 186 | this.template('bin/cmdrexec', 'bin/' + this.slugname); 187 | 188 | cb(); 189 | }; 190 | 191 | CommanderGenerator.prototype.readme = function readme () { 192 | var cb = this.async(); 193 | 194 | var bin = path.join(process.cwd(), './bin/', this.slugname); 195 | 196 | cp.exec('node ' + bin + ' --help', function (error, stdout) { 197 | this.usage = (error === null) ? stdout : 'node ./bin/' + this.slugname + ' --help'; 198 | this.template('Readme.md', 'Readme.md'); 199 | cb(); 200 | }.bind(this)); 201 | }; 202 | 203 | CommanderGenerator.prototype.test = function projectfiles () { 204 | this.mkdir('test'); 205 | 206 | this.template('test/test.js', 'test/' + this.slugname + '.js'); 207 | }; 208 | 209 | CommanderGenerator.prototype.projectfiles = function projectfiles () { 210 | this.copy('editorconfig', '.editorconfig'); 211 | this.copy('jshintrc', '.jshintrc'); 212 | this.copy('gitignore', '.gitignore'); 213 | this.copy('travis.yml', '.travis.yml'); 214 | }; 215 | -------------------------------------------------------------------------------- /app/templates/Readme.md: -------------------------------------------------------------------------------- 1 | #<%= name %> 2 | 3 | ## Description 4 | 5 | <%= description %> 6 | 7 | ## Usage 8 | 9 | To install <%= name %> from npm, run: 10 | 11 | ``` 12 | $ npm install -g <%= slugname %> 13 | ``` 14 | 15 | ```<%= usage %>``` 16 | 17 | ## License 18 | 19 | Copyright (c) <%= year %> <%= author %> 20 | 21 | <%= licenseLink %> 22 | 23 | ## Acknowledgments 24 | 25 | Built using [generator-commader](https://github.com/Hypercubed/generator-commander). 26 | -------------------------------------------------------------------------------- /app/templates/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= slugname %>", 3 | "version": "<%= version %>", 4 | "description": "<%= description %>", 5 | "private": true, 6 | "bin": { 7 | "<%= slugname %>": "./bin/<%= slugname %>" 8 | }, 9 | "scripts": { 10 | "test": "mocha -R spec" 11 | }, 12 | "author": { 13 | "name": "<%= author %>", 14 | "email": "<%= authorEmail %>"<% if (authorUrl) { %>, 15 | "url": "<%= authorUrl %>"<% } %> 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "<%= repoUrl %>" 20 | }, 21 | "license": "<%= license %>", 22 | "bugs": "<%= bugsUrl %>", 23 | "dependencies": { 24 | <%= dependencies %> 25 | }, 26 | "devDependencies": { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/templates/bin/cmdrexec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | var program = require('commander'); 5 | 6 | <%= components %> 7 | 8 | <% if (!package) { %> 9 | program 10 | .version('<%= version %>'); 11 | 12 | <% } 13 | 14 | if (!help) { %> 15 | program 16 | .on('*', function(name) { 17 | console.log('\''+name+'\' is not a known command. See \'<%= slugname %> --help\':'); 18 | program.outputHelp(); 19 | process.exit(1); 20 | }); 21 | <% } %> 22 | 23 | program 24 | .parse(process.argv); 25 | 26 | if (program.args.length < 1 ) { 27 | console.log('No command specified. See \'<%= slugname %> --help\':'); 28 | program.outputHelp(); 29 | process.exit(1); 30 | } 31 | -------------------------------------------------------------------------------- /app/templates/cmds/command.js: -------------------------------------------------------------------------------- 1 | /* <%= name %> commander component 2 | * To use add require('../cmds/<%= slugname %>.js')(program) to your commander.js based node executable before program.parse 3 | */ 4 | 'use strict'; 5 | 6 | module.exports = function(program) { 7 | 8 | program 9 | .command('<%= slugname %>') 10 | .version('<%= version %>') 11 | .description('<%= description %>') 12 | .action(function (<%= args %>) { 13 | <%= code %> 14 | }); 15 | 16 | }; 17 | -------------------------------------------------------------------------------- /app/templates/editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /app/templates/gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | npm-debug.log -------------------------------------------------------------------------------- /app/templates/jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 4, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "white": true 21 | } 22 | -------------------------------------------------------------------------------- /app/templates/lib/component.js: -------------------------------------------------------------------------------- 1 | /* <%= name %> commander component 2 | * To use add `require('../lib/<%= slugname %>.js')(program, opts)` to your commander.js based node executable before `program.parse`. 3 | */ 4 | 'use strict'; 5 | 6 | module.exports = function (program, opts) { 7 | 8 | <%= code %> 9 | 10 | }; 11 | -------------------------------------------------------------------------------- /app/templates/test/test.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 'use strict'; 3 | 4 | var assert = require('assert'); 5 | var exec = require('child_process').exec; 6 | var path = require('path'); 7 | 8 | describe('<%= slugname %> bin', function () { 9 | var cmd = 'node ' + path.join(__dirname, '../bin/<%= slugname %>') + ' '; 10 | console.log(cmd); 11 | 12 | it('--help should run without errors', function (done) { 13 | exec(cmd + '--help', function (error, stdout, stderr) { 14 | assert(!error); 15 | done(); 16 | }); 17 | }); 18 | 19 | it('--version should run without errors', function (done) { 20 | exec(cmd + '--version', function (error, stdout, stderr) { 21 | assert(!error); 22 | done(); 23 | }); 24 | }); 25 | 26 | it('should return error on missing command', function (done) { 27 | this.timeout(4000); 28 | 29 | exec(cmd, function (error, stdout, stderr) { 30 | assert(error); 31 | assert.equal(error.code, 1); 32 | done(); 33 | }); 34 | }); 35 | 36 | it('should return error on unknown command', function (done) { 37 | this.timeout(4000); 38 | 39 | exec(cmd + 'junkcmd', function (error, stdout, stderr) { 40 | assert(error); 41 | assert.equal(error.code, 1); 42 | done(); 43 | }); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /app/templates/travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.8' 4 | - '0.10' 5 | -------------------------------------------------------------------------------- /command/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | var yeoman = require('yeoman-generator'); 5 | 6 | var CommandGenerator = module.exports = function CommandGenerator () { 7 | yeoman.generators.Base.apply(this, arguments); 8 | 9 | this.argument('name', { type: String, required: false }); 10 | 11 | this.on('end', function () { 12 | console.log(); 13 | console.log('I\'m all done. Add `require(\'../cmds/' + this.name + '.js\')(program);` to your app before program.parse.'); 14 | console.log(); 15 | }); 16 | 17 | console.log('Generating a commander.js command component'); 18 | }; 19 | 20 | util.inherits(CommandGenerator, yeoman.generators.Base); 21 | 22 | CommandGenerator.prototype.askFor = function askFor () { 23 | var cb = this.async(); 24 | 25 | // have Yeoman greet the user. 26 | console.log(this.yeoman); 27 | 28 | var prompts = [ 29 | { 30 | name: 'name', 31 | pattern: /^[a-zA-Z0-9\s\-]+$/, 32 | message: 'Command name', 33 | default: this.name, 34 | required: true 35 | }, 36 | { name: 'version', default: '0.0.0', message: 'version' }, 37 | { name: 'description', default: 'A commander command', message: 'description' } 38 | ]; 39 | 40 | this.prompt(prompts, function (props) { 41 | util._extend(this, props); 42 | 43 | this.slugname = this._.slugify(props.name); 44 | this.args = '\/\* Args here \*\/'; 45 | this.code = '\/\/ Your code goes here'; 46 | 47 | cb(); 48 | }.bind(this)); 49 | }; 50 | 51 | CommandGenerator.prototype.files = function files () { 52 | this.mkdir('cmds'); 53 | this.template('../../app/templates/cmds/command.js', 'cmds/' + this.slugname + '.js'); 54 | }; 55 | -------------------------------------------------------------------------------- /component/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | var yeoman = require('yeoman-generator'); 5 | 6 | var ComponentGenerator = module.exports = function ComponentGenerator (args, options, config) { 7 | yeoman.generators.Base.apply(this, arguments); 8 | 9 | this.argument('name', { type: String, required: false }); 10 | 11 | this.on('end', function () { 12 | console.log(); 13 | console.log('I\'m all done. Add `require(\'../lib/' + this.name + '.js\')(program);` to your app before program.parse.'); 14 | console.log(); 15 | }); 16 | 17 | console.log('Generating a commander.js component'); 18 | }; 19 | 20 | util.inherits(ComponentGenerator, yeoman.generators.Base); 21 | 22 | ComponentGenerator.prototype.askFor = function askFor () { 23 | var cb = this.async(); 24 | 25 | // have Yeoman greet the user. 26 | console.log(this.yeoman); 27 | 28 | var prompts = [ 29 | { 30 | name: 'name', 31 | pattern: /^[a-zA-Z0-9\s\-]+$/, 32 | message: 'Component name', 33 | default: this.name, 34 | required: true 35 | } 36 | ]; 37 | 38 | this.prompt(prompts, function (props) { 39 | this.name = props.name; 40 | this.slugname = this._.slugify(props.name); 41 | this.code = '\/\/ Your code goes here'; 42 | 43 | cb(); 44 | }.bind(this)); 45 | }; 46 | 47 | ComponentGenerator.prototype.files = function files () { 48 | this.mkdir('lib'); 49 | this.template('../../app/templates/lib/component.js', 'lib/' + this.slugname + '.js'); 50 | }; 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-commander", 3 | "version": "0.0.11", 4 | "description": "A commander-cli generator for Yeoman", 5 | "keywords": [ 6 | "yeoman-generator", 7 | "commander", 8 | "cli" 9 | ], 10 | "homepage": "https://github.com/Hypercubed/generator-commander", 11 | "bugs": "https://github.com/Hypercubed/generator-commander/issues", 12 | "author": { 13 | "name": "Jayson Harshbarger", 14 | "email": "", 15 | "url": "https://github.com/Hypercubed" 16 | }, 17 | "main": "app/index.js", 18 | "files": [ 19 | "app", 20 | "command", 21 | "component" 22 | ], 23 | "repository": { 24 | "type": "git", 25 | "url": "git://github.com/Hypercubed/generator-commander.git" 26 | }, 27 | "scripts": { 28 | "test": "mocha -R spec" 29 | }, 30 | "dependencies": { 31 | "yeoman-generator": "~0.13.0", 32 | "github": "~0.1.10" 33 | }, 34 | "devDependencies": { 35 | "mocha": "~1.12.0" 36 | }, 37 | "peerDependencies": { 38 | "yo": ">=1.0.0-rc.1" 39 | }, 40 | "engines": { 41 | "node": ">=0.8.0", 42 | "npm": ">=1.2.10" 43 | }, 44 | "licenses": [ 45 | { 46 | "type": "MIT" 47 | } 48 | ], 49 | "semistandard": { 50 | "ignore": [ 51 | "app/templates/" 52 | ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/test-creation.js: -------------------------------------------------------------------------------- 1 | /* global describe, it, before */ 2 | 'use strict'; 3 | 4 | var path = require('path'); 5 | var helpers = require('yeoman-generator').test; 6 | 7 | describe('commander generators', function () { 8 | before(function (done) { 9 | helpers.testDirectory(path.join(__dirname, 'temp'), function (err) { 10 | if (err) { 11 | return done(err); 12 | } 13 | 14 | done(); 15 | }); 16 | }); 17 | 18 | it('commander:app, with components creates expected files', function (done) { 19 | this.app = helpers.createGenerator('commander:app', [ 20 | '../../app' 21 | ]); 22 | 23 | var expected = [ 24 | '.jshintrc', 25 | '.editorconfig', 26 | 'package.json', 27 | 'bin/example', 28 | 'test/example.js' 29 | ]; 30 | 31 | helpers.mockPrompt(this.app, { 32 | 'components': [ 'logger', 'loader', 'completion', 'package', 'config', 'help' ], 33 | 'name': 'example', 34 | 'version': '0.0.0', 35 | 'license': 'MIT', 36 | 'author': 'J. H. Doe', 37 | 'authorEmail': 'jhd@mail.com', 38 | 'authorUrl': 'http://github.com/jhdoe', 39 | 'repoUrl': 'http://github.com/jhdoe/example', 40 | 'bugsUrl': 'http://github.com/jhdoe/example/issues' 41 | }); 42 | 43 | this.app.options['skip-install'] = true; 44 | this.app.run({}, function () { 45 | helpers.assertFiles(expected); 46 | done(); 47 | }); 48 | }); 49 | 50 | /* it('commander:app without components creates expected files', function (done) { 51 | 52 | this.app = helpers.createGenerator('commander:app', [ 53 | '../../app' 54 | ]); 55 | 56 | var expected = [ 57 | '.jshintrc', 58 | '.editorconfig', 59 | 'package.json', 60 | 'bin/example', 61 | 'test/example.js' 62 | ]; 63 | 64 | helpers.mockPrompt(this.app, { 65 | 'components': [ 'logger', 'loader', 'completion', 'config', 'help' ], 66 | 'name': 'example', 67 | 'version': '0.0.0', 68 | 'license': 'MIT', 69 | 'author': 'J. H. Doe', 70 | 'authorEmail': 'jhd@mail.com', 71 | 'authorUrl': 'http://github.com/jhdoe', 72 | 'repoUrl': 'http://github.com/jhdoe/example', 73 | 'bugsUrl': 'http://github.com/jhdoe/example/issues' 74 | }); 75 | 76 | this.app.options['skip-install'] = true; 77 | this.app.run({}, function () { 78 | helpers.assertFiles(expected); 79 | done(); 80 | }); 81 | }); */ 82 | 83 | it('commander:command creates expected files', function (done) { 84 | this.app = helpers.createGenerator('commander:command', [ 85 | '../../command' 86 | ], ['mycmd']); 87 | 88 | var expected = [ 89 | 'cmds/mycmd.js' 90 | ]; 91 | 92 | helpers.mockPrompt(this.app, { 93 | 'name': 'mycmd', 94 | 'version': '0.0.0' 95 | }); 96 | 97 | this.app.run({}, function () { 98 | helpers.assertFiles(expected); 99 | done(); 100 | }); 101 | }); 102 | 103 | it('commander:component creates expected files', function (done) { 104 | this.app = helpers.createGenerator('commander:component', [ 105 | '../../component' 106 | ], ['mycomp']); 107 | 108 | var expected = [ 109 | 'lib/mycomp.js' 110 | ]; 111 | 112 | helpers.mockPrompt(this.app, { 113 | 'name': 'mycomp' 114 | }); 115 | 116 | this.app.run({}, function () { 117 | helpers.assertFiles(expected); 118 | done(); 119 | }); 120 | }); 121 | }); 122 | -------------------------------------------------------------------------------- /test/test-load.js: -------------------------------------------------------------------------------- 1 | /* global describe, it*/ 2 | 'use strict'; 3 | 4 | var assert = require('assert'); 5 | 6 | describe('commander generator', function () { 7 | it('can be imported without blowing up', function () { 8 | var app = require('../app'); 9 | assert(app !== undefined); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /todo.md: -------------------------------------------------------------------------------- 1 | # Todo list for [generator-commander](https://github.com/Hypercubed/generator-commander) 2 | 3 | _(managed using [todo-md](https://github.com/Hypercubed/todo-md))_ 4 | 5 | - [ ] Add LICENSE to template 6 | - [ ] Support coffee based projects? 7 | - [x] Add bugs and repo url to package 8 | - [ ] Integrate autocmdr 9 | - [ ] Check should return error on unknown command error 10 | - [ ] check --version should run without errors error 11 | --------------------------------------------------------------------------------