-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.js
159 lines (139 loc) · 3.84 KB
/
index.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'use strict';
var compareVersion = require('compare-version');
var yeoman = require('yeoman-generator');
var isOnline = require('is-online');
var pkgName = require('pkg-name');
module.exports = yeoman.generators.Base.extend({
initializing: function () {
this.pkg = require('../package.json');
this.compareVersion = compareVersion;
},
promptingName: function () {
var cb = this.async();
var prompts = [{
name: 'name',
message: 'Project Name',
default: this.appname,
}, {
type: 'confirm',
name: 'pkgName',
message: 'The name above already exists on npm or Bower, choose another?',
default: true,
when: function (answers) {
var done = this.async();
isOnline(function (error, online) {
if (!online) {
done(false);
return;
}
pkgName(answers.name, function (err, available) {
if (!available.npm || !available.bower) {
done(true);
}
done(false);
});
});
}
}];
this.prompt(prompts, function (props) {
if (props.pkgName) {
return this.promptingName();
}
// For easier access in the templates.
this.slugname = this._.slugify(props.name);
this.camelname = this._.camelize(props.name);
cb();
}.bind(this));
},
prompting: function () {
var cb = this.async();
var prompts = [{
name: 'title',
default: 'Awesome jQuery plugin'
}, {
name: 'description',
default: 'The best jQuery plugin ever.'
}, {
name: 'version'
}, {
name: 'repository'
}, {
name: 'license',
default: 'MIT'
}, {
name: 'github_username',
store: true
}, {
name: 'author_name',
store: true
}, {
name: 'author_email',
store: true
}, {
name: 'jquery_version',
message: 'jQuery Version'
}, {
type: 'list',
name: 'kind',
message: 'What kind of jQuery plugin would you like to create?',
choices: [{
name: 'Collection method',
value: 'collection_method'
}, {
name: 'Static method',
value: 'static_method'
}, {
name: 'Custom selector',
value: 'custom_selector'
}]
}];
var nameToMessage = function (name) {
return name.split('_').map(
function (x) {
return this._.capitalize(x);
}.bind(this)
).join(' ') + ':';
}.bind(this);
// Generate prompt messages if only the name is defined.
prompts.map(function (entry) {
if (entry.message === undefined) {
entry.message = nameToMessage(entry.name);
}
return entry;
}.bind(this));
this.currentYear = (new Date()).getFullYear();
this.prompt(prompts, function (props) {
this.props = props;
cb();
}.bind(this));
},
configuration: function () {
this.copy('editorconfig', '.editorconfig');
this.copy('jshintrc', '.jshintrc');
this.copy('gitignore', '.gitignore');
this.copy('travis.yml', '.travis.yml');
this.template('_package.json', 'package.json');
this.template('bower.json', 'bower.json');
},
source: function () {
this.mkdir('src');
this.copy('src/jshintrc', 'src/.jshintrc');
this.template('src/name.js', 'src/' + this.slugname + '.js');
},
test: function () {
this.mkdir('test');
this.copy('test/jshintrc', 'test/.jshintrc');
this.template('test/name_test.js', 'test/' + this.slugname + '_test.js');
this.template('test/name.html', 'test/' + this.slugname + '.html');
},
writing: function () {
this.template('readme.md');
this.template('Gruntfile.js');
this.copy('contributing.md', 'contributing.md');
},
install: function () {
this.installDependencies({
skipInstall: this.options['skip-install']
});
}
});