├── .editorconfig
├── .gitattributes
├── .gitignore
├── .jscsrc
├── .jshintrc
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── app
├── index.js
└── templates
│ ├── .jscsrc
│ ├── _CHANGELOG.md
│ ├── _README.md
│ ├── _gitignore
│ ├── _gulpfile.js
│ ├── _package.json
│ ├── _travis.yml
│ ├── editorconfig
│ ├── example
│ └── simple.js
│ ├── jshintrc
│ ├── lib
│ └── name.js
│ └── test
│ └── name_test.js
├── config.js
├── gulpfile.js
├── node-gulp.png
├── package.json
└── test
├── test-config.js
├── test-creation.js
├── test-generated-project.js
└── test-load.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 |
10 | # Change these settings to your own preference
11 | indent_style = space
12 | indent_size = 2
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | temp/
3 | coverage/
4 | npm-debug.log
5 | .DS_Store
6 | .idea
7 | settings.json
--------------------------------------------------------------------------------
/.jscsrc:
--------------------------------------------------------------------------------
1 | {
2 | "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
3 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
4 | "disallowSpaceBeforeBinaryOperators": [",", ":"],
5 | "disallowSpaceAfterBinaryOperators": ["!"],
6 | "requireSpaceBeforeBinaryOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
7 | "requireSpaceAfterBinaryOperators": ["?", "+", "-", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
8 | "disallowImplicitTypeConversion": ["string"],
9 | "disallowKeywords": ["with"],
10 | "disallowMultipleLineBreaks": true,
11 | "disallowKeywordsOnNewLine": ["else"],
12 | "disallowTrailingWhitespace": true,
13 | "requireLineFeedAtFileEnd": true,
14 | "validateJSDoc": {
15 | "checkParamNames": true,
16 | "requireParamTypes": true
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | env: CI=true
3 | sudo: false
4 | node_js:
5 | - '0.10'
6 | after_script:
7 | - npm run coveralls
8 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | #v0.7.0 (2014-10-20)
2 |
3 | ## New features
4 | - [#32](https://github.com/youngmountain/generator-node-gulp/issues/32): Add jscs option: validateQuoteMarks #32
5 | - [#30](https://github.com/youngmountain/generator-node-gulp/pull/30): Add jscs option: validateIndentation #30
6 | - [#27](https://github.com/youngmountain/generator-node-gulp/pull/27): Generate CHANGELOG.md on project creation #27
7 |
8 | ## Bugfix
9 | - [#37](https://github.com/youngmountain/generator-node-gulp/pull/37): Handle gulp-plumber errors #37
10 |
11 | ## Misc
12 | - [#29](https://github.com/youngmountain/generator-node-gulp/pull/29): Bump generator dependencies #29
13 | - [#28](https://github.com/youngmountain/generator-node-gulp/pull/28): Bump generated project devDependencies #28
14 |
15 | #v0.6.0 (2014-09-10)
16 |
17 | ## New features
18 | - [#21](https://github.com/youngmountain/generator-node-gulp/pull/21): Add jasmine as optional test-framework (Thanks @kojiwakayama )
19 |
20 | ## Misc
21 | - [#22](https://github.com/youngmountain/generator-node-gulp/pull/22): Add console.log for return value in example
22 | - [#20](https://github.com/youngmountain/generator-node-gulp/pull/20): Use module.exports instead of exports
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2013
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # node gulp
5 | [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image] [![Coverage Status][coveralls-image]][coveralls-url]
6 |
7 | > Based on [generator-node](https://github.com/yeoman/generator-node)
8 |
9 | This generator creates a new Node.js module, generating all the boilerplate you need to get started with best-of-breed from the gulp ecosystem. The generator also optionally installs additional gulp plugins, see the list below.
10 |
11 |
12 |
13 | ## Installation
14 |
15 | Install the generator by running: `npm install -g generator-node-gulp`.
16 |
17 | ## Options
18 |
19 | * `--test-framework=[framework]`
20 |
21 | Defaults to `mocha`. Can be switched to
22 | another supported testing framework like `jasmine`.
23 |
24 | * `--skip-install`
25 |
26 | Skips the automatic execution of `bower` and `npm` after
27 | scaffolding has finished.
28 |
29 | ## Features
30 |
31 | - Customize the dependencies prompt by editing the ```settings.json``` file [see](#dependencies).
32 | - Prefills prompt with the last used values for
33 | - GitHub username
34 | - Author's Name
35 | - Author's Email
36 | - Author's Homepage
37 |
38 | ### devDependencies
39 |
40 | - Mocha Unit Testing with [gulp-mocha](https://github.com/sindresorhus/gulp-mocha)
41 | - Automagically lint your code with [gulp-jshint](https://github.com/spenceralger/gulp-jshint)
42 | - Optional – Check JavaScript code style with [gulp-jscs](https://github.com/sindresorhus/gulp-jscs)
43 | - Optional – Measuring code coverage with [gulp-istanbul](https://github.com/SBoudrias/gulp-istanbul)
44 | - Optional – Upload LCOV data to [coveralls.io](http://coveralls.io) with [coveralls](https://github.com/cainus/node-coveralls)
45 | - Optional – Bump npm versions with [gulp-bump](https://github.com/stevelacy/gulp-bump)
46 | - Optional - Jasmine Unit Testing with [gulp-jasmine](https://github.com/sindresorhus/gulp-jasmine)
47 |
48 | ### dependencies
49 |
50 | You can customize the dependencies prompt by editing the ```settings.json```. The file is located in the root of the generator-node-gulp ```/usr/local/lib/node_modules/generator-node-gulp/```.
51 |
52 | - [debug](https://github.com/visionmedia/debug)
53 | - [Lo-Dash](http://lodash.com/)
54 | - [q](https://github.com/kriskowal/q)
55 |
56 | ### settings.json
57 |
58 | By default, the file looks something like this.
59 |
60 | ```
61 | {
62 | "meta": {
63 | "githubUsername": "stefanbuck",
64 | "authorName": "Stefan Buck",
65 | "authorEmail": "me@stefanbuck.com",
66 | "authorUrl": "www.stefanbuck.com"
67 | },
68 | "dependencies": [
69 | {
70 | "name": "lodash",
71 | "description": "A utility library"
72 | },
73 | {
74 | "name": "q",
75 | "description": "A library for promises"
76 | },
77 | {
78 | "name": "debug",
79 | "description": "tiny node.js debugging utility"
80 | }
81 | ]
82 | }
83 | ```
84 |
85 |
86 | ## Usage
87 |
88 | At the command-line, cd into an empty directory, run this command and follow the prompts.
89 |
90 | ```
91 | yo node-gulp
92 | ```
93 |
94 | _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._
95 |
96 |
97 |
98 | ## Support
99 |
100 | Should you have any problems or wishes for improvements, feel free to open an [issue](https://github.com/youngmountain/generator-node-gulp/issues).
101 |
102 |
103 | ## Articles
104 |
105 | Some recommended articles to get you started with node.
106 | - [Node.js require(s) best practices](http://www.mircozeiss.com/node-js-require-s-best-practices/)
107 |
108 |
109 | ## Team
110 | - [Stefan Buck](https://github.com/stefanbuck)
111 | - [Kentaro Wakayama](https://github.com/kwakayama)
112 | - [Koji Wakayama](https://github.com/kojiwakayama)
113 |
114 |
115 | ## License
116 |
117 | [MIT License](http://en.wikipedia.org/wiki/MIT_License)
118 |
119 | Logo by [Koji Wakayama](https://github.com/kojiwakayama)
120 |
121 | [npm-url]: https://npmjs.org/package/generator-node-gulp
122 | [npm-image]: https://badge.fury.io/js/generator-node-gulp.svg
123 | [travis-url]: https://travis-ci.org/youngmountain/generator-node-gulp
124 | [travis-image]: https://travis-ci.org/youngmountain/generator-node-gulp.svg?branch=master
125 | [daviddm-url]: https://david-dm.org/youngmountain/generator-node-gulp.svg?theme=shields.io
126 | [daviddm-image]: https://david-dm.org/youngmountain/generator-node-gulp
127 | [coveralls-url]: https://coveralls.io/r/youngmountain/generator-node-gulp
128 | [coveralls-image]: https://coveralls.io/repos/youngmountain/generator-node-gulp/badge.png
129 |
--------------------------------------------------------------------------------
/app/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var chalk = require('chalk');
4 | var util = require('util');
5 | var path = require('path');
6 | var npmName = require('npm-name');
7 | var npmLatest = require('npm-latest');
8 | var yeoman = require('yeoman-generator');
9 | var yosay = require('yosay');
10 | var Config = require('../config');
11 |
12 | module.exports = yeoman.generators.Base.extend({
13 | initializing: function () {
14 | this.settings = new Config();
15 | this.testFramework = this.options['test-framework'] || 'mocha';
16 | },
17 |
18 | prompting: function () {
19 | var cb = this.async();
20 | var log = this.log;
21 |
22 | log(yosay('Hello, and welcome to the node-gulp generator. Let\'s be awesome together!'));
23 |
24 | var prompts = [{
25 | name: 'name',
26 | message: 'Module Name',
27 | default: path.basename(process.cwd()),
28 | filter: function (input) {
29 | var done = this.async();
30 |
31 | npmName(input, function (err, available) {
32 | if (!available) {
33 | log.info(chalk.yellow(input) + ' already exists on npm. You might want to use another name.');
34 | }
35 |
36 | done(input);
37 | });
38 | }
39 | }, {
40 | name: 'description',
41 | message: 'Description',
42 | default: 'The best module ever.'
43 | }, {
44 | name: 'homepage',
45 | message: 'Homepage'
46 | }, {
47 | name: 'license',
48 | message: 'License',
49 | default: 'MIT'
50 | }, {
51 | name: 'githubUsername',
52 | message: 'GitHub username'
53 | }, {
54 | name: 'authorName',
55 | message: 'Author\'s Name'
56 | }, {
57 | name: 'authorEmail',
58 | message: 'Author\'s Email'
59 | }, {
60 | name: 'authorUrl',
61 | message: 'Author\'s Homepage'
62 | }];
63 |
64 | this.currentYear = new Date().getFullYear();
65 | this.currentDate = new Date().toISOString().slice(0,10); // YYY-MM-DD
66 |
67 | // Write settings default values back to prompt
68 | var meta = this.settings.getMeta();
69 | prompts.forEach(function (val) {
70 | if (meta[val.name]) {
71 | val.default = meta[val.name];
72 | }
73 | }.bind(this));
74 |
75 | this.prompt(prompts, function (props) {
76 | this.slugname = this._.slugify(props.name);
77 | this.safeSlugname = this.slugname.replace(
78 | /-+([a-zA-Z0-9])/g,
79 | function (g) {
80 | return g[1].toUpperCase();
81 | }
82 | );
83 |
84 | if (props.homepage) {
85 | props.homepage = props.homepage.trim();
86 | }
87 | if (props.license) {
88 | props.license = props.license.trim() || 'MIT';
89 | }
90 | if (props.authorName) {
91 | props.authorName = props.authorName.trim();
92 | }
93 | if (props.authorEmail) {
94 | props.authorEmail = props.authorEmail.trim();
95 | }
96 | if (props.authorUrl) {
97 | props.authorUrl = props.authorUrl.trim();
98 | }
99 |
100 | this.settings.setMeta(props);
101 |
102 | if (props.githubUsername && props.githubUsername.trim()) {
103 | this.repoUrl = 'https://github.com/' + props.githubUsername + '/' + this.slugname;
104 | } else {
105 | this.repoUrl = 'user/repo';
106 | props.githubUsername = 'user';
107 | }
108 |
109 | if (!props.homepage) {
110 | props.homepage = this.repoUrl;
111 | }
112 |
113 | this.props = props;
114 |
115 | cb();
116 | }.bind(this));
117 |
118 | },
119 |
120 | askForModules: function () {
121 | var cb = this.async();
122 |
123 | var prompts = [{
124 | type: 'checkbox',
125 | name: 'modules',
126 | message: 'Which modules would you like to include?',
127 | choices: [{
128 | value: 'jscsModule',
129 | name: 'jscs (JavaScript Code Style checker)',
130 | checked: true
131 | }, {
132 | value: 'releaseModule',
133 | name: 'release (Bump npm versions with Gulp)',
134 | checked: true
135 | }, {
136 | value: 'istanbulModule',
137 | name: 'istanbul (JS code coverage tool)',
138 | checked: true
139 | }
140 | ]
141 | }];
142 |
143 | this.prompt(prompts, function (props) {
144 |
145 | var hasMod = function (mod) {
146 | return props.modules.indexOf(mod) !== -1;
147 | };
148 |
149 | this.jscsModule = hasMod('jscsModule');
150 | this.releaseModule = hasMod('releaseModule');
151 | this.istanbulModule = hasMod('istanbulModule');
152 | this.coverallsModule = true;
153 |
154 | if (this.istanbulModule) {
155 |
156 | var promptCoveralls = [{
157 | type: 'confirm',
158 | name: 'coverallsModule',
159 | message: 'Would you like add coveralls',
160 | default: true
161 | }];
162 |
163 | this.prompt(promptCoveralls, function (props) {
164 | if (props && props.coverallsModule) {
165 | this.coverallsModule = props.coverallsModule;
166 | } else {
167 | this.coverallsModule = false;
168 | }
169 | cb();
170 |
171 | }.bind(this));
172 |
173 | } else {
174 | cb();
175 | }
176 |
177 | }.bind(this));
178 |
179 | },
180 |
181 | askForDependencies: function () {
182 | var cb = this.async();
183 |
184 | var prompts = [{
185 | type: 'checkbox',
186 | name: 'dependencies',
187 | message: 'Which dependencies would you like to include?',
188 | choices: []
189 | }];
190 |
191 | var dependencies = this.settings.getDependencies();
192 | dependencies.forEach(function (pkg) {
193 | prompts[0].choices.push({
194 | value: pkg.name,
195 | name: util.format('%s (%s)', pkg.name, pkg.description),
196 | checked: true
197 | });
198 | });
199 |
200 | this.prompt(prompts, function (props) {
201 |
202 | var hasMod = function (mod) {
203 | return props.dependencies.indexOf(mod) !== -1;
204 | };
205 |
206 | this.usedDependencies = {};
207 | dependencies.forEach(function (dep) {
208 | if (hasMod(dep.name)) {
209 | this.usedDependencies[dep.name] = 'latest';
210 | }
211 | }.bind(this));
212 |
213 | cb();
214 |
215 | }.bind(this));
216 |
217 | },
218 |
219 | getLatestVersions: function () {
220 | var cb = this.async();
221 | var count = Object.keys(this.usedDependencies).length;
222 |
223 | if (count === 0) {
224 | return cb();
225 | }
226 |
227 | for (var packageName in this.usedDependencies) {
228 | npmLatest(packageName, {timeout: 1900}, function (err, result) {
229 | if (!err && result.name && result.version) {
230 | this.usedDependencies[result.name] = result.version;
231 | }
232 | if (!--count) {
233 | cb();
234 | }
235 | }.bind(this));
236 | }
237 | },
238 |
239 | dependency: function dependency() {
240 | this.dependencies = '';
241 | for (var name in this.usedDependencies) {
242 | var version = this.usedDependencies[name];
243 | this.dependencies += util.format('\n "%s": "%s",', name, version);
244 | }
245 | if (this.dependencies.length > 0) {
246 | this.dependencies = this.dependencies.replace('\n', '');
247 | this.dependencies = this.dependencies.substring(0, this.dependencies.length - 1);
248 | }
249 | },
250 |
251 | copyfiles: function () {
252 | this.copy('jshintrc', '.jshintrc');
253 | this.copy('_gitignore', '.gitignore');
254 | this.copy('_travis.yml', '.travis.yml');
255 | this.copy('editorconfig', '.editorconfig');
256 | if (this.jscsModule) {
257 | this.copy('.jscsrc', '.jscsrc');
258 | }
259 |
260 | this.template('_README.md', 'README.md');
261 | this.template('_CHANGELOG.md', 'CHANGELOG.md');
262 | this.template('_gulpfile.js', 'gulpfile.js');
263 | this.template('_package.json', 'package.json');
264 | },
265 |
266 | writing: function () {
267 | this.mkdir('lib');
268 | this.template('lib/name.js', 'lib/' + this.slugname + '.js');
269 |
270 | this.mkdir('test');
271 | this.template('test/name_test.js', 'test/' + this.slugname + '_test.js');
272 |
273 | this.mkdir('example');
274 | this.template('example/simple.js', 'example/simple.js');
275 | },
276 |
277 | install: function () {
278 | this.installDependencies({
279 | bower: false,
280 | skipInstall: this.options['skip-install']
281 | });
282 | }
283 | });
284 |
--------------------------------------------------------------------------------
/app/templates/.jscsrc:
--------------------------------------------------------------------------------
1 | {
2 | "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
3 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
4 | "disallowSpaceBeforeBinaryOperators": [",", ":"],
5 | "disallowSpaceAfterBinaryOperators": ["!"],
6 | "requireSpaceBeforeBinaryOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
7 | "requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
8 | "disallowImplicitTypeConversion": ["string"],
9 | "disallowKeywords": ["with"],
10 | "disallowMultipleLineBreaks": true,
11 | "disallowKeywordsOnNewLine": ["else"],
12 | "disallowTrailingWhitespace": true,
13 | "requireLineFeedAtFileEnd": true,
14 | "validateIndentation": 2,
15 | "validateQuoteMarks": "'",
16 | "validateJSDoc": {
17 | "checkParamNames": true,
18 | "requireParamTypes": true
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/templates/_CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | # 0.1.0 (<%= currentDate %>)
3 |
4 | - Initial version
5 |
--------------------------------------------------------------------------------
/app/templates/_README.md:
--------------------------------------------------------------------------------
1 | # <%= props.name %>
2 | [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image]<% if (coverallsModule) { %> [![Coverage Status][coveralls-image]][coveralls-url]<% } %>
3 |
4 | <%= props.description %>
5 |
6 |
7 | ## Install
8 |
9 | ```bash
10 | $ npm install --save <%= slugname %>
11 | ```
12 |
13 |
14 | ## Usage
15 |
16 | ```javascript
17 | var <%= safeSlugname %> = require('<%= slugname %>');
18 | <%= safeSlugname %>(); // "awesome"
19 | ```
20 |
21 | ## API
22 |
23 | _(Coming soon)_
24 |
25 |
26 | ## Contributing
27 |
28 | 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 [gulp](http://gulpjs.com/).
29 |
30 |
31 | ## License
32 |
33 | Copyright (c) <%= currentYear %><% if (props.authorName) { %> <%= props.authorName %><% } %>. Licensed under the <%= props.license %> license.
34 |
35 |
36 |
37 | [npm-url]: https://npmjs.org/package/<%= slugname %>
38 | [npm-image]: https://badge.fury.io/js/<%= slugname %>.svg
39 | [travis-url]: https://travis-ci.org/<%= props.githubUsername %>/<%= slugname %>
40 | [travis-image]: https://travis-ci.org/<%= props.githubUsername %>/<%= slugname %>.svg?branch=master
41 | [daviddm-url]: https://david-dm.org/<%= props.githubUsername %>/<%= slugname %>.svg?theme=shields.io
42 | [daviddm-image]: https://david-dm.org/<%= props.githubUsername %>/<%= slugname %><% if (coverallsModule) { %>
43 | [coveralls-url]: https://coveralls.io/r/<%= props.githubUsername %>/<%= slugname %>
44 | [coveralls-image]: https://coveralls.io/repos/<%= props.githubUsername %>/<%= slugname %>/badge.png<% } %>
45 |
--------------------------------------------------------------------------------
/app/templates/_gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | temp/<% if (coverallsModule) { %>
3 | coverage/
4 | <% } %>npm-debug.log
5 | .DS_Store
6 | .idea
7 |
--------------------------------------------------------------------------------
/app/templates/_gulpfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var gulp = require('gulp');
4 | var plugins = require('gulp-load-plugins')();
5 |
6 | var paths = {
7 | lint: ['./gulpfile.js', './lib/**/*.js'],
8 | watch: ['./gulpfile.js', './lib/**', './test/**/*.js', '!test/{temp,temp/**}'],
9 | tests: ['./test/**/*.js', '!test/{temp,temp/**}']<% if (istanbulModule) { %>,
10 | source: ['./lib/*.js']<% } %>
11 | };
12 |
13 | var plumberConf = {};
14 |
15 | if (process.env.CI) {
16 | plumberConf.errorHandler = function(err) {
17 | throw err;
18 | };
19 | }
20 |
21 | gulp.task('lint', function () {
22 | return gulp.src(paths.lint)
23 | .pipe(plugins.jshint('.jshintrc'))<% if (jscsModule) { %>
24 | .pipe(plugins.plumber(plumberConf))
25 | .pipe(plugins.jscs())<% } %>
26 | .pipe(plugins.jshint.reporter('jshint-stylish'));
27 | });<% if (istanbulModule) { %>
28 |
29 | gulp.task('istanbul', function (cb) {
30 | gulp.src(paths.source)
31 | .pipe(plugins.istanbul()) // Covering files
32 | .pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files
33 | .on('finish', function () {
34 | gulp.src(paths.tests)
35 | .pipe(plugins.plumber(plumberConf))<% if (testFramework === 'jasmine') { %>
36 | .pipe(plugins.jasmine())<% } %><% if (testFramework === 'mocha') { %>
37 | .pipe(plugins.mocha())<% } %>
38 | .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests runned
39 | .on('finish', function() {
40 | process.chdir(__dirname);
41 | cb();
42 | });
43 | });
44 | });<% } else { %>
45 |
46 | gulp.task('unitTest', function () {
47 | gulp.src(paths.tests, {cwd: __dirname})
48 | .pipe(plugins.plumber(plumberConf))<% if (testFramework === 'jasmine') { %>
49 | .pipe(plugins.jasmine());<% } %><% if (testFramework === 'mocha') { %>
50 | .pipe(plugins.mocha({ reporter: 'list' }));<% } %>
51 | });<% } %><% if (releaseModule) { %>
52 |
53 | gulp.task('bump', ['test'], function () {
54 | var bumpType = plugins.util.env.type || 'patch'; // major.minor.patch
55 |
56 | return gulp.src(['./package.json'])
57 | .pipe(plugins.bump({ type: bumpType }))
58 | .pipe(gulp.dest('./'));
59 | });<% } %>
60 |
61 | gulp.task('watch', ['test'], function () {
62 | gulp.watch(paths.watch, ['test']);
63 | });
64 |
65 | gulp.task('test', ['lint', <% if (istanbulModule) { %>'istanbul'<% } else { %>'unitTest'<% } %>]);<% if (releaseModule) { %>
66 |
67 | gulp.task('release', ['bump']);<% } %>
68 |
69 | gulp.task('default', ['test']);
70 |
--------------------------------------------------------------------------------
/app/templates/_package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "<%= slugname %>",
3 | "description": "<%= props.description %>",
4 | "version": "0.0.0",<% if (props.homepage) { %>
5 | "homepage": "<%= props.homepage %>",<%}%>
6 | "bugs": "<%= repoUrl %>/issues",
7 | "license": "<%= props.license %>",
8 | "main": "lib/<%= slugname %>.js",
9 | "author": {
10 | "name": "<%= props.authorName %>"<% if (props.authorEmail) { %>,
11 | "email": "<%= props.authorEmail %>"<% } %><% if (props.authorUrl) { %>,
12 | "url": "<%= props.authorUrl %>"<% } %>
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "<%= repoUrl %>"
17 | },
18 | "keywords":[],
19 | "dependencies": {<% if (dependencies) { %>
20 | <%= dependencies %>
21 | <% } %>},
22 | "devDependencies": {
23 | "gulp": "^3.8.8",<% if (releaseModule) { %>
24 | "gulp-util": "^3.0.1",
25 | "gulp-bump": "^0.1.11",<% } %><% if (jscsModule) { %>
26 | "gulp-jscs": "^1.1.2",<% } %>
27 | "gulp-jshint": "^1.8.4",<% if (testFramework === 'mocha') { %>
28 | "gulp-mocha": "^1.1.0",<% } %><% if (testFramework === 'jasmine') { %>
29 | "gulp-jasmine": "^1.0.0",<% } %><% if (istanbulModule) { %>
30 | "gulp-istanbul": "^0.5.0",<% } %><% if (coverallsModule) { %>
31 | "coveralls": "^2.11.1",<% } %><% if (testFramework === 'mocha') { %>
32 | "should": "^4.0.4",<% } %>
33 | "jshint-stylish": "^0.4.0",
34 | "gulp-load-plugins": "^0.6.0",
35 | "gulp-plumber": "^0.6.5"
36 | },
37 | "scripts": {<% if (coverallsModule) { %>
38 | "coveralls": "gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",<% } %>
39 | "test": "gulp test"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/templates/_travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | env: CI=true
3 | sudo: false
4 | node_js:
5 | - '0.10'<% if (coverallsModule) { %>
6 | after_script:
7 | - npm run coveralls<% } %>
8 |
--------------------------------------------------------------------------------
/app/templates/editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 |
10 | # Change these settings to your own preference
11 | indent_style = space
12 | indent_size = 2
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/app/templates/example/simple.js:
--------------------------------------------------------------------------------
1 | /*
2 | * <%= props.name %>
3 | * <%= props.homepage %>
4 | *
5 | * Copyright (c) <%= currentYear %><% if (props.authorName) { %> <%= props.authorName %><% } %>
6 | * Licensed under the <%= props.license %> license.
7 | */
8 |
9 | 'use strict';
10 |
11 | var <%= safeSlugname %> = require('../');
12 |
13 | console.log(<%= safeSlugname %>()); // "awesome"
14 |
--------------------------------------------------------------------------------
/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 | "globals": {
15 | "describe" : false,
16 | "it" : false,
17 | "before" : false,
18 | "beforeEach" : false,
19 | "after" : false,
20 | "afterEach" : false
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/templates/lib/name.js:
--------------------------------------------------------------------------------
1 | /*
2 | * <%= props.name %>
3 | * <%= props.homepage %>
4 | *
5 | * Copyright (c) <%= currentYear %><% if (props.authorName) { %> <%= props.authorName %><% } %>
6 | * Licensed under the <%= props.license %> license.
7 | */
8 |
9 | 'use strict';
10 |
11 | module.exports = function() {
12 | return 'awesome';
13 | };
14 |
--------------------------------------------------------------------------------
/app/templates/test/name_test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var <%= safeSlugname %> = require('../');<% if (testFramework === 'mocha') { %>
4 | var assert = require('should');<% } %>
5 |
6 | describe('<%= safeSlugname %>', function () {
7 |
8 | it('should be awesome', function () {<% if (testFramework === 'jasmine') { %>
9 | expect(<%= safeSlugname %>()).toEqual('awesome');<% } %><% if (testFramework === 'mocha') { %>
10 | <%= safeSlugname %>().should.equal('awesome');<% } %>
11 | });
12 |
13 | });
14 |
--------------------------------------------------------------------------------
/config.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var path = require('path');
4 | var fs = require('fs');
5 |
6 | var configKeys = ['githubUsername', 'authorName', 'authorEmail', 'authorUrl'];
7 |
8 | var _defaultDependencies = [
9 | {name: 'lodash', description: 'A utility library'},
10 | {name: 'q', description: 'A library for promises'},
11 | {name: 'debug', description: 'tiny node.js debugging utility'}
12 | ];
13 |
14 | /**
15 | * The Generator settings
16 | * This is used to store the generators meta and dependencies information in a persistent data source.
17 | * @constructor
18 | */
19 | var Config = module.exports = function Config(configPath) {
20 | this._meta = {};
21 | this._dependencies = [];
22 | this._configPath = configPath || path.join(__dirname, './settings.json');
23 |
24 | this._load();
25 | };
26 |
27 | /**
28 | * Loads the meta and dependencies data from the settings file
29 | */
30 | Config.prototype._load = function _load() {
31 | if (fs.existsSync(this._configPath)) {
32 | var content = fs.readFileSync(this._configPath);
33 | content = JSON.parse(content);
34 | this._meta = content.meta;
35 | this._dependencies = content.dependencies;
36 | } else {
37 | this._dependencies = _defaultDependencies;
38 | }
39 | };
40 |
41 | /**
42 | * Store the meta and dependencies data in the settings file
43 | */
44 | Config.prototype._write = function _write() {
45 | var content = {
46 | meta: this._meta,
47 | dependencies: this._dependencies,
48 | };
49 | content = JSON.stringify(content, '', 2);
50 | fs.writeFileSync(this._configPath, content);
51 | };
52 |
53 | /**
54 | * Get the stored generators dependencies
55 | * @return {Object} Generators dependencies
56 | */
57 | Config.prototype.getDependencies = function getDependencies() {
58 | return this._dependencies;
59 | };
60 |
61 | /**
62 | * Get the stored generators meta data
63 | * @return {Object} Generators metadata
64 | */
65 | Config.prototype.getMeta = function getMeta() {
66 | return this._meta;
67 | };
68 |
69 | /**
70 | * Store the given metadata in the settings file
71 | * @return {Object} Generators metadata
72 | */
73 | Config.prototype.setMeta = function storeMeta(options) {
74 | configKeys.forEach(function (val) {
75 | if (options[val] && options[val].trim()) {
76 | this._meta[val] = options[val];
77 | }
78 | }.bind(this));
79 | this._write();
80 | };
81 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var gulp = require('gulp');
4 | var plugins = require('gulp-load-plugins')();
5 |
6 | var paths = {
7 | lint: ['./gulpfile.js', './app/index.js', './config.js'],
8 | tests: ['./test/**/*.js', '!./test/temp/**/*.js'],
9 | watch: ['./gulpfile.js', './app/**', './config.js', './test/**/*.js', '!./test/temp/**/*.js'],
10 | source: ['./lib/*.js', './app/index.js', './config.js']
11 | };
12 |
13 | var plumberConf = {};
14 |
15 | if (process.env.CI) {
16 | plumberConf.errorHandler = function(err) {
17 | throw err;
18 | };
19 | }
20 |
21 | gulp.task('lint', function () {
22 | return gulp.src(paths.lint)
23 | .pipe(plugins.jshint('.jshintrc'))
24 | .pipe(plugins.plumber(plumberConf))
25 | .pipe(plugins.jscs())
26 | .pipe(plugins.jshint.reporter('jshint-stylish'));
27 | });
28 |
29 | gulp.task('istanbul', function (cb) {
30 | gulp.src(paths.source)
31 | .pipe(plugins.istanbul()) // Covering files
32 | .pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files
33 | .on('finish', function () {
34 | gulp.src(paths.tests, {cwd: __dirname})
35 | .pipe(plugins.plumber(plumberConf))
36 | .pipe(plugins.mocha())
37 | .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests runned
38 | .on('finish', function() {
39 | process.chdir(__dirname);
40 | cb();
41 | });
42 | });
43 | });
44 |
45 | gulp.task('bump', ['test'], function () {
46 | var bumpType = plugins.util.env.type || 'patch'; // major.minor.patch
47 |
48 | return gulp.src(['./package.json'])
49 | .pipe(plugins.bump({ type: bumpType }))
50 | .pipe(gulp.dest('./'));
51 | });
52 |
53 | gulp.task('watch', ['istanbul'], function () {
54 | gulp.watch(paths.watch, ['istanbul']);
55 | });
56 |
57 | gulp.task('test', ['lint', 'istanbul']);
58 |
59 | gulp.task('release', ['bump']);
60 |
61 | gulp.task('default', ['test']);
62 |
--------------------------------------------------------------------------------
/node-gulp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmountain/generator-node-gulp/71b463f40a1afb169da09a41ff468b76a4c69d6c/node-gulp.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generator-node-gulp",
3 | "description": "A node generator for Yeoman",
4 | "version": "0.7.5",
5 | "homepage": "https://github.com/youngmountain/generator-node-gulp",
6 | "bugs": "https://github.com/youngmountain/generator-node-gulp/issues",
7 | "license": "MIT",
8 | "main": "app/index.js",
9 | "author": {
10 | "name": "Stefan Buck",
11 | "email": "code@stefanbuck.com",
12 | "url": "http://stefanbuck.com"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/youngmountain/generator-node-gulp"
17 | },
18 | "keywords": [
19 | "yeoman-generator",
20 | "scaffold",
21 | "node",
22 | "gulp"
23 | ],
24 | "dependencies": {
25 | "chalk": "^0.5.1",
26 | "npm-latest": "^0.2.0",
27 | "npm-name": "^1.0.1",
28 | "yeoman-generator": "^0.17.5",
29 | "yosay": "^1.0.0"
30 | },
31 | "devDependencies": {
32 | "gulp": "^3.8.8",
33 | "gulp-util": "^3.0.1",
34 | "gulp-bump": "^0.1.11",
35 | "gulp-jscs": "^1.1.2",
36 | "gulp-jshint": "^1.8.4",
37 | "gulp-mocha": "^1.1.0",
38 | "gulp-istanbul": "^0.5.0",
39 | "coveralls": "^2.11.1",
40 | "should": "^4.0.4",
41 | "jshint-stylish": "^0.4.0",
42 | "gulp-load-plugins": "^0.6.0",
43 | "gulp-plumber": "^0.6.5"
44 | },
45 | "peerDependencies": {
46 | "yo": ">=1.0.3"
47 | },
48 | "scripts": {
49 | "coveralls": "gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
50 | "test": "gulp test"
51 | },
52 | "engines": {
53 | "node": ">= 0.10.0",
54 | "npm": ">=1.2.10"
55 | },
56 | "files": [
57 | "app",
58 | "config.js",
59 | "LICENSE"
60 | ]
61 | }
62 |
--------------------------------------------------------------------------------
/test/test-config.js:
--------------------------------------------------------------------------------
1 | /*global describe, beforeEach, it*/
2 | 'use strict';
3 | var path = require('path');
4 | var helpers = require('yeoman-generator').test;
5 | var Config = require('../config');
6 |
7 | describe('generator settings', function () {
8 |
9 | beforeEach(function (done) {
10 | helpers.testDirectory(path.join(__dirname, 'temp'), function (err) {
11 | if (err) {
12 | return done(err);
13 | }
14 | done();
15 | }.bind(this));
16 | });
17 |
18 | it('wirte meta infos', function () {
19 |
20 | var config = new Config('config.json');
21 | config.setMeta({
22 | githubUsername: 'tom',
23 | authorName: 'Tom Jerry',
24 | authorEmail: 'tom@jerry.org',
25 | authorUrl: 'http://jerry.org'
26 | });
27 |
28 | var expectedFiles = [
29 | 'config.json'
30 | ];
31 |
32 | var expectedContent = [
33 | ['config.json',
34 | /"githubUsername": "tom"/,
35 | /"authorName": "Tom Jerry"/,
36 | /"authorEmail": "tom@jerry.org"/,
37 | /"authorUrl": "http:\/\/jerry.org"/
38 | ]
39 | ];
40 |
41 | helpers.assertFile(expectedFiles);
42 | helpers.assertFileContent(expectedContent);
43 | });
44 | });
45 |
--------------------------------------------------------------------------------
/test/test-creation.js:
--------------------------------------------------------------------------------
1 | /*global describe, beforeEach, it*/
2 | 'use strict';
3 |
4 | var path = require('path');
5 | var helpers = require('yeoman-generator').test;
6 |
7 | describe('node generator', function () {
8 | beforeEach(function (done) {
9 | helpers.testDirectory(path.join(__dirname, 'temp'), function (err) {
10 | if (err) {
11 | return done(err);
12 | }
13 |
14 | this.app = helpers.createGenerator('node-gulp:app', [
15 | '../../app'
16 | ]);
17 | this.app.options['skip-install'] = true;
18 | done();
19 | }.bind(this));
20 | });
21 |
22 | it('creates expected files', function (done) {
23 | var expectedFiles = [
24 | 'lib/mymodule.js',
25 | 'test/mymodule_test.js',
26 | 'example/simple.js',
27 | '.gitignore',
28 | '.jshintrc',
29 | '.travis.yml',
30 | '.editorconfig',
31 | 'gulpfile.js',
32 | 'package.json',
33 | 'README.md',
34 | 'CHANGELOG.md'
35 | ];
36 |
37 | var expectedContent = [
38 | ['lib/mymodule.js', /https:\/\/github.com\/octocat\/mymodule/],
39 | ['package.json', /"name": "mymodule"/]
40 | ];
41 |
42 | helpers.mockPrompt(this.app, {
43 | 'name': 'mymodule',
44 | 'description': 'awesome module',
45 | 'license': 'MIT',
46 | 'githubUsername': 'octocat',
47 | 'authorName': 'Octo Cat',
48 | 'authorEmail': 'octo@example.com',
49 | 'modules': [],
50 | 'dependencies': []
51 | });
52 |
53 | this.app.run({}, function () {
54 | helpers.assertFile(expectedFiles);
55 | helpers.assertFileContent(expectedContent);
56 | done();
57 | });
58 | });
59 |
60 | it('creates expected files', function (done) {
61 | var expectedFiles = [
62 | 'lib/mymodule.js',
63 | 'test/mymodule_test.js',
64 | 'example/simple.js',
65 | '.gitignore',
66 | '.jshintrc',
67 | '.travis.yml',
68 | '.editorconfig',
69 | 'gulpfile.js',
70 | 'package.json',
71 | 'README.md',
72 | 'CHANGELOG.md'
73 | ];
74 |
75 | var expectedContent = [
76 | ['lib/mymodule.js', /http:\/\/example.com/],
77 | ['package.json', /"name": "mymodule"/]
78 | ];
79 |
80 | helpers.mockPrompt(this.app, {
81 | 'name': 'mymodule',
82 | 'description': 'awesome module',
83 | 'license': 'MIT',
84 | 'githubUsername': 'octocat',
85 | 'authorName': 'Octo Cat',
86 | 'authorEmail': 'octo@example.com',
87 | 'homepage': 'http://example.com',
88 | 'modules': [],
89 | 'dependencies': []
90 | });
91 |
92 | this.app.run({}, function () {
93 | helpers.assertFile(expectedFiles);
94 | helpers.assertFileContent(expectedContent);
95 | done();
96 | });
97 | });
98 |
99 | it('generator with releaseModule', function (done) {
100 | var expectedFiles = [
101 | 'lib/mymodule.js',
102 | 'test/mymodule_test.js',
103 | 'example/simple.js',
104 | '.gitignore',
105 | '.jshintrc',
106 | '.travis.yml',
107 | '.editorconfig',
108 | 'gulpfile.js',
109 | 'package.json',
110 | 'README.md',
111 | 'CHANGELOG.md'
112 | ];
113 |
114 | var expectedContent = [
115 | ['package.json', /"gulp-bump"/],
116 | ['package.json', /"name": "mymodule"/],
117 | ];
118 |
119 | helpers.mockPrompt(this.app, {
120 | 'name': 'mymodule',
121 | 'description': 'awesome module',
122 | 'license': 'MIT',
123 | 'githubUsername': 'octocat',
124 | 'authorName': 'Octo Cat',
125 | 'authorEmail': 'octo@example.com',
126 | 'modules': ['releaseModule'],
127 | 'dependencies': []
128 | });
129 |
130 | this.app.run({}, function () {
131 | helpers.assertFile(expectedFiles);
132 | helpers.assertFileContent(expectedContent);
133 | done();
134 | });
135 | });
136 |
137 | it('generator with jscsModule', function (done) {
138 | var expectedFiles = [
139 | 'lib/mymodule.js',
140 | 'test/mymodule_test.js',
141 | 'example/simple.js',
142 | '.gitignore',
143 | '.jshintrc',
144 | '.jscsrc',
145 | '.travis.yml',
146 | '.editorconfig',
147 | 'gulpfile.js',
148 | 'package.json',
149 | 'README.md',
150 | 'CHANGELOG.md'
151 | ];
152 |
153 | var expectedContent = [
154 | ['package.json', /"name": "mymodule"/],
155 | ['package.json', /"gulp-jscs"/]
156 | ];
157 |
158 | helpers.mockPrompt(this.app, {
159 | 'name': 'mymodule',
160 | 'description': 'awesome module',
161 | 'license': 'MIT',
162 | 'githubUsername': 'octocat',
163 | 'authorName': 'Octo Cat',
164 | 'authorEmail': 'octo@example.com',
165 | 'modules': ['jscsModule'],
166 | 'dependencies': []
167 | });
168 |
169 | this.app.run({}, function () {
170 | helpers.assertFile(expectedFiles);
171 | helpers.assertFileContent(expectedContent);
172 | done();
173 | });
174 | });
175 |
176 | it('generator with package lodash', function (done) {
177 | var expectedContent = [
178 | ['package.json', /"lodash"/]
179 | ];
180 |
181 | helpers.mockPrompt(this.app, {
182 | 'name': 'mymodule',
183 | 'description': 'awesome module',
184 | 'license': 'MIT',
185 | 'githubUsername': 'octocat',
186 | 'authorName': 'Octo Cat',
187 | 'authorEmail': 'octo@example.com',
188 | 'modules': [],
189 | 'dependencies': ['lodash']
190 | });
191 |
192 | this.app.run({}, function () {
193 | helpers.assertFileContent(expectedContent);
194 | done();
195 | });
196 | });
197 |
198 | it('generator with package q', function (done) {
199 | var expectedContent = [
200 | ['package.json', /"q"/]
201 | ];
202 |
203 | helpers.mockPrompt(this.app, {
204 | 'name': 'mymodule',
205 | 'description': 'awesome module',
206 | 'license': 'MIT',
207 | 'githubUsername': 'octocat',
208 | 'authorName': 'Octo Cat',
209 | 'authorEmail': 'octo@example.com',
210 | 'modules': [],
211 | 'dependencies': ['q']
212 | });
213 |
214 | this.app.run({}, function () {
215 | helpers.assertFileContent(expectedContent);
216 | done();
217 | });
218 | });
219 |
220 | it('generator with package lodash and q', function (done) {
221 | var expectedContent = [
222 | ['package.json', /"lodash"/],
223 | ['package.json', /"q"/]
224 | ];
225 |
226 | helpers.mockPrompt(this.app, {
227 | 'name': 'mymodule',
228 | 'description': 'awesome module',
229 | 'license': 'MIT',
230 | 'githubUsername': 'octocat',
231 | 'authorName': 'Octo Cat',
232 | 'authorEmail': 'octo@example.com',
233 | 'modules': [],
234 | 'dependencies': ['lodash', 'q']
235 | });
236 |
237 | this.app.run({}, function () {
238 | helpers.assertFileContent(expectedContent);
239 | done();
240 | });
241 | });
242 |
243 | it('generator with istanbul', function (done) {
244 | var expectedFiles = [
245 | 'lib/mymodule.js',
246 | 'test/mymodule_test.js',
247 | 'example/simple.js',
248 | '.gitignore',
249 | '.jshintrc',
250 | '.travis.yml',
251 | '.editorconfig',
252 | 'gulpfile.js',
253 | 'package.json',
254 | 'README.md',
255 | 'CHANGELOG.md'
256 | ];
257 |
258 | var expectedContent = [
259 | ['.gitignore', /^(?!coverage\/)/],
260 | ['gulpfile.js', /gulp.task\('istanbul'/],
261 | ['gulpfile.js', /gulp.task\('test', \['lint', 'istanbul'\]\);/],
262 | ['package.json', /"name": "mymodule"/],
263 | ['package.json', /"gulp-istanbul"/]
264 | ];
265 |
266 | helpers.mockPrompt(this.app, {
267 | 'name': 'mymodule',
268 | 'description': 'awesome module',
269 | 'license': 'MIT',
270 | 'githubUsername': 'octocat',
271 | 'authorName': 'Octo Cat',
272 | 'authorEmail': 'octo@example.com',
273 | 'modules': ['istanbulModule'],
274 | 'dependencies': []
275 | });
276 |
277 | this.app.run({}, function () {
278 | helpers.assertFile(expectedFiles);
279 | helpers.assertFileContent(expectedContent);
280 | done();
281 | });
282 | });
283 |
284 | it('generator with istanbul and coveralls', function (done) {
285 | var expectedFiles = [
286 | 'lib/mymodule.js',
287 | 'test/mymodule_test.js',
288 | 'example/simple.js',
289 | '.gitignore',
290 | '.jshintrc',
291 | '.travis.yml',
292 | '.editorconfig',
293 | 'gulpfile.js',
294 | 'README.md',
295 | 'CHANGELOG.md',
296 | 'package.json'
297 | ];
298 | var expectedContent = [
299 | ['.travis.yml', /npm run coveralls/],
300 | ['.gitignore', /coverage\//],
301 | ['gulpfile.js', /gulp.task\('istanbul'/],
302 | ['gulpfile.js', /gulp.task\('test', \['lint', 'istanbul'\]\);/],
303 | ['package.json', /"name": "mymodule"/],
304 | ['package.json', /"gulp-istanbul"/],
305 | ['package.json', /"coveralls": "gulp test/]
306 | ];
307 |
308 | helpers.mockPrompt(this.app, {
309 | 'name': 'mymodule',
310 | 'description': 'awesome module',
311 | 'license': 'MIT',
312 | 'githubUsername': 'octocat',
313 | 'authorName': 'Octo Cat',
314 | 'authorEmail': 'octo@example.com',
315 | 'modules': ['istanbulModule'],
316 | 'coverallsModule': true,
317 | 'dependencies': []
318 | });
319 |
320 | this.app.run({}, function () {
321 | helpers.assertFile(expectedFiles);
322 | helpers.assertFileContent(expectedContent);
323 | done();
324 | });
325 | });
326 |
327 | });
328 |
--------------------------------------------------------------------------------
/test/test-generated-project.js:
--------------------------------------------------------------------------------
1 | /*global describe, beforeEach, it*/
2 | 'use strict';
3 |
4 | var path = require('path');
5 | var spawn = require('child_process').spawn;
6 | var helpers = require('yeoman-generator').test;
7 |
8 | var NPM_INSTALL_TIMEOUT = 60000;
9 |
10 | describe('execute generated project', function () {
11 |
12 | beforeEach(function (done) {
13 |
14 | helpers.testDirectory(path.join(__dirname, 'temp'), function (err) {
15 | if (err) {
16 | return done(err);
17 | }
18 |
19 | this.app = helpers.createGenerator('node-gulp:app', [
20 | '../../app'
21 | ]);
22 | this.app.options['skip-install'] = false;
23 | done();
24 | }.bind(this));
25 | });
26 |
27 | it('execute npm test', function (done) {
28 | this.timeout(NPM_INSTALL_TIMEOUT + 5000);
29 |
30 | helpers.mockPrompt(this.app, {
31 | 'name': 'mymodule',
32 | 'description': 'awesome module',
33 | 'license': 'MIT',
34 | 'githubUsername': 'octocat',
35 | 'authorName': 'Octo Cat',
36 | 'authorEmail': 'octo@example.com',
37 | 'modules': [],
38 | 'dependencies': []
39 | });
40 |
41 | this.app.run({}, function () {
42 | var npmTest = spawn('npm', ['test']);
43 | var testError = '';
44 |
45 | npmTest.stderr.on('data', function (data) {
46 | testError += data.toString();
47 | });
48 |
49 | npmTest.on('close', function (code) {
50 | if (testError) {
51 | return done(new Error('Project test failed:\n' + testError));
52 | } else if (code > 0) {
53 | return done(new Error('Child process exited with code ' + code));
54 | }
55 | done();
56 | });
57 |
58 | });
59 | });
60 |
61 | });
62 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------