1
1
'use strict' ;
2
+ var fs = require ( 'fs' ) ;
2
3
var path = require ( 'path' ) ;
3
4
var util = require ( 'util' ) ;
4
5
var angularUtils = require ( '../util.js' ) ;
5
- var spawn = require ( 'child_process' ) . spawn ;
6
6
var yeoman = require ( 'yeoman-generator' ) ;
7
+ var chalk = require ( 'chalk' ) ;
8
+ var wiredep = require ( 'wiredep' ) ;
7
9
8
10
9
11
var Generator = module . exports = function Generator ( args , options ) {
@@ -81,7 +83,10 @@ var Generator = module.exports = function Generator(args, options) {
81
83
} ) ;
82
84
83
85
this . on ( 'end' , function ( ) {
84
- this . installDependencies ( { skipInstall : this . options [ 'skip-install' ] } ) ;
86
+ this . installDependencies ( {
87
+ skipInstall : this . options [ 'skip-install' ] ,
88
+ callback : this . _injectDependencies . bind ( this )
89
+ } ) ;
85
90
86
91
var enabledComponents = [ ] ;
87
92
@@ -112,14 +117,50 @@ var Generator = module.exports = function Generator(args, options) {
112
117
] . concat ( enabledComponents )
113
118
}
114
119
} ) ;
120
+
115
121
} ) ;
116
122
117
- this . pkg = JSON . parse ( this . readFileAsString ( path . join ( __dirname , '../package.json' ) ) ) ;
123
+ this . pkg = require ( '../package.json' ) ;
118
124
} ;
119
125
120
126
util . inherits ( Generator , yeoman . generators . Base ) ;
121
127
128
+ Generator . prototype . welcome = function welcome ( ) {
129
+ // welcome message
130
+ if ( ! this . options [ 'skip-welcome-message' ] ) {
131
+ console . log ( this . yeoman ) ;
132
+ console . log (
133
+ 'Out of the box I include Bootstrap and some AngularJS recommended modules.\n'
134
+ ) ;
135
+
136
+ // Deprecation notice for minsafe
137
+ if ( this . options . minsafe ) {
138
+ console . warn (
139
+ '\n** The --minsafe flag is being deprecated in 0.7.0 and removed in ' +
140
+ '0.8.0. For more information, see ' +
141
+ 'https://github.com/yeoman/generator-angular#minification-safe. **\n'
142
+ ) ;
143
+ }
144
+ }
145
+ } ;
146
+
147
+ Generator . prototype . askForCompass = function askForCompass ( ) {
148
+ var cb = this . async ( ) ;
149
+
150
+ this . prompt ( [ {
151
+ type : 'confirm' ,
152
+ name : 'compass' ,
153
+ message : 'Would you like to use Sass (with Compass)?' ,
154
+ default : true
155
+ } ] , function ( props ) {
156
+ this . compass = props . compass ;
157
+
158
+ cb ( ) ;
159
+ } . bind ( this ) ) ;
160
+ } ;
161
+
122
162
Generator . prototype . askForBootstrap = function askForBootstrap ( ) {
163
+ var compass = this . compass ;
123
164
var cb = this . async ( ) ;
124
165
125
166
this . prompt ( [ {
@@ -130,10 +171,10 @@ Generator.prototype.askForBootstrap = function askForBootstrap() {
130
171
} , {
131
172
type : 'confirm' ,
132
173
name : 'compassBootstrap' ,
133
- message : 'Would you like to use the SCSS version of Twitter Bootstrap with the Compass CSS Authoring Framework ?' ,
174
+ message : 'Would you like to use the Sass version of Twitter Bootstrap?' ,
134
175
default : true ,
135
176
when : function ( props ) {
136
- return props . bootstrap ;
177
+ return props . bootstrap && compass ;
137
178
}
138
179
} ] , function ( props ) {
139
180
this . bootstrap = props . bootstrap ;
@@ -190,6 +231,7 @@ Generator.prototype.askForModules = function askForModules() {
190
231
}
191
232
if ( this . routeModule ) {
192
233
angMods . push ( "'ngRoute'" ) ;
234
+ this . env . options . ngRoute = true ;
193
235
}
194
236
195
237
if ( angMods . length ) {
@@ -216,6 +258,7 @@ Generator.prototype.askForMongo = function askForMongo() {
216
258
} ;
217
259
218
260
Generator . prototype . readIndex = function readIndex ( ) {
261
+ this . ngRoute = this . env . options . ngRoute ;
219
262
this . jade = this . env . options . jade ;
220
263
221
264
if ( this . jade ) {
@@ -225,26 +268,18 @@ Generator.prototype.readIndex = function readIndex() {
225
268
}
226
269
} ;
227
270
228
- // Waiting a more flexible solution for #138
229
271
Generator . prototype . bootstrapFiles = function bootstrapFiles ( ) {
230
- var sass = this . compassBootstrap ;
231
- var files = [ ] ;
232
- var source = 'styles/' + ( sass ? 's' : '' ) + 'css/' ;
272
+ var sass = this . compass ;
273
+ var mainFile = 'main.' + ( sass ? 's' : '' ) + 'css' ;
233
274
234
275
if ( this . bootstrap && ! sass ) {
235
- files . push ( 'bootstrap.css' ) ;
236
276
this . copy ( 'fonts/glyphicons-halflings-regular.eot' , 'app/fonts/glyphicons-halflings-regular.eot' ) ;
237
277
this . copy ( 'fonts/glyphicons-halflings-regular.ttf' , 'app/fonts/glyphicons-halflings-regular.ttf' ) ;
238
278
this . copy ( 'fonts/glyphicons-halflings-regular.svg' , 'app/fonts/glyphicons-halflings-regular.svg' ) ;
239
279
this . copy ( 'fonts/glyphicons-halflings-regular.woff' , 'app/fonts/glyphicons-halflings-regular.woff' ) ;
240
280
}
241
281
242
- files . push ( 'main.' + ( sass ? 's' : '' ) + 'css' ) ;
243
-
244
- files . forEach ( function ( file ) {
245
- this . copy ( source + file , 'app/styles/' + file ) ;
246
- } . bind ( this ) ) ;
247
-
282
+ this . copy ( 'styles/' + mainFile , 'app/styles/' + mainFile ) ;
248
283
var appendOptions = {
249
284
html : this . indexFile ,
250
285
fileType : 'css' ,
@@ -262,75 +297,6 @@ Generator.prototype.bootstrapFiles = function bootstrapFiles() {
262
297
}
263
298
} ;
264
299
265
- Generator . prototype . bootstrapJS = function bootstrapJS ( ) {
266
- if ( ! this . bootstrap ) {
267
- return ; // Skip if disabled.
268
- }
269
-
270
- // Wire Twitter Bootstrap plugins
271
- var appendOptions = {
272
- html : this . indexFile ,
273
- fileType : 'js' ,
274
- optimizedPath : 'scripts/plugins.js' ,
275
- sourceFileList : [
276
- 'bower_components/sass-bootstrap/js/affix.js' ,
277
- 'bower_components/sass-bootstrap/js/alert.js' ,
278
- 'bower_components/sass-bootstrap/js/button.js' ,
279
- 'bower_components/sass-bootstrap/js/carousel.js' ,
280
- 'bower_components/sass-bootstrap/js/transition.js' ,
281
- 'bower_components/sass-bootstrap/js/collapse.js' ,
282
- 'bower_components/sass-bootstrap/js/dropdown.js' ,
283
- 'bower_components/sass-bootstrap/js/modal.js' ,
284
- 'bower_components/sass-bootstrap/js/scrollspy.js' ,
285
- 'bower_components/sass-bootstrap/js/tab.js' ,
286
- 'bower_components/sass-bootstrap/js/tooltip.js' ,
287
- 'bower_components/sass-bootstrap/js/popover.js'
288
- ] ,
289
- searchPath : 'app'
290
- } ;
291
-
292
- if ( this . jade ) {
293
- this . indexFile = appendFilesToJade ( appendOptions ) ;
294
- } else {
295
- this . indexFile = this . appendFiles ( appendOptions ) ;
296
- }
297
- } ;
298
-
299
- Generator . prototype . extraModules = function extraModules ( ) {
300
- var modules = [ ] ;
301
- if ( this . resourceModule ) {
302
- modules . push ( 'bower_components/angular-resource/angular-resource.js' ) ;
303
- }
304
-
305
- if ( this . cookiesModule ) {
306
- modules . push ( 'bower_components/angular-cookies/angular-cookies.js' ) ;
307
- }
308
-
309
- if ( this . sanitizeModule ) {
310
- modules . push ( 'bower_components/angular-sanitize/angular-sanitize.js' ) ;
311
- }
312
-
313
- if ( this . routeModule ) {
314
- modules . push ( 'bower_components/angular-route/angular-route.js' ) ;
315
- }
316
-
317
- if ( modules . length ) {
318
- var appendOptions = {
319
- html : this . indexFile ,
320
- fileType : 'js' ,
321
- optimizedPath : 'scripts/modules.js' ,
322
- sourceFileList : modules ,
323
- searchPath : 'app'
324
- } ;
325
-
326
- if ( this . jade ) {
327
- this . indexFile = appendFilesToJade ( appendOptions ) ;
328
- } else {
329
- this . indexFile = this . appendFiles ( appendOptions ) ;
330
- }
331
- }
332
- } ;
333
-
334
300
function generateJadeBlock ( blockType , optimizedPath , filesBlock , searchPath , prefix ) {
335
301
var blockStart , blockEnd ;
336
302
var blockSearchPath = '' ;
@@ -452,6 +418,27 @@ Generator.prototype.imageFiles = function () {
452
418
this . directory ( 'images' , 'app/images' , true ) ;
453
419
} ;
454
420
421
+ Generator . prototype . _injectDependencies = function _injectDependencies ( ) {
422
+ var howToInstall =
423
+ '\nAfter running `npm install & bower install`, inject your front end dependencies into' +
424
+ '\nyour HTML by running:' +
425
+ '\n' +
426
+ chalk . yellow . bold ( '\n grunt bower-install' ) ;
427
+
428
+ if ( this . options [ 'skip-install' ] ) {
429
+ console . log ( howToInstall ) ;
430
+ } else {
431
+ wiredep ( {
432
+ directory : 'app/bower_components' ,
433
+ bowerJson : JSON . parse ( fs . readFileSync ( './bower.json' ) ) ,
434
+ ignorePath : 'app/' ,
435
+ htmlFile : 'app/index.html' ,
436
+ cssPattern : '<link rel="stylesheet" href="{{filePath}}">'
437
+ } ) ;
438
+ }
439
+ } ;
440
+ } ;
441
+
455
442
Generator . prototype . serverFiles = function ( ) {
456
443
this . template ( '../../templates/express/server.js' , 'server.js' ) ;
457
444
this . template ( '../../templates/express/api.js' , 'lib/controllers/api.js' ) ;
0 commit comments