├── .gitattributes ├── .gitignore ├── .travis.yml ├── app ├── templates │ ├── gitignore │ ├── travis.yml │ ├── index.js │ ├── jshintrc │ ├── cli.js │ ├── test │ │ └── test.js │ ├── README.md │ ├── Gruntfile.js │ └── _package.json └── index.js ├── .editorconfig ├── test ├── test-load.js └── test-creation.js ├── .jshintrc ├── README.md ├── package.json └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | npm-debug.log 2 | node_modules 3 | temp 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | -------------------------------------------------------------------------------- /app/templates/gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /app/templates/travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | -------------------------------------------------------------------------------- /app/templates/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = function (str) { 3 | console.log(str || 'Rainbow'); 4 | }; 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /app/templates/jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": true, 11 | "boss": true, 12 | "eqnull": true, 13 | "node": true 14 | } 15 | -------------------------------------------------------------------------------- /test/test-load.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it */ 2 | 'use strict'; 3 | var assert = require('assert'); 4 | 5 | describe('node generator', function () { 6 | it('can be imported without blowing up', function () { 7 | var app = require('../app'); 8 | assert(app !== undefined); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 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 | "undef": true, 15 | "unused": true, 16 | "strict": true 17 | } 18 | -------------------------------------------------------------------------------- /app/templates/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | var meow = require('meow'); 4 | var <%= safeSlugname %> = require('./'); 5 | 6 | var cli = meow({ 7 | help: [ 8 | 'Usage', 9 | ' <%= slugname %> ', 10 | '', 11 | 'Example', 12 | ' <%= slugname %> Unicorn' 13 | ].join('\n') 14 | }); 15 | 16 | <%= safeSlugname %>(cli.input[0]); 17 | -------------------------------------------------------------------------------- /app/templates/test/test.js: -------------------------------------------------------------------------------- 1 | /*global describe, it */ 2 | 'use strict'; 3 | var assert = require('assert'); 4 | var <%= safeSlugname %> = require('../'); 5 | 6 | describe('<%= slugname %> node module', function () { 7 | it('must have at least one test', function () { 8 | <%= safeSlugname %>(); 9 | assert(false, 'I was too lazy to write any tests. Shame on me.'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node Generator [![Build Status](https://secure.travis-ci.org/yeoman/generator-node.svg?branch=master)](https://travis-ci.org/yeoman/generator-node) 2 | 3 | > Create a Node.js module 4 | 5 | Maintained by [Hemanth.HM](http://github.com/hemanth). 6 | 7 | 8 | ## Install 9 | 10 | ```sh 11 | $ npm install --global generator-node 12 | ``` 13 | 14 | 15 | ## Usage 16 | 17 | ```sh 18 | $ yo node 19 | ``` 20 | 21 | *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.* 22 | 23 | 24 | ## License 25 | 26 | MIT © Yeoman team 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-node", 3 | "version": "0.5.0", 4 | "description": "Create a Node.js module", 5 | "keywords": [ 6 | "yeoman-generator", 7 | "scaffold", 8 | "node", 9 | "module", 10 | "cli" 11 | ], 12 | "author": "Yeoman team", 13 | "main": "app", 14 | "repository": "yeoman/generator-node", 15 | "scripts": { 16 | "test": "mocha --timeout 50000" 17 | }, 18 | "dependencies": { 19 | "npm-name": "^1.0.2", 20 | "yeoman-generator": "^0.18.3" 21 | }, 22 | "devDependencies": { 23 | "grunt": "^0.4.5", 24 | "mocha": "*", 25 | "shelljs": "^0.3.0" 26 | }, 27 | "engines": { 28 | "node": ">=0.10.0", 29 | "npm": ">=1.2.10" 30 | }, 31 | "files": [ 32 | "app" 33 | ], 34 | "license": "MIT" 35 | } 36 | -------------------------------------------------------------------------------- /app/templates/README.md: -------------------------------------------------------------------------------- 1 | # <%= props.slugname %> [![Build Status](https://secure.travis-ci.org/<%= props.githubUsername %>/<%= slugname %>.png?branch=master)](http://travis-ci.org/<%= props.githubUsername %>/<%= slugname %>) 2 | 3 | > <%= props.description %> 4 | 5 | 6 | ## Install 7 | 8 | ```sh 9 | $ npm install --save <%= slugname %> 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | var <%= slugname %> = require('<%= slugname %>'); 17 | 18 | <%= slugname %>('Rainbow'); 19 | ```<% if (props.cli) { %> 20 | 21 | ```sh 22 | $ npm install --global <%= slugname %> 23 | $ <%= slugname %> --help 24 | ```<% } %><% if (props.browser) { %> 25 | 26 | ```sh 27 | # creates a browser.js 28 | $ npm run browser 29 | ```<% } %> 30 | 31 | 32 | ## License 33 | 34 | MIT © [<%= props.authorName %>](<%= props.authorUrl %>) 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /app/templates/Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = function (grunt) { 3 | // Show elapsed time at the end 4 | require('time-grunt')(grunt); 5 | // Load all grunt tasks 6 | require('load-grunt-tasks')(grunt); 7 | 8 | grunt.initConfig({ 9 | jshint: { 10 | options: { 11 | jshintrc: '.jshintrc', 12 | reporter: require('jshint-stylish') 13 | }, 14 | js: { 15 | src: ['*.js'] 16 | }, 17 | test: { 18 | src: ['test/**/*.js'] 19 | } 20 | }, 21 | mochacli: { 22 | options: { 23 | reporter: 'nyan', 24 | bail: true 25 | }, 26 | all: ['test/*.js'] 27 | }, 28 | watch: { 29 | gruntfile: { 30 | files: '<%%= jshint.gruntfile.src %>', 31 | tasks: ['jshint:gruntfile'] 32 | }, 33 | lib: { 34 | files: '<%%= jshint.lib.src %>', 35 | tasks: ['jshint:lib', 'mochacli'] 36 | }, 37 | test: { 38 | files: '<%%= jshint.test.src %>', 39 | tasks: ['jshint:test', 'mochacli'] 40 | } 41 | } 42 | }); 43 | 44 | grunt.registerTask('default', ['jshint', 'mochacli']); 45 | }; 46 | -------------------------------------------------------------------------------- /app/templates/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= slugname %>", 3 | "version": "0.0.0", 4 | "description": "<%= props.description %>", 5 | <% if (props.homepage) { %> "homepage": "<%= props.homepage %>",<% } %> 6 | "author": { 7 | "name": "<%= props.authorName %>", 8 | "email": "<%= props.authorEmail %>"<% if (props.authorUrl) { %>, 9 | "url": "<%= props.authorUrl %>"<% } %> 10 | }, 11 | "repository": "<%= repoUrl %>", 12 | "license": "<%= props.license %>", 13 | "files": [ 14 | "index.js"<% if (props.cli) { %>, 15 | "cli.js"<% } %> 16 | ], 17 | "keywords": [ 18 | "<%= slugname %>"<% for (var i = 0; i < keywords.length; i++) { %>, 19 | "<%= keywords[i] %>"<% } %> 20 | ], 21 | "dependencies": {<% if (props.cli) { %> 22 | "meow": "^2.0.0" 23 | <% } %>}, 24 | "devDependencies": { 25 | "grunt-cli": "^0.1.13", 26 | "grunt-contrib-jshint": "^0.10.0", 27 | "grunt-contrib-nodeunit": "^0.4.1", 28 | "grunt-contrib-watch": "^0.6.1", 29 | "load-grunt-tasks": "^1.0.0", 30 | "time-grunt": "^1.0.0", 31 | "grunt-mocha-cli": "^1.11.0", 32 | "jshint-stylish": "^1.0.0"<% if (props.browser) { %>, 33 | "browserify": "^7.0.0"<% } %> 34 | }, 35 | "scripts": { 36 | "test": "grunt"<% if (props.browser) { %>, 37 | "browser": "browserify index.js > browser.js"<% } %> 38 | }<% if (props.cli) { %>, 39 | "bin": { 40 | "<%= slugname %>": "cli.js" 41 | }<% } %> 42 | } 43 | -------------------------------------------------------------------------------- /test/test-creation.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it */ 2 | 'use strict'; 3 | var path = require('path'); 4 | var assert = require('yeoman-generator').assert; 5 | var helpers = require('yeoman-generator').test; 6 | var shelljs = require('shelljs'); 7 | 8 | describe('node generator', function () { 9 | beforeEach(function (done) { 10 | helpers.testDirectory(path.join(__dirname, 'temp'), function (err) { 11 | if (err) { 12 | done(err); 13 | return; 14 | } 15 | 16 | this.app = helpers.createGenerator('node:app', [ 17 | '../../app' 18 | ]); 19 | this.app.options['skip-install'] = true; 20 | done(); 21 | }.bind(this)); 22 | }); 23 | 24 | it('creates expected files', function (done) { 25 | var expected = [ 26 | 'index.js', 27 | 'cli.js', 28 | 'test/test.js', 29 | '.gitignore', 30 | '.jshintrc', 31 | '.travis.yml', 32 | 'Gruntfile.js', 33 | 'package.json', 34 | 'README.md' 35 | ]; 36 | 37 | helpers.mockPrompt(this.app, { 38 | 'name': 'mymodule', 39 | 'description': 'awesome module', 40 | 'pkgName': false, 41 | 'license': 'MIT', 42 | 'homepage': 'http://yeoman.io', 43 | 'githubUsername': 'octocat', 44 | 'authorName': 'Octo Cat', 45 | 'authorEmail': 'octo@example.com', 46 | 'authorUrl': 'http://yeoman.io', 47 | 'keywords': 'keyword1,keyword2,keyword3', 48 | 'cli': true, 49 | 'browser': true 50 | }); 51 | 52 | shelljs.exec('npm install meow', {silent: true}); 53 | 54 | this.app.run({}, function () { 55 | assert.file(expected); 56 | assert.fileContent('package.json', /"name": "mymodule"/); 57 | assert.deepEqual(require('./temp/cli.js'), {}); 58 | done(); 59 | }); 60 | 61 | }); 62 | 63 | it('creates expected files without cli', function (done) { 64 | var expected = [ 65 | 'index.js', 66 | 'test/test.js', 67 | '.gitignore', 68 | '.jshintrc', 69 | '.travis.yml', 70 | 'Gruntfile.js', 71 | 'package.json', 72 | 'README.md' 73 | ]; 74 | 75 | helpers.mockPrompt(this.app, { 76 | 'name': 'mymodule', 77 | 'description': 'awesome module', 78 | 'pkgName': false, 79 | 'license': 'MIT', 80 | 'homepage': 'http://yeoman.io', 81 | 'githubUsername': 'octocat', 82 | 'authorName': 'Octo Cat', 83 | 'authorEmail': 'octo@example.com', 84 | 'authorUrl': 'http://yeoman.io', 85 | 'keywords': 'keyword1,keyword2,keyword3', 86 | 'cli': false, 87 | 'browser': true 88 | }); 89 | 90 | this.app.run({}, function () { 91 | assert.file(expected); 92 | assert.fileContent('package.json', /"name": "mymodule"/); 93 | done(); 94 | }); 95 | }); 96 | }); 97 | -------------------------------------------------------------------------------- /app/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var path = require('path'); 3 | var npmName = require('npm-name'); 4 | var yeoman = require('yeoman-generator'); 5 | 6 | module.exports = yeoman.generators.Base.extend({ 7 | init: function () { 8 | this.pkg = require('../package.json'); 9 | this.log( 10 | this.yeoman + 11 | '\nThe name of your project shouldn\'t contain "node" or "js" and' + 12 | '\nshould be a unique ID not already in use at npmjs.org.'); 13 | }, 14 | askForModuleName: function () { 15 | var done = this.async(); 16 | 17 | var prompts = [{ 18 | name: 'name', 19 | message: 'Module Name', 20 | default: path.basename(process.cwd()), 21 | }, { 22 | type: 'confirm', 23 | name: 'pkgName', 24 | message: 'The name above already exists on npm, choose another?', 25 | default: true, 26 | when: function(answers) { 27 | var done = this.async(); 28 | 29 | npmName(answers.name, function (err, available) { 30 | if (!available) { 31 | done(true); 32 | return; 33 | } 34 | 35 | done(false); 36 | }); 37 | } 38 | }]; 39 | 40 | this.prompt(prompts, function (props) { 41 | if (props.pkgName) { 42 | return this.askForModuleName(); 43 | } 44 | 45 | this.slugname = this._.slugify(props.name); 46 | this.safeSlugname = this.slugname.replace(/-+([a-zA-Z0-9])/g, function (g) { 47 | return g[1].toUpperCase(); 48 | }); 49 | 50 | done(); 51 | 52 | }.bind(this)); 53 | }, 54 | 55 | askFor: function () { 56 | var cb = this.async(); 57 | 58 | var prompts = [{ 59 | name: 'description', 60 | message: 'Description', 61 | default: 'The best module ever.' 62 | }, { 63 | name: 'homepage', 64 | message: 'Homepage' 65 | }, { 66 | name: 'license', 67 | message: 'License', 68 | default: 'MIT' 69 | }, { 70 | name: 'githubUsername', 71 | message: 'GitHub username' 72 | }, { 73 | name: 'authorName', 74 | message: 'Author\'s Name' 75 | }, { 76 | name: 'authorEmail', 77 | message: 'Author\'s Email' 78 | }, { 79 | name: 'authorUrl', 80 | message: 'Author\'s Homepage' 81 | }, { 82 | name: 'keywords', 83 | message: 'Key your keywords (comma to split)' 84 | }, { 85 | type: 'confirm', 86 | name: 'cli', 87 | message: 'Do you need a CLI?' 88 | }, { 89 | type: 'confirm', 90 | name: 'browser', 91 | message: 'Do you need Browserify?' 92 | }]; 93 | 94 | this.currentYear = (new Date()).getFullYear(); 95 | 96 | this.prompt(prompts, function (props) { 97 | if (props.githubUsername) { 98 | this.repoUrl = props.githubUsername + '/' + this.slugname; 99 | } else { 100 | this.repoUrl = 'user/repo'; 101 | } 102 | 103 | this.keywords = props.keywords.split(',').map(function (el) { 104 | return el.trim(); 105 | }); 106 | 107 | this.props = props; 108 | 109 | cb(); 110 | }.bind(this)); 111 | }, 112 | 113 | 114 | app: function () { 115 | this.config.save(); 116 | this.copy('jshintrc', '.jshintrc'); 117 | this.copy('gitignore', '.gitignore'); 118 | this.copy('travis.yml', '.travis.yml'); 119 | 120 | this.template('README.md', 'README.md'); 121 | this.template('Gruntfile.js', 'Gruntfile.js'); 122 | this.template('_package.json', 'package.json'); 123 | 124 | if (this.props.cli) { 125 | this.template('cli.js', 'cli.js'); 126 | } 127 | }, 128 | 129 | projectfiles: function () { 130 | this.template('index.js', 'index.js'); 131 | this.mkdir('test'); 132 | this.template('test/test.js', 'test/test.js'); 133 | }, 134 | 135 | install: function () { 136 | this.installDependencies({ 137 | bower: false, 138 | skipInstall: this.options['skip-install'] 139 | }); 140 | } 141 | }); 142 | --------------------------------------------------------------------------------