This repository was archived by the owner on Mar 26, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathindex.js
288 lines (241 loc) · 7.88 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
'use strict';
var fs = require('fs');
var path = require('path');
var util = require('util');
var angularUtils = require('../util.js');
var yeoman = require('yeoman-generator');
var wiredep = require('wiredep');
var Generator = module.exports = function Generator(args, options) {
yeoman.generators.Base.apply(this, arguments);
this.argument('appname', { type: String, required: false });
this.appname = this.appname || path.basename(process.cwd());
this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname)));
this.option('app-suffix', {
desc: 'Allow a custom suffix to be added to the module name',
type: String,
required: 'false'
});
this.scriptAppName = this.appname + angularUtils.appName(this);
args = ['main'];
if (typeof this.env.options.appPath === 'undefined') {
try {
this.env.options.appPath = require(path.join(process.cwd(), 'bower.json')).appPath;
} catch (e) {}
this.env.options.appPath = this.env.options.appPath || 'app';
}
this.appPath = this.env.options.appPath;
if (typeof this.env.options.coffee === 'undefined') {
this.option('coffee', {
desc: 'Generate CoffeeScript instead of JavaScript'
});
// attempt to detect if user is using CS or not
// if cml arg provided, use that; else look for the existence of cs
if (!this.options.coffee &&
this.expandFiles(path.join(this.appPath, '/scripts/**/*.coffee'), {}).length > 0) {
this.options.coffee = true;
}
this.env.options.coffee = this.options.coffee;
}
this.hookFor('angular:common', {
args: args
});
this.hookFor('angular:main', {
args: args
});
this.hookFor('angular:controller', {
args: args
});
this.on('end', function () {
this.installDependencies({
skipInstall: this.options['skip-install'],
callback: this._injectDependencies.bind(this)
});
var enabledComponents = [];
if (this.resourceModule) {
enabledComponents.push('angular-resource/angular-resource.js');
}
if (this.cookiesModule) {
enabledComponents.push('angular-cookies/angular-cookies.js');
}
if (this.sanitizeModule) {
enabledComponents.push('angular-sanitize/angular-sanitize.js');
}
if (this.routeModule) {
enabledComponents.push('angular-route/angular-route.js');
}
this.invoke('karma:app', {
options: {
coffee: this.options.coffee,
travis: true,
'skip-install': this.options['skip-install'],
components: [
'angular/angular.js',
'angular-mocks/angular-mocks.js'
].concat(enabledComponents)
}
});
});
this.pkg = require('../package.json');
};
util.inherits(Generator, yeoman.generators.Base);
Generator.prototype.welcome = function welcome() {
// welcome message
if (!this.options['skip-welcome-message']) {
console.log(this.yeoman);
console.log(
'Out of the box I include Bootstrap and some AngularJS recommended modules.\n'
);
// Removed notice for minsafe
if (this.options.minsafe) {
console.warn(
'\n** The --minsafe flag has been removed. For more information, see ' +
'https://github.com/yeoman/generator-angular#minification-safe. **\n'
);
}
}
};
Generator.prototype.askForCompass = function askForCompass() {
var cb = this.async();
this.prompt([{
type: 'confirm',
name: 'compass',
message: 'Would you like to use Sass (with Compass)?',
default: true
}], function (props) {
this.compass = props.compass;
cb();
}.bind(this));
};
Generator.prototype.askForBootstrap = function askForBootstrap() {
var compass = this.compass;
var cb = this.async();
this.prompt([{
type: 'confirm',
name: 'bootstrap',
message: 'Would you like to include Bootstrap?',
default: true
}, {
type: 'confirm',
name: 'compassBootstrap',
message: 'Would you like to use the Sass version of Bootstrap?',
default: true,
when: function (props) {
return props.bootstrap && compass;
}
}], function (props) {
this.bootstrap = props.bootstrap;
this.compassBootstrap = props.compassBootstrap;
cb();
}.bind(this));
};
Generator.prototype.askForModules = function askForModules() {
var cb = this.async();
var prompts = [{
type: 'checkbox',
name: 'modules',
message: 'Which modules would you like to include?',
choices: [{
value: 'resourceModule',
name: 'angular-resource.js',
checked: true
}, {
value: 'cookiesModule',
name: 'angular-cookies.js',
checked: true
}, {
value: 'sanitizeModule',
name: 'angular-sanitize.js',
checked: true
}, {
value: 'routeModule',
name: 'angular-route.js',
checked: true
}]
}];
this.prompt(prompts, function (props) {
var hasMod = function (mod) { return props.modules.indexOf(mod) !== -1; };
this.resourceModule = hasMod('resourceModule');
this.cookiesModule = hasMod('cookiesModule');
this.sanitizeModule = hasMod('sanitizeModule');
this.routeModule = hasMod('routeModule');
var angMods = [];
if (this.cookiesModule) {
angMods.push("'ngCookies'");
}
if (this.resourceModule) {
angMods.push("'ngResource'");
}
if (this.sanitizeModule) {
angMods.push("'ngSanitize'");
}
if (this.routeModule) {
angMods.push("'ngRoute'");
this.env.options.ngRoute = true;
}
if (angMods.length) {
this.env.options.angularDeps = '\n ' + angMods.join(',\n ') + '\n ';
}
cb();
}.bind(this));
};
Generator.prototype.readIndex = function readIndex() {
this.ngRoute = this.env.options.ngRoute;
this.indexFile = this.engine(this.read('../../templates/common/index.html'), this);
};
Generator.prototype.bootstrapFiles = function bootstrapFiles() {
var sass = this.compass;
var mainFile = 'main.' + (sass ? 's' : '') + 'css';
if (this.bootstrap && !sass) {
this.copy('fonts/glyphicons-halflings-regular.eot', 'app/fonts/glyphicons-halflings-regular.eot');
this.copy('fonts/glyphicons-halflings-regular.ttf', 'app/fonts/glyphicons-halflings-regular.ttf');
this.copy('fonts/glyphicons-halflings-regular.svg', 'app/fonts/glyphicons-halflings-regular.svg');
this.copy('fonts/glyphicons-halflings-regular.woff', 'app/fonts/glyphicons-halflings-regular.woff');
}
this.copy('styles/' + mainFile, 'app/styles/' + mainFile);
};
Generator.prototype.appJs = function appJs() {
this.indexFile = this.appendFiles({
html: this.indexFile,
fileType: 'js',
optimizedPath: 'scripts/scripts.js',
sourceFileList: ['scripts/app.js', 'scripts/controllers/main.js']
});
};
Generator.prototype.createIndexHtml = function createIndexHtml() {
this.indexFile = this.indexFile.replace(/'/g, "'");
this.write(path.join(this.appPath, 'index.html'), this.indexFile);
};
Generator.prototype.packageFiles = function () {
this.coffee = this.env.options.coffee;
this.template('../../templates/common/_bower.json', 'bower.json');
this.template('../../templates/common/_package.json', 'package.json');
this.template('../../templates/common/Gruntfile.js', 'Gruntfile.js');
};
Generator.prototype.imageFiles = function () {
this.sourceRoot(path.join(__dirname, 'templates'));
this.directory('images', 'app/images', true);
};
Generator.prototype._injectDependencies = function _injectDependencies() {
if (this.options['skip-install']) {
console.log(
'\nAfter running `npm install & bower install`, inject your front end dependencies into' +
'\nyour HTML by running:' +
'\n' +
'\n grunt bowerInstall'
);
} else {
wiredep({
directory: 'app/bower_components',
bowerJson: JSON.parse(fs.readFileSync('./bower.json')),
ignorePath: 'app/',
src: 'app/index.html',
fileTypes: {
html: {
replace: {
css: '<link rel="stylesheet" href="{{filePath}}">'
}
}
}
});
}
};