diff --git a/.editorconfig b/.editorconfig index e717f5e..4a7ea30 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,3 @@ -# http://editorconfig.org root = true [*] diff --git a/.gitignore b/.gitignore index 05bef3b..de0dbbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ npm-debug.log -node_modules/ -temp/ +node_modules +temp diff --git a/LICENSE b/LICENSE index 281e7fd..35bffb8 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 9020f90..d1120c6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/index.js b/app/index.js index 7c9c142..3cf04d3 100644 --- a/app/index.js +++ b/app/index.js @@ -1,5 +1,4 @@ 'use strict'; - var path = require('path'); var npmName = require('npm-name'); var yeoman = require('yeoman-generator'); @@ -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(); @@ -30,6 +29,7 @@ module.exports = yeoman.generators.Base.extend({ npmName(answers.name, function (err, available) { if (!available) { done(true); + return; } done(false); @@ -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)); @@ -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; @@ -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 () { diff --git a/app/templates/Gruntfile.js b/app/templates/Gruntfile.js new file mode 100644 index 0000000..a48c045 --- /dev/null +++ b/app/templates/Gruntfile.js @@ -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']); +}; diff --git a/app/templates/README.md b/app/templates/README.md new file mode 100644 index 0000000..02d2ee7 --- /dev/null +++ b/app/templates/README.md @@ -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 %>) diff --git a/app/templates/_Gruntfile.js b/app/templates/_Gruntfile.js deleted file mode 100644 index 408b83d..0000000 --- a/app/templates/_Gruntfile.js +++ /dev/null @@ -1,54 +0,0 @@ -'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); - - // Project configuration. - grunt.initConfig({ - nodeunit: { - files: ['test/**/*_test.js'] - }, - jshint: { - options: { - jshintrc: '.jshintrc', - reporter: require('jshint-stylish') - }, - gruntfile: { - src: 'Gruntfile.js' - }, - lib: { - src: ['lib/**/*.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'] - } - } - }); - - // Default task. - grunt.registerTask('default', ['jshint', 'mochacli']); -}; diff --git a/app/templates/_README.md b/app/templates/_README.md deleted file mode 100644 index f97f23c..0000000 --- a/app/templates/_README.md +++ /dev/null @@ -1,49 +0,0 @@ -# <%= props.name %> [![Build Status](https://secure.travis-ci.org/<%= props.githubUsername %>/<%= slugname %>.png?branch=master)](http://travis-ci.org/<%= props.githubUsername %>/<%= slugname %>) - -> <%= props.description %> - - -## Getting Started - -Install the module with: `npm install <%= slugname %>` - -```js -var <%= slugname %> = require('<%= slugname %>'); -<%= slugname %>.awesome(); // "awesome" -```<% if (props.cli) { %> - -Install with cli command - -```sh -$ npm install -g <%= slugname %> -$ <%= slugname %> --help -$ <%= slugname %> --version -```<% } %> - -<% if (props.browser) { %> -```sh -# creates a browser.js -$ npm run browser -``` -<%}%> - - -## Documentation - -_(Coming soon)_ - - -## Examples - -_(Coming soon)_ - - -## Contributing - -In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com). - - -## License - -Copyright (c) <%= currentYear %> <%= props.authorName %> -Licensed under the <%= props.license %> license. diff --git a/app/templates/_package.json b/app/templates/_package.json index eb8fdef..9dbcde4 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -1,61 +1,42 @@ { "name": "<%= slugname %>", "version": "0.0.0", - "main": "lib/<%= slugname %>.js", "description": "<%= props.description %>", - <% - if (props.homepage) { %> - "homepage": "<%= props.homepage %>", - <% - } %> - "bugs": "<%= repoUrl %>/issues", +<% if (props.homepage) { %> "homepage": "<%= props.homepage %>",<% } %> "author": { "name": "<%= props.authorName %>", - "email": "<%= props.authorEmail %>" <% - if (props.authorUrl) { %> , - "url": "<%= props.authorUrl %>" <% - } %> - }, - "repository": { - "type": "git", - "url": "<%= repoUrl %>" + "email": "<%= props.authorEmail %>"<% if (props.authorUrl) { %>, + "url": "<%= props.authorUrl %>"<% } %> }, + "repository": "<%= repoUrl %>", "license": "<%= props.license %>", "files": [ - "lib"<% if (props.cli) { %>, + "index.js"<% if (props.cli) { %>, "cli.js"<% } %> ], "keywords": [ - "<%= slugname %>" <% - for (var i = 0; i < keywords.length; i++) { %> , - "<%= keywords[i] %>" <% - } %> + "<%= slugname %>"<% for (var i = 0; i < keywords.length; i++) { %>, + "<%= keywords[i] %>"<% } %> ], "dependencies": {<% if (props.cli) { %> "meow": "^2.0.0" <% } %>}, "devDependencies": { + "grunt-cli": "^0.1.13", "grunt-contrib-jshint": "^0.10.0", - "grunt-contrib-nodeunit": "^0.3.3", + "grunt-contrib-nodeunit": "^0.4.1", "grunt-contrib-watch": "^0.6.1", - "load-grunt-tasks": "^0.4.0", - "time-grunt": "^0.3.1", - "grunt-mocha-cli": "^1.9.0", - "jshint-stylish": "^0.2.0" <% - if (props.browser) { %> , - "browserify": "^4.1.3" <% - } %> + "load-grunt-tasks": "^1.0.0", + "time-grunt": "^1.0.0", + "grunt-mocha-cli": "^1.11.0", + "jshint-stylish": "^1.0.0"<% if (props.browser) { %>, + "browserify": "^7.0.0"<% } %> }, "scripts": { - "test": "grunt" <% - if (props.browser) { %> , - "browser": "browserify lib/<%= slugname %>.js > browser.js" <% - } %> - } <% - if (props.cli) { %> , - "bin": { - "<%= slugname %>": "cli.js" - }, - "preferGlobal": "true" <% - } %> + "test": "grunt"<% if (props.browser) { %>, + "browser": "browserify index.js > browser.js"<% } %> + }<% if (props.cli) { %>, + "bin": { + "<%= slugname %>": "cli.js" + }<% } %> } diff --git a/app/templates/_cli.js b/app/templates/cli.js similarity index 81% rename from app/templates/_cli.js rename to app/templates/cli.js index ed91495..e1405b0 100644 --- a/app/templates/_cli.js +++ b/app/templates/cli.js @@ -1,7 +1,7 @@ #!/usr/bin/env node 'use strict'; var meow = require('meow'); -var <%= safeSlugname %> = require('./lib/<%= slugname %>'); +var <%= safeSlugname %> = require('./'); var cli = meow({ help: [ diff --git a/app/templates/example/name_example.js b/app/templates/example/name_example.js deleted file mode 100644 index 43bebae..0000000 --- a/app/templates/example/name_example.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -var <%= safeSlugname %> = require('../lib/<%= slugname %>.js'); - -<%= safeSlugname %>.awesome(); -// => awesome \ No newline at end of file diff --git a/app/templates/index.js b/app/templates/index.js new file mode 100644 index 0000000..ca2d41e --- /dev/null +++ b/app/templates/index.js @@ -0,0 +1,4 @@ +'use strict'; +module.exports = function (str) { + console.log(str || 'Rainbow'); +}; diff --git a/app/templates/lib/name.js b/app/templates/lib/name.js deleted file mode 100644 index fc158ca..0000000 --- a/app/templates/lib/name.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * <%= props.name %> - * <%= props.homepage %> - * - * Copyright (c) <%= currentYear %> <%= props.authorName %> - * Licensed under the <%= props.license %> license. - */ - -'use strict'; - -module.exports = function (str) { - console.log(str || 'Rainbow'); -}; diff --git a/app/templates/test/name_test.js b/app/templates/test/name_test.js deleted file mode 100644 index a0264d3..0000000 --- a/app/templates/test/name_test.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global describe,it*/ -'use strict'; -var assert = require('assert'), - <%= safeSlugname %> = require('../lib/<%= slugname %>.js'); - -describe('<%= slugname %> node module', function() { - it('must be awesome', function() { - assert.equal( <%= safeSlugname %>.awesome(), 'awesome'); - }); -}); - -describe('<%= slugname %> node module', function() { - it('must have at least one test', function() { - assert(false, 'I was too lazy to write any tests. Shame on me.'); - }); -}); diff --git a/app/templates/test/test.js b/app/templates/test/test.js new file mode 100644 index 0000000..d59eda6 --- /dev/null +++ b/app/templates/test/test.js @@ -0,0 +1,11 @@ +/*global describe, it */ +'use strict'; +var assert = require('assert'); +var <%= safeSlugname %> = require('../'); + +describe('<%= slugname %> node module', function () { + it('must have at least one test', function () { + <%= safeSlugname %>(); + assert(false, 'I was too lazy to write any tests. Shame on me.'); + }); +}); diff --git a/app/templates/travis.yml b/app/templates/travis.yml index 9da632c..244b7e8 100644 --- a/app/templates/travis.yml +++ b/app/templates/travis.yml @@ -1,6 +1,3 @@ language: node_js node_js: - '0.10' - - '0.8' -before_script: - - npm install -g grunt-cli diff --git a/package.json b/package.json index ee3a847..9b0b6d5 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,31 @@ { "name": "generator-node", "version": "0.4.4", - "description": "A node generator for Yeoman", + "description": "Create a Node.js module", "keywords": [ "yeoman-generator", "scaffold", - "node" + "node", + "module", + "cli" ], - "homepage": "https://github.com/yeoman/generator-node", - "bugs": "https://github.com/yeoman/generator-node/issues", - "author": "The Yeoman Team", - "main": "app/index.js", - "repository": { - "type": "git", - "url": "https://github.com/yeoman/generator-node.git" - }, + "author": "Yeoman team", + "main": "app", + "repository": "yeoman/generator-node", "scripts": { "test": "mocha --timeout 50000" }, "dependencies": { - "npm-name": "~0.1.0", - "yeoman-generator": "~0.17.3" + "npm-name": "^1.0.2", + "yeoman-generator": "^0.18.3" }, "devDependencies": { - "grunt": "~0.4.5", + "grunt": "^0.4.5", "mocha": "*", "shelljs": "^0.3.0" }, - "peerDependencies": { - "yo": ">=1.0.3" - }, "engines": { - "node": ">= 0.10.0", + "node": ">=0.10.0", "npm": ">=1.2.10" }, "files": [ diff --git a/test/test-creation.js b/test/test-creation.js index ce84aed..f6a79ea 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -1,6 +1,5 @@ -/*global describe, beforeEach, it*/ +/*global describe, beforeEach, it */ 'use strict'; - var path = require('path'); var assert = require('yeoman-generator').assert; var helpers = require('yeoman-generator').test; @@ -10,7 +9,8 @@ describe('node generator', function () { beforeEach(function (done) { helpers.testDirectory(path.join(__dirname, 'temp'), function (err) { if (err) { - return done(err); + done(err); + return; } this.app = helpers.createGenerator('node:app', [ @@ -23,10 +23,9 @@ describe('node generator', function () { it('creates expected files', function (done) { var expected = [ - 'lib/mymodule.js', - 'test/mymodule_test.js', - 'example/mymodule_example.js', + 'index.js', 'cli.js', + 'test/test.js', '.gitignore', '.jshintrc', '.travis.yml', @@ -63,9 +62,8 @@ describe('node generator', function () { it('creates expected files without cli', function (done) { var expected = [ - 'lib/mymodule.js', - 'test/mymodule_test.js', - 'example/mymodule_example.js', + 'index.js', + 'test/test.js', '.gitignore', '.jshintrc', '.travis.yml', diff --git a/test/test-load.js b/test/test-load.js index 9549863..4333599 100644 --- a/test/test-load.js +++ b/test/test-load.js @@ -1,4 +1,4 @@ -/*global describe, beforeEach, it*/ +/*global describe, beforeEach, it */ 'use strict'; var assert = require('assert');