Skip to content

Commit

Permalink
use meow for the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 7, 2014
1 parent d194a30 commit fd76965
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
24 changes: 12 additions & 12 deletions app/templates/_cli.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#! /usr/bin/env node

#!/usr/bin/env node
'use strict';

var meow = require('meow');
var <%= safeSlugname %> = require('./lib/<%= slugname %>');

var userArgs = process.argv;
var searchParam = userArgs[2];

if (userArgs.indexOf('-h') !== -1 || userArgs.indexOf('--help') !== -1 || searchParam === undefined) {
return console.log('cli help');
}
var cli = meow({
help: [
'Usage',
' <%= slugname %> <input>',
'',
'Example',
' <%= slugname %> Unicorn'
].join('\n')
});

if (userArgs.indexOf('-v') !== -1 || userArgs.indexOf('--version') !== -1) {
return console.log(require('./package').version);
}
<%= safeSlugname %>(cli.input[0]);
3 changes: 3 additions & 0 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"<%= keywords[i] %>" <%
} %>
],
"dependencies": {<% if (props.cli) { %>
"meow": "^2.0.0"
<% } %>},
"devDependencies": {
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-nodeunit": "^0.3.3",
Expand Down
4 changes: 2 additions & 2 deletions app/templates/lib/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

'use strict';

exports.awesome = function() {
return 'awesome';
module.exports = function (str) {
console.log(str || 'Rainbow');
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
"url": "https://github.com/yeoman/generator-node.git"
},
"scripts": {
"test": "mocha --timeout 3500"
"test": "mocha --timeout 50000"
},
"dependencies": {
"npm-name": "~0.1.0",
"yeoman-generator": "~0.17.3"
},
"devDependencies": {
"grunt": "~0.4.5",
"mocha": "*",
"grunt": "~0.4.5"
"shelljs": "^0.3.0"
},
"peerDependencies": {
"yo": ">=1.0.3"
Expand Down
3 changes: 3 additions & 0 deletions test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var path = require('path');
var assert = require('yeoman-generator').assert;
var helpers = require('yeoman-generator').test;
var shelljs = require('shelljs');

describe('node generator', function () {
beforeEach(function (done) {
Expand Down Expand Up @@ -49,6 +50,8 @@ describe('node generator', function () {
'browser': true
});

shelljs.exec('npm install meow', {silent: true});

this.app.run({}, function () {
assert.file(expected);
assert.fileContent('package.json', /"name": "mymodule"/);
Expand Down

0 comments on commit fd76965

Please sign in to comment.