1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 | 3
3
3
3
1
3
3
3
1
1
1
1
1
1
1
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
3
| var mkdirp = require('mkdirp');
var p = require('path');
var util = require('util');
var yeoman = require('yeoman-generator');
/**
* class Generator
*
* @param {Object} args:
* @param {Object} options:
* @param {Object} config:
*/
function Generator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);
}
util.inherits(Generator, yeoman.generators.Base);
/**
* Sets up user input prompts.
*/
Generator.prototype.askFor = function () {
var cb = this.async();
var prompts = [
{
name: 'projectName',
message: 'Project name'
},
{
name: 'projectDesc',
message: 'Project description'
},
{
name: 'authorName',
message: 'Author name'
},
{
name: 'authorEmail',
message: 'Author email'
},
{
name: 'authorWebsite',
message: 'Author website'
},
{
name: 'githubUsername',
message: 'GitHub username'
},
{
name: 'copyrightYear',
message: 'Copyright year',
default: (new Date()).getFullYear()
},
{
type: 'confirm',
name: 'hasCli',
message: 'Has command-line interface?',
default: true
}
];
this.prompt(prompts, function (params) {
this.params = params;
this.params.projectClass =
this.params.projectName.charAt(0).toUpperCase() +
this.params.projectName.slice(1).toLowerCase();
this.params.projectTitle = this.params.projectClass;
cb();
}.bind(this));
};
/**
* Creates directories and templatised files.
* Also handles specific project types, e.g. projects having CLI.
*/
Generator.prototype.app = function () {
mkdirp('lib');
mkdirp('test');
mkdirp('test-integration');
this.template('_.bob.json', '.bob.json');
this.template('_.gitignore', '.gitignore');
this.template('_.jshintrc', '.jshintrc');
this.template('_.npmignore', '.npmignore');
this.template('_.travis.yml', '.travis.yml');
this.template('_CHANGELOG.md', 'CHANGELOG.md');
this.template('_LICENSE', 'LICENSE');
this.template('_README.md', 'README.md');
this.template('_package.json', 'package.json');
this.template(p.join('lib', '_project.js'), p.join('lib', this.params.projectName + '.js'));
if (this.params.hasCli) {
mkdirp('bin');
mkdirp('conf');
this.template(p.join('bin', '_project'), p.join('bin', this.params.projectName));
this.template(p.join('conf', '_commands.json'), p.join('conf', 'commands.json'));
this.template(p.join('lib', '_cli.js'), p.join('lib', 'cli.js'));
}
};
module.exports = Generator;
|