Skip to content

Commit 1c9ec4c

Browse files
committed
Update to the yeoman-generator 0.16 extend inheritance method
Use Mocha spec reporter and repository short form in package.json Update assert function
1 parent 652b0ea commit 1c9ec4c

File tree

3 files changed

+52
-88
lines changed

3 files changed

+52
-88
lines changed

app/index.js

+48-80
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,23 @@
11
'use strict';
2-
32
var grunt = require('grunt');
4-
var path = require('path');
5-
var util = require('util');
63
var yeoman = require('yeoman-generator');
74

8-
/**
9-
* Generator constructor
10-
*
11-
* @api public
12-
*/
13-
14-
function Generator() {
15-
yeoman.generators.Base.apply(this, arguments);
16-
this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
17-
}
18-
19-
/**
20-
* Inherit from `yeoman.generators.Base`
21-
*/
22-
23-
util.inherits(Generator, yeoman.generators.Base);
5+
var GruntfileGenerator = yeoman.generators.Base.extend({
6+
initializing: function () {
7+
this.pkg = require('../package.json');
8+
},
249

25-
/**
26-
* Prompts for information
27-
*
28-
* @api public
29-
*/
10+
prompting: function () {
11+
var done = this.async();
3012

31-
Generator.prototype.askFor = function () {
32-
var self = this;
33-
var cb = this.async();
13+
this.log(this.yeoman);
14+
this.log('This template tries to guess file and directory paths, but ' +
15+
'you will most likely need to edit the generated Gruntfile.js file before ' +
16+
'running grunt. _If you run grunt after generating the Gruntfile, and ' +
17+
'it exits with errors, edit the file!_');
3418

35-
console.log(this.yeoman);
36-
console.log('This template tries to guess file and directory paths, but ' +
37-
'you will most likely need to edit the generated Gruntfile.js file before ' +
38-
'running grunt. _If you run grunt after generating the Gruntfile, and ' +
39-
'it exits with errors, edit the file!_');
4019

41-
42-
var prompts = [
43-
{
20+
var prompts = [{
4421
type: 'checkbox',
4522
name: 'features',
4623
message: 'What more would you like?',
@@ -57,62 +34,53 @@ Generator.prototype.askFor = function () {
5734
value: 'packageJSON',
5835
checked: false
5936
}]
60-
}
61-
];
37+
}];
6238

63-
function prefer(arr, preferred) {
64-
for (var i = 0; i < preferred.length; i++) {
65-
if (arr.indexOf(preferred[i]) !== -1) {
66-
return preferred[i];
39+
function prefer(arr, preferred) {
40+
for (var i = 0; i < preferred.length; ++i) {
41+
if (arr.indexOf(preferred[i]) !== -1) {
42+
return preferred[i];
43+
}
6744
}
45+
return preferred[0];
6846
}
6947

70-
return preferred[0];
71-
}
72-
73-
var dirs = grunt.file.expand({ filter: 'isDirectory' }, '*').map(function (d) {
74-
return d.slice(0, -1);
75-
});
76-
77-
this.jquery = grunt.file.expand({ filter: 'isFile' }, '**/jquery*.js').length > 0;
78-
this.libDir = prefer(dirs, ['lib', 'src']);
79-
this.testDir = prefer(dirs, ['test', 'tests', 'unit', 'spec']);
48+
var dirs = grunt.file.expand({ filter: 'isDirectory' }, '*').map(function (d) {
49+
return d.slice(0, -1);
50+
});
8051

81-
this.prompt(prompts, function (answers) {
82-
var features = answers.features;
83-
84-
function hasFeature(feat) {
85-
return features.indexOf(feat) !== -1;
86-
}
52+
this.jquery = grunt.file.expand({ filter: 'isFile' }, '**/jquery*.js').length > 0;
53+
this.libDir = prefer(dirs, ['lib', 'src']);
54+
this.testDir = prefer(dirs, ['test', 'tests', 'unit', 'spec']);
8755

88-
self.dom = hasFeature('dom');
89-
self.minConcat = hasFeature('minConcat');
90-
self.packageJSON = hasFeature('packageJSON');
56+
this.prompt(prompts, function (answers) {
57+
var features = answers.features;
9158

92-
self.testTask = hasFeature('dom') ? 'qunit' : 'nodeunit';
59+
function hasFeature(feat) {
60+
return features.indexOf(feat) !== -1;
61+
}
9362

94-
self.fileName = hasFeature('packageJSON') ? '<%= pkg.name %>' : 'FILE_NAME';
63+
this.dom = hasFeature('dom');
64+
this.minConcat = hasFeature('minConcat');
65+
this.packageJSON = hasFeature('packageJSON');
66+
this.testTask = hasFeature('dom') ? 'qunit' : 'nodeunit';
67+
this.fileName = hasFeature('packageJSON') ? '<%= pkg.name %>' : 'FILE_NAME';
9568

96-
cb();
97-
});
98-
};
69+
done();
70+
}.bind(this));
71+
},
9972

100-
/**
101-
* Generate the project files
102-
*
103-
* @api public
104-
*/
73+
configuring: function () {
74+
this.config.save();
75+
},
10576

106-
Generator.prototype.projectfiles = function () {
107-
if (!this.packageJSON) {
108-
this.template('package.json');
77+
writing: function () {
78+
if (!this.packageJSON) {
79+
this.template('package.json');
80+
}
81+
this.template('gruntfile.js');
10982
}
110-
this.template('gruntfile.js');
111-
};
112-
113-
/**
114-
* Module exports
115-
*/
83+
});
11684

117-
module.exports = Generator;
85+
module.exports = GruntfileGenerator;
11886

package.json

+3-7
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
"files": [
2323
"app"
2424
],
25-
"repository": {
26-
"type": "git",
27-
"url": "https://github.com/yeoman/generator-gruntfile.git"
28-
},
25+
"repository": "yeoman/generator-gruntfile",
2926
"scripts": {
30-
"test": "mocha"
27+
"test": "mocha --reporter spec"
3128
},
3229
"dependencies": {
3330
"yeoman-generator": "~0.16.0",
@@ -40,8 +37,7 @@
4037
"yo": ">=1.0.0"
4138
},
4239
"engines": {
43-
"node": ">=0.10.0",
44-
"npm": ">=1.2.10"
40+
"node": ">=0.10.0"
4541
},
4642
"licenses": [
4743
{

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('gruntfile:app', function () {
2626
});
2727

2828
generator.run({}, function () {
29-
helpers.assertFiles(expected);
29+
helpers.assertFile(expected);
3030
cb();
3131
});
3232
});

0 commit comments

Comments
 (0)