Skip to content

Commit

Permalink
rewrite the generator
Browse files Browse the repository at this point in the history
to be simpler and fix a lot of trailing whitespace, bugs, bad output and other inconsistencies.
  • Loading branch information
sindresorhus committed Dec 7, 2014
1 parent fd76965 commit 6adf1f4
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 251 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# http://editorconfig.org
root = true

[*]
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
npm-debug.log
node_modules/
temp/
node_modules
temp
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013
Copyright 2014

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
# Node Generator [![Build Status](https://secure.travis-ci.org/yeoman/generator-node.svg?branch=master)](https://travis-ci.org/yeoman/generator-node)

> Create a node.js module with [Yeoman](http://yeoman.io), including mocha unit tests.
> Create a Node.js module
This generator is based of
[grunt-init-node](https://github.com/gruntjs/grunt-init-node), authored by the
magnificient GruntJS team.
Maintained by [Hemanth.HM](http://github.com/hemanth).

Maintained by [Hemanth.HM](http://github.com/hemanth)

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


## Installation

Install the generator by running: `npm install -g generator-node`.
```sh
$ npm install --global generator-node
```


## Usage

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

```
yo node
```sh
$ 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._
*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)
MIT © Yeoman team
40 changes: 17 additions & 23 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var path = require('path');
var npmName = require('npm-name');
var yeoman = require('yeoman-generator');
Expand All @@ -10,7 +9,7 @@ module.exports = yeoman.generators.Base.extend({
this.log(
this.yeoman +
'\nThe name of your project shouldn\'t contain "node" or "js" and' +
'\nshould be a unique ID not already in use at search.npmjs.org.');
'\nshould be a unique ID not already in use at npmjs.org.');
},
askForModuleName: function () {
var done = this.async();
Expand All @@ -30,6 +29,7 @@ module.exports = yeoman.generators.Base.extend({
npmName(answers.name, function (err, available) {
if (!available) {
done(true);
return;
}

done(false);
Expand All @@ -43,10 +43,9 @@ module.exports = yeoman.generators.Base.extend({
}

this.slugname = this._.slugify(props.name);
this.safeSlugname = this.slugname.replace(
/-+([a-zA-Z0-9])/g,
function (g) { return g[1].toUpperCase(); }
);
this.safeSlugname = this.slugname.replace(/-+([a-zA-Z0-9])/g, function (g) {
return g[1].toUpperCase();
});

done();
}.bind(this));
Expand Down Expand Up @@ -84,27 +83,25 @@ module.exports = yeoman.generators.Base.extend({
}, {
type: 'confirm',
name: 'cli',
message: 'Do you need cli tools?'
message: 'Do you need a CLI?'
}, {
type: 'confirm',
name: 'browser',
message: 'Do you need browserify?'
message: 'Do you need Browserify?'
}];

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

this.prompt(prompts, function (props) {
if(props.githubUsername){
this.repoUrl = 'https://github.com/' + props.githubUsername + '/' + this.slugname;
if (props.githubUsername) {
this.repoUrl = props.githubUsername + '/' + this.slugname;
} else {
this.repoUrl = 'user/repo';
}

if (!props.homepage) {
props.homepage = this.repoUrl;
}

this.keywords = props.keywords.split(',');
this.keywords = props.keywords.split(',').map(function (el) {
return el.trim();
})

this.props = props;

Expand All @@ -119,22 +116,19 @@ module.exports = yeoman.generators.Base.extend({
this.copy('gitignore', '.gitignore');
this.copy('travis.yml', '.travis.yml');

this.template('_README.md', 'README.md');
this.template('_Gruntfile.js', 'Gruntfile.js');
this.template('README.md', 'README.md');
this.template('Gruntfile.js', 'Gruntfile.js');
this.template('_package.json', 'package.json');

if (this.props.cli) {
this.template('_cli.js', 'cli.js');
this.template('cli.js', 'cli.js');
}
},

projectfiles: function () {
this.mkdir('lib');
this.template('lib/name.js', 'lib/' + this.slugname + '.js');
this.template('index.js', 'index.js');
this.mkdir('test');
this.template('test/name_test.js', 'test/' + this.slugname + '_test.js');
this.mkdir('example');
this.template('example/name_example.js', 'example/' + this.slugname + '_example.js');
this.template('test/test.js', 'test/test.js');
},

install: function () {
Expand Down
45 changes: 45 additions & 0 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
module.exports = function (grunt) {
// Show elapsed time at the end
require('time-grunt')(grunt);
// Load all grunt tasks
require('load-grunt-tasks')(grunt);

grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
js: {
src: ['*.js']
},
test: {
src: ['test/**/*.js']
}
},
mochacli: {
options: {
reporter: 'nyan',
bail: true
},
all: ['test/*.js']
},
watch: {
gruntfile: {
files: '<%%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
lib: {
files: '<%%= jshint.lib.src %>',
tasks: ['jshint:lib', 'mochacli']
},
test: {
files: '<%%= jshint.test.src %>',
tasks: ['jshint:test', 'mochacli']
}
}
});

grunt.registerTask('default', ['jshint', 'mochacli']);
};
34 changes: 34 additions & 0 deletions app/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# <%= props.slugname %> [![Build Status](https://secure.travis-ci.org/<%= props.githubUsername %>/<%= slugname %>.png?branch=master)](http://travis-ci.org/<%= props.githubUsername %>/<%= slugname %>)

> <%= props.description %>

## Install

```sh
$ npm install --save <%= slugname %>
```


## Usage

```js
var <%= slugname %> = require('<%= slugname %>');

<%= slugname %>('Rainbow');
```<% if (props.cli) { %>
```sh
$ npm install --global <%= slugname %>
$ <%= slugname %> --help
```<% } %><% if (props.browser) { %>
```sh
# creates a browser.js
$ npm run browser
```<% } %>
## License
MIT © [<%= props.authorName %>](<%= props.authorUrl %>)
54 changes: 0 additions & 54 deletions app/templates/_Gruntfile.js

This file was deleted.

49 changes: 0 additions & 49 deletions app/templates/_README.md

This file was deleted.

Loading

0 comments on commit 6adf1f4

Please sign in to comment.