Skip to content

Commit 2bd7353

Browse files
Initial commit.
0 parents  commit 2bd7353

17 files changed

+342
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.jshintrc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"node": true,
3+
"esnext": true,
4+
"bitwise": true,
5+
"camelcase": true,
6+
"curly": true,
7+
"eqeqeq": true,
8+
"immed": true,
9+
"indent": 2,
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+
}

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'
4+
before_install:
5+
- currentfolder=${PWD##*/}
6+
- if [ "$currentfolder" != 'generator-yargs' ]; then cd .. && eval "mv $currentfolder generator-yargs" && cd generator-yargs; fi
7+

.yo-rc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"generator-generator": {}
3+
}

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2014 undefined
2+
3+
This software is released under the MIT license:
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
13+
all 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
21+
THE SOFTWARE.

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# generator-yargs [![Build Status](https://secure.travis-ci.org/rahatarmanahmed/generator-yargs.png?branch=master)](https://travis-ci.org/rahatarmanahmed/generator-yargs)
2+
3+
A [Yeoman](http://yeoman.io) generator that generates a simple scaffold for node scripts meant to be used as global commands. Supports CoffeeScript, too!
4+
5+
6+
## Getting Started
7+
8+
### What is Yeoman?
9+
10+
Trick question. It's not a thing. It's this guy:
11+
12+
![](http://i.imgur.com/JHaAlBJ.png)
13+
14+
Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create.
15+
16+
Not every new computer comes with a Yeoman pre-installed. He lives in the [npm](https://npmjs.org) package repository. You only have to ask for him once, then he packs up and moves into your hard drive. *Make sure you clean up, he likes new and shiny things.*
17+
18+
```bash
19+
npm install -g yo
20+
```
21+
22+
### Yeoman Generators
23+
24+
Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension.
25+
26+
To install generator-yargs from npm, run:
27+
28+
```bash
29+
npm install -g generator-yargs
30+
```
31+
32+
Finally, initiate the generator:
33+
34+
```bash
35+
yo yargs
36+
```
37+
38+
### CoffeeScript
39+
40+
This generator will generate a simple CoffeeScript project with a simple Gruntfile to compile with. Either initiate the generator with `yo yargs --coffee` or just answer the question in the generator wizard.
41+
42+
To build your coffee files, run `grunt build` or just `grunt`.
43+
44+
### Getting To Know Yeoman
45+
46+
Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced.
47+
48+
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).
49+
50+
51+
## License
52+
53+
MIT

app/index.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
var util = require('util');
3+
var path = require('path');
4+
var yeoman = require('yeoman-generator');
5+
var yosay = require('yosay');
6+
7+
var YargsGenerator = yeoman.generators.Base.extend({
8+
9+
constructor: function() {
10+
yeoman.generators.Base.apply(this, arguments);
11+
this.option("coffee", {
12+
desc: "Generate a project for CoffeeScript",
13+
type: "boolean",
14+
default: false
15+
});
16+
},
17+
18+
initializing: function () {
19+
this.pkg = require('../package.json');
20+
21+
},
22+
23+
prompting: function () {
24+
var done = this.async();
25+
26+
this.useCoffee = !!this.options['coffee'];
27+
28+
// Have Yeoman greet the user.
29+
this.log(yosay(
30+
'Welcome to the great Yargs command generator!'
31+
));
32+
33+
var prompts = [
34+
{
35+
type: 'input',
36+
name: 'author',
37+
message: 'Who is the author?',
38+
default: "Linus Torvalds"
39+
},
40+
{
41+
type: 'input',
42+
name: 'commandName',
43+
message: 'What should your command be called?',
44+
default: "rm-rf-slash"
45+
},
46+
{
47+
type: 'input',
48+
name: 'description',
49+
message: 'Describe what your command does.',
50+
default: "Formats your hard drive."
51+
}
52+
];
53+
54+
if(!this.useCoffee)
55+
prompts.push({
56+
type: 'confirm',
57+
name: 'useCoffee',
58+
message: "Would you like to use CoffeeScript?",
59+
default: false
60+
})
61+
62+
this.prompt(prompts, function (props) {
63+
for(var key in props){
64+
this[key] = props[key];
65+
}
66+
done();
67+
}.bind(this));
68+
},
69+
70+
writing: {
71+
app: function () {
72+
this.template('_package.json', 'package.json');
73+
this.template('.gitignore', '.gitignore');
74+
this.template('.npmignore', '.npmignore');
75+
this.dest.mkdir('src');
76+
77+
if(this.useCoffee)
78+
{
79+
this.src.copy('Gruntfile.coffee', 'Gruntfile.coffee')
80+
this.src.copy('src/index.coffee', 'src/index.coffee');
81+
}
82+
else
83+
{
84+
this.src.copy('src/index.js', 'src/index.js');
85+
}
86+
},
87+
88+
},
89+
90+
end: function () {
91+
this.installDependencies();
92+
}
93+
});
94+
95+
module.exports = YargsGenerator;

app/templates/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
bin

app/templates/.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src

app/templates/Gruntfile.coffee

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = (grunt) ->
2+
3+
grunt.task.loadNpmTasks 'grunt-contrib-coffee'
4+
5+
grunt.initConfig
6+
pkg:
7+
grunt.file.readJSON('package.json')
8+
9+
coffee:
10+
compile:
11+
expand: true
12+
flatten: true
13+
cwd: "src/"
14+
src: ['**/*.coffee']
15+
dest: 'bin/'
16+
ext: '.js'
17+
18+
19+
grunt.registerTask 'build', ['coffee']
20+
grunt.registerTask 'default', ['build']

app/templates/_package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "<%= commandName %>",
3+
"main": "<%= useCoffee ? 'src/index.coffee' : 'src/index.js' %>",
4+
"version": "0.0.0",
5+
"description": "<%= description %>",
6+
"author": "<%= author %>",
7+
"preferGlobal": "true",
8+
"bin": {
9+
"<%= commandName %>": "<%= useCoffee ? './bin/index.js' : './src/index.js' %>"
10+
},
11+
"dependencies": {
12+
"yargs": "1.3.2"
13+
},
14+
"devDependencies": {
15+
"grunt": "*",
16+
"grunt-contrib-coffee": "*"
17+
}
18+
}

app/templates/src/index.coffee

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
argv = (require 'yargs')
3+
.alias 's', 'safe'
4+
.argv
5+
6+
if argv.safe
7+
message = 'In safe mode, instead of formatting your hard drive, we save one puppy from the shelter.'
8+
else
9+
message = 'Formatting hard drive... done.'
10+
11+
console.log message

app/templates/src/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env node
2+
var argv = require('yargs')
3+
.alias('s', 'safe')
4+
.argv;
5+
6+
var message;
7+
if(argv.safe)
8+
message = 'In safe mode, instead of formatting your hard drive, we save one puppy from the shelter.';
9+
else
10+
message = 'Formatting hard drive... done.';
11+
12+
console.log(message);

package.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "generator-yargs",
3+
"version": "0.0.0",
4+
"description": "Yeoman generator",
5+
"license": "MIT",
6+
"main": "app/index.js",
7+
"repository": "rahatarmanahmed/generator-yargs",
8+
"author": {
9+
"name": "Rahat Ahmed",
10+
"email": "[email protected]",
11+
"url": "https://github.com/rahatarmanahmed"
12+
},
13+
"engines": {
14+
"node": ">=0.10.0"
15+
},
16+
"scripts": {
17+
"test": "mocha"
18+
},
19+
"files": [
20+
"app"
21+
],
22+
"keywords": [
23+
"yeoman-generator"
24+
],
25+
"dependencies": {
26+
"yeoman-generator": "^0.17.0",
27+
"chalk": "^0.5.0",
28+
"yosay": "^0.3.0"
29+
},
30+
"devDependencies": {
31+
"mocha": "*"
32+
},
33+
"peerDependencies": {
34+
"yo": ">=1.0.0"
35+
}
36+
}

test/test-app.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*global describe, beforeEach, it*/
2+
'use strict';
3+
4+
var path = require('path');
5+
var assert = require('yeoman-generator').assert;
6+
var helpers = require('yeoman-generator').test;
7+
var os = require('os');
8+
9+
describe('yargs:app', function () {
10+
before(function (done) {
11+
helpers.run(path.join(__dirname, '../app'))
12+
.inDir(path.join(os.tmpdir(), './temp-test'))
13+
.withOptions({ 'skip-install': true })
14+
.withPrompt({
15+
someOption: true
16+
})
17+
.on('end', done);
18+
});
19+
20+
it('creates files', function () {
21+
assert.file([
22+
'bower.json',
23+
'package.json',
24+
'.editorconfig',
25+
'.jshintrc'
26+
]);
27+
});
28+
});

0 commit comments

Comments
 (0)