Skip to content

Commit

Permalink
Copy over grunt-init-node basic template
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed May 16, 2013
1 parent 08ce872 commit 6b428b1
Show file tree
Hide file tree
Showing 19 changed files with 519 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
temp/
22 changes: 22 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"node": true,
"es5": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"white": true
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- '0.10'
- '0.8'
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2013

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
generator-node
==============
# Node Generator [![Build Status](https://secure.travis-ci.org/yeoman/generator-node.png?branch=master)](https://travis-ci.org/yeoman/generator-node)

Create a Node.js module with yo, including Nodeunit unit tests.
> Create a node.js module with [Yeoman][], including nodeunit unit tests.
This generator is based of
[grunt-init-node](https://github.com/gruntjs/grunt-init-node), authored by the
magnificient GruntJS team.

Maintained by [Pascal Hartig](https://github.com/passy).

[Yeoman]: http://yeoman.io/


## Installation

If you haven't already done so, install [Yeoman][].

Once Yeoman is installed, install this generator via `npm install -g generator-node`.


## Usage

At the command-line, cd into an empty directory, run this command and follow the prompts.

```
yo node
```

_Note that this template will generate files in the current directory, so be sure to change to a new directory first if you don't want to overwrite existing files._


## License

[MIT License](http://en.wikipedia.org/wiki/MIT_License)
146 changes: 146 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
'use strict';

var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');

var NodeGenerator = module.exports = function NodeGenerator(args, options) {
yeoman.generators.Base.apply(this, arguments);

this.on('end', function () {
this.installDependencies({
bower: false,
skipInstall: options['skip-install']
});
});

this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
};
util.inherits(NodeGenerator, yeoman.generators.NamedBase);

NodeGenerator.prototype.askFor = function askFor() {
var cb = this.async();

// welcome message
var welcome =
'\n _-----_' +
'\n | |' +
'\n |' + '--(o)--'.red + '| .--------------------------.' +
'\n `---------´ | ' + 'Welcome to Yeoman,'.yellow.bold + ' |' +
'\n ' + '( '.yellow + '_' + '´U`'.yellow + '_' + ' )'.yellow + ' | ' + 'ladies and gentlemen!'.yellow.bold + ' |' +
'\n /___A___\\ \'__________________________\'' +
'\n | ~ |'.yellow +
'\n __' + '\'.___.\''.yellow + '__' +
'\n ´ ' + '` |'.red + '° ' + '´ Y'.red + ' `\n' +
'\n' +
'_Project name_ shouldn\'t contain "node" or "js" and should ' +
'be a unique ID not already in use at search.npmjs.org.' +
'\n\n' +
'You should now install project dependencies with _npm ' +
'install_. After that, you may execute project tasks with _grunt_. For ' +
'more information about installing and configuring Grunt, please see ' +
'the Getting Started guide:' +
'\n\n' +
'http://gruntjs.com/getting-started';

console.log(welcome);

var prompts = [{
name: 'name',
message: 'Project Name:',
// TODO: default to folder name
}, {
name: 'description',
default: 'The best project ever.'
}, {
name: 'version',
default: '0.1.0'
}, {
name: 'repository',
message: 'Project git repository'
// TODO: Default to git://github.com/[username]/[projectname].git
}, {
name: 'homepage',
message: 'Project homepage'
// TODO: Default to https://github.com/[username]/[projectname]
}, {
name: 'bugs',
message: 'Project issues tracker'
// TODO: Default to https://github.com/[username]/[projectname]/issues
}, {
name: 'license',
default: 'MIT'
}, {
name: 'author_name',
// TODO: Default to Name
}, {
name: 'author_email',
// TODO: Default to Email
}, {
name: 'author_url',
// TODO: Default to homepage
}, {
name: 'node_version',
message: 'What versions of node does it run on?',
default: '>= 0.10.0'
}, {
name: 'main',
message: 'Main module entry point:',
default: 'lib/',
// TODO: default to project name
}, {
name: 'npm_test',
message: 'npm test command:',
default: 'grunt nodeunit',
}, {
name: 'travis',
message: 'Will this project be tested with Travis CI?'
}];

var nameToMessage = function (name) {
return name.split('_').map(
function (x) { return this._.capitalize(x); }.bind(this)
).join(' ') + ':';
}.bind(this);

// Generate prompt messages if only the name is defined.
prompts.map(function (entry) {
if (entry.message === undefined) {
entry.message = nameToMessage(entry.name);
}
return entry;
});

this.currentYear = (new Date()).getFullYear();

this.prompt(prompts, function (err, props) {
if (err) {
return this.emit('error', err);
}

this.props = props;
// For easier access in the templates.
this.slugname = this._.slugify(props.name);
cb();
}.bind(this));
};

NodeGenerator.prototype.lib = function lib() {
this.mkdir('lib');
this.template('lib/name.js', 'lib/' + this.slugname + '.js');
};

NodeGenerator.prototype.test = function test() {
this.mkdir('test');
this.template('test/name_test.js', 'test/' + this.slugname + '_test.js');
};

NodeGenerator.prototype.projectfiles = function projectfiles() {
this.copy('jshintrc', '.jshintrc');
this.copy('gitignore', '.gitignore');
this.copy('travis.yml', '.travis.yml');

this.template('README.md');
this.template('Gruntfile.js');
this.template('_package.json', 'package.json');
};
48 changes: 48 additions & 0 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
nodeunit: {
files: ['test/**/*_test.js'],
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
gruntfile: {
src: 'Gruntfile.js'
},
lib: {
src: ['lib/**/*.js']
},
test: {
src: ['test/**/*.js']
},
},
watch: {
gruntfile: {
files: '<%%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
lib: {
files: '<%%= jshint.lib.src %>',
tasks: ['jshint:lib', 'nodeunit']
},
test: {
files: '<%%= jshint.test.src %>',
tasks: ['jshint:test', 'nodeunit']
},
},
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');

// Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']);

};
31 changes: 31 additions & 0 deletions app/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# <%= props.title || props.name %>

<%= props.description %>

## Getting Started

Download the [production version][min] or the [development version][max].

[min]: https://raw.github.com/<%= props.github_username %>/jquery-<%= slugname %>/master/dist/jquery.<%= slugname %>.min.js
[max]: https://raw.github.com/<%= props.github_username %>/jquery-<%= slugname %>/master/dist/jquery.<%= slugname %>.js

In your web page:

```html
<script src="jquery.js"></script>
<script src="dist/<%= slugname %>.min.js"></script>
<script>
jQuery(function($) {
$.awesome(); // "awesome"
});
</script>
```

## Documentation
_(Coming soon)_

## Examples
_(Coming soon)_

## Release History
_(Nothing yet)_
33 changes: 33 additions & 0 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "<%= slugname %>",
"version": "<%= props.version %>",
"description": "<%= props.title %>",
"keywords": [
],
"homepage": "https://github.com/<%= props.github_username %>/<%= slugname %>",
<% if (props.bugs) { %>
"bugs": "<%= props.bugs %>",
<% } %>
"author": {
"name": "<%= props.author_name %>",
"email": "<%= props.author_email %>",
"url": "https://github.com/<%= props.github_username %>"
},
"repository": {
"type": "git",
"url": "https://github.com/<%= props.github_username %>/<%= slugname %>.git"
},
"licenses": [
{
"type": "<%= props.license %>"
}
],
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-qunit": "~0.1.1",
"grunt-contrib-concat": "~0.1.2",
"grunt-contrib-uglify": "~0.1.1",
"grunt-contrib-watch": "~0.2.0",
"grunt-contrib-clean": "~0.4.0"
}
}
1 change: 1 addition & 0 deletions app/templates/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
15 changes: 15 additions & 0 deletions app/templates/jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"unused": true,
"boss": true,
"eqnull": true,
"node": true,
"es5": true
}
13 changes: 13 additions & 0 deletions app/templates/lib/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* <%= props.name %>
* <%= props.homepage %>
*
* Copyright (c) <%= currentYear %> <%= props.author_name %>
* Licensed under the <%= props.license %> license.
*/

'use strict';

exports.awesome = function() {
return 'awesome';
};
Loading

0 comments on commit 6b428b1

Please sign in to comment.