11'use strict' ;
2+ var fs = require ( 'fs' ) ;
23var path = require ( 'path' ) ;
34var util = require ( 'util' ) ;
45var angularUtils = require ( '../util.js' ) ;
5- var spawn = require ( 'child_process' ) . spawn ;
66var yeoman = require ( 'yeoman-generator' ) ;
7+ var chalk = require ( 'chalk' ) ;
8+ var wiredep = require ( 'wiredep' ) ;
79
810
911var Generator = module . exports = function Generator ( args , options ) {
@@ -81,7 +83,10 @@ var Generator = module.exports = function Generator(args, options) {
8183 } ) ;
8284
8385 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+ } ) ;
8590
8691 var enabledComponents = [ ] ;
8792
@@ -112,14 +117,50 @@ var Generator = module.exports = function Generator(args, options) {
112117 ] . concat ( enabledComponents )
113118 }
114119 } ) ;
120+
115121 } ) ;
116122
117- this . pkg = JSON . parse ( this . readFileAsString ( path . join ( __dirname , '../package.json' ) ) ) ;
123+ this . pkg = require ( '../package.json' ) ;
118124} ;
119125
120126util . inherits ( Generator , yeoman . generators . Base ) ;
121127
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+
122162Generator . prototype . askForBootstrap = function askForBootstrap ( ) {
163+ var compass = this . compass ;
123164 var cb = this . async ( ) ;
124165
125166 this . prompt ( [ {
@@ -130,10 +171,10 @@ Generator.prototype.askForBootstrap = function askForBootstrap() {
130171 } , {
131172 type : 'confirm' ,
132173 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?' ,
134175 default : true ,
135176 when : function ( props ) {
136- return props . bootstrap ;
177+ return props . bootstrap && compass ;
137178 }
138179 } ] , function ( props ) {
139180 this . bootstrap = props . bootstrap ;
@@ -190,6 +231,7 @@ Generator.prototype.askForModules = function askForModules() {
190231 }
191232 if ( this . routeModule ) {
192233 angMods . push ( "'ngRoute'" ) ;
234+ this . env . options . ngRoute = true ;
193235 }
194236
195237 if ( angMods . length ) {
@@ -216,6 +258,7 @@ Generator.prototype.askForMongo = function askForMongo() {
216258} ;
217259
218260Generator . prototype . readIndex = function readIndex ( ) {
261+ this . ngRoute = this . env . options . ngRoute ;
219262 this . jade = this . env . options . jade ;
220263
221264 if ( this . jade ) {
@@ -225,26 +268,18 @@ Generator.prototype.readIndex = function readIndex() {
225268 }
226269} ;
227270
228- // Waiting a more flexible solution for #138
229271Generator . 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' ;
233274
234275 if ( this . bootstrap && ! sass ) {
235- files . push ( 'bootstrap.css' ) ;
236276 this . copy ( 'fonts/glyphicons-halflings-regular.eot' , 'app/fonts/glyphicons-halflings-regular.eot' ) ;
237277 this . copy ( 'fonts/glyphicons-halflings-regular.ttf' , 'app/fonts/glyphicons-halflings-regular.ttf' ) ;
238278 this . copy ( 'fonts/glyphicons-halflings-regular.svg' , 'app/fonts/glyphicons-halflings-regular.svg' ) ;
239279 this . copy ( 'fonts/glyphicons-halflings-regular.woff' , 'app/fonts/glyphicons-halflings-regular.woff' ) ;
240280 }
241281
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 ) ;
248283 var appendOptions = {
249284 html : this . indexFile ,
250285 fileType : 'css' ,
@@ -262,75 +297,6 @@ Generator.prototype.bootstrapFiles = function bootstrapFiles() {
262297 }
263298} ;
264299
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-
334300function generateJadeBlock ( blockType , optimizedPath , filesBlock , searchPath , prefix ) {
335301 var blockStart , blockEnd ;
336302 var blockSearchPath = '' ;
@@ -452,6 +418,27 @@ Generator.prototype.imageFiles = function () {
452418 this . directory ( 'images' , 'app/images' , true ) ;
453419} ;
454420
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+
455442Generator . prototype . serverFiles = function ( ) {
456443 this . template ( '../../templates/express/server.js' , 'server.js' ) ;
457444 this . template ( '../../templates/express/api.js' , 'lib/controllers/api.js' ) ;
0 commit comments