1+ 'use strict' ;
2+ var yeoman = require ( 'yeoman-generator' ) ;
3+ var chalk = require ( 'chalk' ) ;
4+ var yosay = require ( 'yosay' ) ;
5+ var path = require ( 'path' ) ;
6+ var fs = require ( 'fs' ) ;
7+ var naming = require ( '../util/naming' ) ;
8+ var moduleUtil = require ( './module-util' ) ;
9+ var gen ;
10+ module . exports = yeoman . generators . Base . extend ( {
11+ initializing : function ( ) {
12+ this . pkg = require ( '../package.json' ) ;
13+ gen = this ;
14+ } ,
15+
16+ promptiing : function ( ) {
17+ var done = this . async ( ) ;
18+
19+ // Have Yeoman greet the user.
20+ this . log ( yosay ( 'Time to scaffold a ' + chalk . red ( 'module' ) + '!' ) ) ;
21+
22+ var prompts = [ {
23+ type : 'input' ,
24+ name : 'moduleName' ,
25+ message : 'What would you like the name of your module to be?' ,
26+ validate : function ( moduleName ) {
27+ if ( ! moduleName || ! moduleName . trim ( ) ) {
28+ return false ;
29+ }
30+ gen . moduleName = moduleName ;
31+ return true ;
32+ }
33+ } , {
34+ when : function ( props ) {
35+ gen . defaultUrl = '/' + naming . toDasherized ( props . moduleName ) ;
36+ return true ;
37+ } ,
38+ type : 'input' ,
39+ name : 'url' ,
40+ message : 'What do you want the URL to be?' ,
41+ default : function ( ) {
42+ return gen . defaultUrl ;
43+ }
44+ } , {
45+ when : function ( props ) {
46+ gen . defaultPath = moduleUtil . getDefaultModuleFolder ( props . moduleName ) ;
47+ return true ;
48+ } ,
49+ type : 'input' ,
50+ name : 'path' ,
51+ message : 'Where would you like this module to be placed?' ,
52+ default : function ( ) {
53+ return gen . defaultPath ;
54+ }
55+ } ] ;
56+
57+ this . prompt ( prompts , function ( props ) {
58+ this . props = props ;
59+ this . props . dasherizedModuleName = naming . toDasherized ( this . props . moduleName ) ;
60+ this . props . lowerCamelCaseModuleName = naming . toLowerCamelCase ( this . props . moduleName ) ;
61+ var moduleFilename = this . props . dasherizedModuleName + '.module.js' ;
62+ this . props . fullPath = path . join ( 'src' , 'scripts' , this . props . path , moduleFilename ) ;
63+
64+ done ( ) ;
65+ } . bind ( this ) ) ;
66+ } ,
67+
68+ writing : {
69+ module : function ( ) {
70+ this . template ( this . templatePath ( 'full.module.js' ) , this . destinationPath ( this . props . fullPath ) , this . props ) ;
71+ }
72+ }
73+
74+ } ) ;
0 commit comments