@@ -6,16 +6,32 @@ var yeoman = require('yeoman-generator');
66var CraftyGenerator = module . exports = function CraftyGenerator ( args , options , config ) {
77 yeoman . generators . Base . apply ( this , arguments ) ;
88
9- this . on ( 'end' , function ( ) {
10- this . installDependencies ( { skipInstall : options [ 'skip-install' ] } ) ;
11- } ) ;
12-
139 this . pkg = JSON . parse ( this . readFileAsString ( path . join ( __dirname , '../package.json' ) ) ) ;
10+
11+ // setup the test-framework property, Gruntfile template will need this
12+ this . testFramework = options [ 'test-framework' ] || 'mocha' ;
13+
14+ // for hooks to resolve on mocha by default
15+ if ( ! options [ 'test-framework' ] ) {
16+ options [ 'test-framework' ] = 'mocha' ;
17+ }
18+
19+ // hook for karma test runner
20+ this . options . karma = options . karma ;
21+
22+ // resolved to mocha by default (could be switched to jasmine for instance)
23+ this . hookFor ( 'test-framework' , { as : 'app' } ) ;
24+
25+ this . indexFile = this . readFileAsString ( path . join ( this . sourceRoot ( ) , '_index.html' ) ) ;
26+
27+ //this.on('end', function () {
28+ // this.installDependencies({ skipInstall: options['skip-install'] });
29+ //});
1430} ;
1531
1632util . inherits ( CraftyGenerator , yeoman . generators . Base ) ;
1733
18- CraftyGenerator . prototype . askFor = function askFor ( ) {
34+ CraftyGenerator . prototype . askQuestions = function askQuestions ( ) {
1935 var cb = this . async ( ) ;
2036
2137 console . log ( this . yeoman ) ;
@@ -24,45 +40,44 @@ CraftyGenerator.prototype.askFor = function askFor() {
2440 name : 'gameName' ,
2541 message : 'What is the name of your game?' ,
2642 default : ( this . appname )
43+ } , {
44+ name : 'gameWidth' ,
45+ message : 'How wide do you want your game canvas to be?' ,
46+ default : 800
47+ } , {
48+ name : 'gameHeight' ,
49+ message : 'And how tall do you want it to be?' ,
50+ default : 600
2751 } ] ;
2852
2953 this . prompt ( prompts , function ( props ) {
3054 this . gameName = props . gameName ;
55+ this . gameWidth = props . gameWidth ;
56+ this . gameHeight = props . gameHeight ;
3157
3258 cb ( ) ;
3359 } . bind ( this ) ) ;
3460} ;
3561
36- CraftyGenerator . prototype . app = function app ( ) {
62+ CraftyGenerator . prototype . createDirLayout = function createDirLayout ( ) {
63+ this . mkdir ( 'app/styles' ) ;
64+ this . mkdir ( 'app/images' ) ;
65+ this . mkdir ( 'app/scripts/scenes' ) ;
66+ this . mkdir ( 'app/scripts/components' ) ;
67+ this . mkdir ( 'app/libs' ) ;
68+ this . mkdir ( 'app/bower_components' ) ;
3769} ;
3870
39- CraftyGenerator . prototype . projectfiles = function projectfiles ( ) {
40- this . mkdir ( 'app' ) ;
41- this . mkdir ( 'app/web' ) ;
42- this . mkdir ( 'app/web/css' ) ;
43- this . mkdir ( 'app/web/images' ) ;
44-
71+ CraftyGenerator . prototype . editorConfig = function editorConfig ( ) {
4572 this . copy ( '_.editorconfig' , '.editorconfig' ) ;
46- this . copy ( '_.jshintrc' , '.jshintrc' ) ;
47-
48- this . copy ( 'src/_config.js' , 'app/src/config.js' ) ;
49- this . copy ( 'src/_game.js' , 'app/src/game.js' ) ;
50- this . copy ( 'src/_sprites.js' , 'app/src/sprites.js' ) ;
51- this . copy ( 'src/components/_MouseHover.js' , 'app/src/components/MouseHover.js' ) ;
52- this . copy ( 'src/entities/base/_BaseEntity.js' , 'app/src/entities/base/BaseEntity.js' ) ;
53- this . copy ( 'src/interfaces/_info.js' , 'app/src/interfaces/info.js' ) ;
54- this . copy ( 'src/scenes/_main.js' , 'app/src/scenes/main.js' ) ;
55-
56- this . copy ( 'src/libs/Crafty/_crafty.js' , 'app/src/libs/Crafty/crafty.js' ) ;
57- this . copy ( 'src/libs/Crafty/_crafty.min.js' , 'app/src/libs/Crafty/crafty.min.js' ) ;
73+ } ;
5874
59- this . copy ( 'src/libs/CraftyDebug/_craftyDebug.js' , 'app/src/libs/CraftyDebug/craftyDebug.js' ) ;
60- this . copy ( 'src/libs/CraftyDebug/panels/_assets.js' , 'app/src/libs/CraftyDebug/panels/assets.js' ) ;
61- this . copy ( 'src/libs/CraftyDebug/panels/_entities.js' , 'app/src/libs/CraftyDebug/panels/entities.js' ) ;
75+ CraftyGenerator . prototype . jshintrc = function jsHint ( ) {
76+ this . copy ( '_.jshintrc' , '.jshintrc' ) ;
6277} ;
6378
6479CraftyGenerator . prototype . gruntfileJSON = function gruntfile ( ) {
65- this . copy ( '_Gruntfile.js' , 'Gruntfile.js' ) ;
80+ this . template ( '_Gruntfile.js' , 'Gruntfile.js' ) ;
6681} ;
6782
6883CraftyGenerator . prototype . packageJSON = function packageJSON ( ) {
@@ -74,6 +89,59 @@ CraftyGenerator.prototype.bowerJSON = function bower() {
7489 this . copy ( '_bower.json' , 'bower.json' ) ;
7590} ;
7691
77- CraftyGenerator . prototype . indexHTML = function writeIndex ( ) {
78- this . copy ( "_index.html" , "app/index.html" ) ;
79- }
92+ CraftyGenerator . prototype . craftyFiles = function craftyFiles ( ) {
93+ this . copy ( 'libs/Crafty/_crafty.js' , 'app/libs/Crafty/crafty.js' ) ;
94+ this . copy ( 'libs/Crafty/_crafty.min.js' , 'app/libs/Crafty/crafty.min.js' ) ;
95+ } ;
96+
97+ CraftyGenerator . prototype . craftyDebugFiles = function craftyDebugFiles ( ) {
98+ this . copy ( 'libs/CraftyDebug/_craftyDebug.js' , 'app/libs/CraftyDebug/craftyDebug.js' ) ;
99+ this . copy ( 'libs/CraftyDebug/panels/_assets.js' , 'app/libs/CraftyDebug/panels/assets.js' ) ;
100+ this . copy ( 'libs/CraftyDebug/panels/_entities.js' , 'app/libs/CraftyDebug/panels/entities.js' ) ;
101+ } ;
102+
103+ CraftyGenerator . prototype . app = function app ( ) {
104+ this . copy ( 'scripts/_app.js' , 'app/scripts/app.js' ) ;
105+ this . template ( 'scripts/_game.js' , 'app/scripts/game.js' ) ;
106+ } ;
107+
108+ CraftyGenerator . prototype . writeIndex = function writeIndex ( ) {
109+ var mainCssFiles = [ 'styles/normalize.css' , 'styles/style.css' ] ;
110+
111+ this . indexFile = this . appendStyles ( this . indexFile , 'styles/main.css' , mainCssFiles ) ;
112+
113+ this . indexFile = this . appendFiles ( this . indexFile , 'js' , 'scripts/bower_components.js' , [ 'bower_components/jquery/jquery.js' ] , null , 'app' ) ;
114+
115+ this . indexFile = this . appendScripts ( this . indexFile , 'scripts/crafty.js' , [
116+ 'libs/Crafty/crafty.js'
117+ ] , null , 'app' ) ;
118+
119+ this . indexFile = this . appendScripts ( this . indexFile , 'scripts/crafty_debug.js' , [
120+ 'libs/CraftyDebug/craftyDebug.js' ,
121+ 'libs/CraftyDebug/panels/assets.js' ,
122+ 'libs/CraftyDebug/panels/entities.js'
123+ ] , null , 'app' ) ;
124+
125+ this . indexFile = this . appendFiles ( this . indexFile , 'js' , 'scripts/components.js' , [ 'scripts/compiled-components.js' ] , null , '.tmp' ) ;
126+ this . indexFile = this . appendFiles ( this . indexFile , 'js' , 'scripts/scenes.js' , [ 'scripts/compiled-scenes.js' ] , null , '.tmp' ) ;
127+ this . indexFile = this . appendFiles ( this . indexFile , 'js' , 'scripts/main.js' , [ 'scripts/combined-scripts.js' ] , null , '.tmp' ) ;
128+
129+ this . write ( 'app/index.html' , this . indexFile ) ;
130+
131+ this . copy ( 'styles/normalize.css' , 'app/styles/normalize.css' ) ;
132+ this . copy ( 'styles/style.css' , 'app/styles/style.css' ) ;
133+ //this.copy("_index.html", "app/index.html");
134+ } ;
135+
136+ CraftyGenerator . prototype . install = function ( ) {
137+ if ( this . options [ 'skip-install' ] ) {
138+ return ;
139+ }
140+
141+ var done = this . async ( ) ;
142+ this . installDependencies ( {
143+ skipMessage : this . options [ 'skip-message' ] ,
144+ skipInstall : this . options [ 'skip-install' ] ,
145+ callback : done
146+ } ) ;
147+ } ;
0 commit comments