1+ /// <binding />
12module . exports = function ( grunt ) {
23
34 var loadConfig = require ( 'load-grunt-config' ) ;
45
56 loadConfig ( grunt , {
67 configPath : __dirname + '/tasks/options' ,
78 config : {
9+ target_dir : 'build' ,
810 release_dir : 'build' ,
11+ release_custom_dir : 'build/custom' ,
912 compile_dir : 'dist' ,
13+ modules_dir : 'dist/modules' ,
1014 docs_dir : 'docs' ,
15+ sourcemap : false ,
16+ filename : 'phaser' ,
17+ filelist : [ ] ,
1118 banner : require ( 'fs' ) . readFileSync ( __dirname + '/tasks/banner.txt' , 'utf8' )
1219 }
1320 } ) ;
@@ -16,10 +23,244 @@ module.exports = function (grunt) {
1623
1724 grunt . registerTask ( 'default' , [ 'build' ] ) ;
1825
19- grunt . registerTask ( 'build' , [ 'clean:dist' , 'jshint' , 'concat' , 'uglify' ] ) ;
26+ grunt . registerTask ( 'docs' , [ 'clean:docs' , 'pixidoc' , 'jsdoc:html' , 'replace:docs' , 'clean:out' ] ) ;
27+ grunt . registerTask ( 'tsdocs' , [ 'clean:out' , 'pixidoc' , 'gitclone:plugins' , 'jsdoc:json' , 'buildtsdoc:pixi' , 'buildtsdoc:phaser' , 'replace:phasertsdefheader' , 'clean:out' ] ) ;
2028
21- grunt . registerTask ( 'dist ' , [ 'replace:pixi' , 'replace:p2' , 'build' , 'copy' ] ) ;
29+ grunt . registerTask ( 'custom ' , 'Build a custom version of Phaser' , function ( arg ) {
2230
23- grunt . registerTask ( 'docs' , [ 'clean:docs' , 'pixidoc' , 'builddoc' , 'replace:docs' , 'clean:out' ] ) ;
31+ var modules = {
32+
33+ 'pixi' : { 'description' : 'Pixi.js (custom Phaser build)' , 'optional' : true , 'stub' : false } ,
34+ 'intro' : { 'description' : 'Phaser UMD wrapper' , 'optional' : true , 'stub' : false } ,
35+ 'phaser' : { 'description' : 'Phaser Globals' , 'optional' : false , 'stub' : false } ,
36+ 'geom' : { 'description' : 'Geometry Classes' , 'optional' : false , 'stub' : false } ,
37+ 'core' : { 'description' : 'Phaser Core' , 'optional' : false , 'stub' : false } ,
38+ 'input' : { 'description' : 'Input Manager + Mouse and Touch Support' , 'optional' : false , 'stub' : false } ,
39+ 'gamepad' : { 'description' : 'Gamepad Input' , 'optional' : true , 'stub' : false } ,
40+ 'keyboard' : { 'description' : 'Keyboard Input' , 'optional' : true , 'stub' : false } ,
41+ 'components' : { 'description' : 'Game Object Components' , 'optional' : false , 'stub' : false } ,
42+ 'gameobjects' : { 'description' : 'Core Game Objects' , 'optional' : false , 'stub' : false } ,
43+ 'bitmapdata' : { 'description' : 'BitmapData Game Object' , 'optional' : true , 'stub' : false } ,
44+ 'graphics' : { 'description' : 'Graphics Game Object' , 'optional' : true , 'stub' : false } ,
45+ 'rendertexture' : { 'description' : 'RenderTexture Game Object' , 'optional' : true , 'stub' : false } ,
46+ 'text' : { 'description' : 'Text Game Object (inc. Web Font Support)' , 'optional' : true , 'stub' : false } ,
47+ 'bitmaptext' : { 'description' : 'BitmapText Game Object' , 'optional' : true , 'stub' : false } ,
48+ 'retrofont' : { 'description' : 'Retro Fonts Game Object' , 'optional' : true , 'stub' : false } ,
49+ 'system' : { 'description' : 'System Classes' , 'optional' : false , 'stub' : false } ,
50+ 'math' : { 'description' : 'Math, QuadTree and RND' , 'optional' : false , 'stub' : false } ,
51+ 'net' : { 'description' : 'Network Class' , 'optional' : true , 'stub' : false } ,
52+ 'tweens' : { 'description' : 'Tween Manager' , 'optional' : true , 'stub' : true } ,
53+ 'time' : { 'description' : 'Time and Clock Manager' , 'optional' : false , 'stub' : false } ,
54+ 'animation' : { 'description' : 'Animation and Frame Manager' , 'optional' : false , 'stub' : false } ,
55+ 'loader' : { 'description' : 'Loader and Cache' , 'optional' : false , 'stub' : false } ,
56+ 'sound' : { 'description' : 'Sound Support (Web Audio and HTML Audio)' , 'optional' : true , 'stub' : true } ,
57+ 'debug' : { 'description' : 'Debug Class' , 'optional' : true , 'stub' : false } ,
58+ 'utils' : { 'description' : 'Core Utilities' , 'optional' : false , 'stub' : false } ,
59+ 'physics' : { 'description' : 'Physics Manager' , 'optional' : false , 'stub' : false } ,
60+ 'arcade' : { 'description' : 'Arcade Physics' , 'optional' : true , 'stub' : false } ,
61+ 'ninja' : { 'description' : 'Ninja Physics' , 'optional' : true , 'stub' : false } ,
62+ 'p2' : { 'description' : 'P2 Physics' , 'optional' : true , 'stub' : false } ,
63+ 'tilemaps' : { 'description' : 'Tilemap Support' , 'optional' : true , 'stub' : false } ,
64+ 'particles' : { 'description' : 'Arcade Physics Particle System' , 'optional' : true , 'stub' : true } ,
65+ 'outro' : { 'description' : 'Phaser UMD closure' , 'optional' : true , 'stub' : false }
66+
67+ } ;
68+
69+ grunt . log . writeln ( "---------------------" ) ;
70+ grunt . log . writeln ( "Building Phaser " + grunt . config . get ( 'package.version' ) ) ;
71+ grunt . log . writeln ( "---------------------" ) ;
72+
73+ if ( ! grunt . option ( 'exclude' ) )
74+ {
75+ grunt . log . writeln ( "\nUse --exclude to select which modules to exclude:\n" ) ;
76+
77+ for ( var module in modules )
78+ {
79+ if ( modules [ module ] . optional )
80+ {
81+ grunt . log . writeln ( module + ' - ' + modules [ module ] . description ) ;
82+ }
83+ }
84+
85+ grunt . log . writeln ( "\nFor example: --exclude p2,tilemap,retrofont" ) ;
86+ grunt . log . writeln ( "Optional flags: --filename yourfilename and --sourcemap true" ) ;
87+ grunt . log . writeln ( "Note that some modules have dependencies on others.\n" ) ;
88+
89+ grunt . fail . fatal ( "No build options were specified." ) ;
90+ }
91+ else
92+ {
93+ // Defaults
94+ grunt . config . set ( 'sourcemap' , false ) ;
95+ grunt . config . set ( 'filename' , 'phaser' ) ;
96+ grunt . config . set ( 'target_dir' , '<%= release_dir %>' ) ;
97+
98+ // Overrides
99+ if ( grunt . option ( 'filename' ) )
100+ {
101+ grunt . config . set ( 'filename' , grunt . option ( 'filename' ) ) ;
102+ }
103+
104+ if ( grunt . option ( 'sourcemap' ) )
105+ {
106+ grunt . config . set ( 'sourcemap' , grunt . option ( 'sourcemap' ) ) ;
107+ }
108+
109+ grunt . log . writeln ( "Excluding modules:\n" ) ;
110+
111+ var excludes = grunt . option ( 'exclude' ) . split ( ',' ) ;
112+
113+ // Check the given modules are all valid
114+ for ( var i = 0 ; i < excludes . length ; i ++ )
115+ {
116+ var exclude = excludes [ i ] ;
117+
118+ if ( modules [ exclude ] )
119+ {
120+ grunt . log . writeln ( "* " + exclude + ' - ' + modules [ exclude ] . description ) ;
121+ }
122+ else
123+ {
124+ grunt . fail . fatal ( "Unknown module '" + exclude + "'" ) ;
125+ }
126+ }
127+
128+ // Handle basic dependencies
129+
130+ if ( excludes [ 'arcade' ] && ! excludes [ 'particles' ] )
131+ {
132+ grunt . log . writeln ( "Warning: Particles rely on Arcade Physics. Excluding from build." ) ;
133+ excludes . push ( 'particles' ) ;
134+ }
135+
136+ if ( excludes [ 'rendertexture' ] && ! excludes [ 'retrofont' ] )
137+ {
138+ grunt . log . writeln ( "Warning: RetroFonts rely on RenderTextures. Excluding from build." ) ;
139+ excludes . push ( 'retrofont' ) ;
140+ }
141+
142+ // Ok we know the excludes array is fine, let's get this show started
143+
144+ grunt . log . writeln ( "\nBuilding ...\n" ) ;
145+
146+ var filelist = [ ] ;
147+
148+ // Clean the working folder
149+ var tasks = [ 'clean:build' ] ;
150+
151+ for ( var key in modules )
152+ {
153+ if ( modules [ key ] . stub && excludes . indexOf ( key ) !== - 1 )
154+ {
155+ // If the module IS excluded and has a stub, we need that
156+ tasks . push ( 'concat:' + key + 'Stub' ) ;
157+
158+ filelist . push ( '<%= modules_dir %>/' + key + '.js' ) ;
159+ }
160+ else if ( modules [ key ] . optional === false || excludes . indexOf ( key ) === - 1 )
161+ {
162+ // If it's required or NOT excluded, add it to the tasks list
163+ tasks . push ( 'concat:' + key ) ;
164+
165+ filelist . push ( '<%= modules_dir %>/' + key + '.js' ) ;
166+
167+ // Special case: If they have Arcade Physics AND Tilemaps we need to include the Tilemap Collision class
168+ if ( key === 'arcade' && ! excludes [ 'tilemaps' ] )
169+ {
170+ tasks . push ( 'concat:arcadeTilemaps' ) ;
171+ filelist . push ( '<%= modules_dir %>/arcadeTilemaps.js' ) ;
172+ }
173+ }
174+ }
175+
176+ grunt . config . set ( 'filelist' , filelist ) ;
177+
178+ tasks . push ( 'concat:custom' ) ;
179+
180+ tasks . push ( 'uglify:custom' ) ;
181+
182+ if ( grunt . option ( 'copy' ) )
183+ {
184+ tasks . push ( 'copy:custom' ) ;
185+ }
186+ else if ( grunt . option ( 'copycustom' ) )
187+ {
188+ grunt . config . set ( 'target_dir' , '<%= release_custom_dir %>' ) ;
189+ tasks . push ( 'copy:custom' ) ;
190+ }
191+
192+ grunt . task . run ( tasks ) ;
193+
194+ }
195+
196+ } ) ;
197+
198+ grunt . registerTask ( 'dist' , 'Compile all Phaser versions and copy to the build folder' , function ( ) {
199+
200+ grunt . task . run ( 'clean:release' ) ;
201+ grunt . task . run ( 'full' ) ;
202+ grunt . task . run ( 'arcadephysics' ) ;
203+ grunt . task . run ( 'nophysics' ) ;
204+ grunt . task . run ( 'minimum' ) ;
205+
206+ } ) ;
207+
208+ grunt . registerTask ( 'build' , 'Compile all Phaser versions just to the dist folder' , function ( ) {
209+
210+ grunt . option ( 'exclude' , 'ninja' ) ;
211+ grunt . option ( 'filename' , 'phaser' ) ;
212+ grunt . option ( 'sourcemap' , true ) ;
213+ grunt . option ( 'copy' , false ) ;
214+
215+ grunt . task . run ( 'custom' ) ;
216+
217+ } ) ;
218+
219+ grunt . registerTask ( 'full' , 'Phaser complete' , function ( ) {
220+
221+ grunt . option ( 'exclude' , 'ninja' ) ;
222+ grunt . option ( 'filename' , 'phaser' ) ;
223+ grunt . option ( 'sourcemap' , true ) ;
224+ grunt . option ( 'copy' , true ) ;
225+
226+ grunt . task . run ( 'custom' ) ;
227+
228+ } ) ;
229+
230+ grunt . registerTask ( 'arcadephysics' , 'Phaser with Arcade Physics, Tilemaps and Particles' , function ( ) {
231+
232+ grunt . option ( 'exclude' , 'ninja,p2' ) ;
233+ grunt . option ( 'filename' , 'phaser-arcade-physics' ) ;
234+ grunt . option ( 'sourcemap' , true ) ;
235+ grunt . option ( 'copy' , false ) ;
236+ grunt . option ( 'copycustom' , true ) ;
237+
238+ grunt . task . run ( 'custom' ) ;
239+
240+ } ) ;
241+
242+ grunt . registerTask ( 'nophysics' , 'Phaser without physics, tilemaps or particles' , function ( ) {
243+
244+ grunt . option ( 'exclude' , 'arcade,ninja,p2,tilemaps,particles' ) ;
245+ grunt . option ( 'filename' , 'phaser-no-physics' ) ;
246+ grunt . option ( 'sourcemap' , true ) ;
247+ grunt . option ( 'copy' , false ) ;
248+ grunt . option ( 'copycustom' , true ) ;
249+
250+ grunt . task . run ( 'custom' ) ;
251+
252+ } ) ;
253+
254+ grunt . registerTask ( 'minimum' , 'Phaser without any optional modules except Pixi' , function ( ) {
255+
256+ grunt . option ( 'exclude' , 'gamepad,keyboard,bitmapdata,graphics,rendertexture,text,bitmaptext,retrofont,net,tweens,sound,debug,arcade,ninja,p2,tilemaps,particles' ) ;
257+ grunt . option ( 'filename' , 'phaser-minimum' ) ;
258+ grunt . option ( 'sourcemap' , true ) ;
259+ grunt . option ( 'copy' , false ) ;
260+ grunt . option ( 'copycustom' , true ) ;
261+
262+ grunt . task . run ( 'custom' ) ;
263+
264+ } ) ;
24265
25266} ;
0 commit comments