@@ -30,7 +30,6 @@ module.exports = function (grunt) {
3030
3131 var modules = {
3232
33- 'pixi' : { 'description' : 'Pixi.js (custom Phaser build)' , 'optional' : false , 'stub' : false } ,
3433 'intro' : { 'description' : 'Phaser UMD wrapper' , 'optional' : true , 'stub' : false } ,
3534 'phaser' : { 'description' : 'Phaser Globals' , 'optional' : false , 'stub' : false } ,
3635 'geom' : { 'description' : 'Geometry Classes' , 'optional' : false , 'stub' : false } ,
@@ -112,76 +111,151 @@ module.exports = function (grunt) {
112111
113112 grunt . log . writeln ( "Excluding modules:\n" ) ;
114113
115- var excludes = grunt . option ( 'exclude' ) . split ( ',' ) ;
114+ var excludedKeys = [ ] ;
116115
117- // Check the given modules are all valid
118- for ( var i = 0 ; i < excludes . length ; i ++ )
116+ // Nothing is excluded!
117+ var excludes = false ;
118+
119+ if ( grunt . option ( 'exclude' ) !== 'null' )
119120 {
120- var exclude = excludes [ i ] ;
121+ excludes = grunt . option ( 'exclude' ) . split ( ',' ) ;
122+
123+ // Check the given modules are all valid
124+ for ( var i = 0 ; i < excludes . length ; i ++ )
125+ {
126+ var exclude = excludes [ i ] ;
127+
128+ if ( modules [ exclude ] )
129+ {
130+ grunt . log . writeln ( "* " + exclude + ' - ' + modules [ exclude ] . description ) ;
131+ excludedKeys [ exclude ] = true ;
132+ }
133+ else
134+ {
135+ grunt . fail . fatal ( "Unknown module '" + exclude + "'" ) ;
136+ }
137+ }
138+
139+ // Handle basic dependencies
121140
122- if ( modules [ exclude ] )
141+ if ( excludedKeys [ 'arcade' ] && ! excludedKeys [ 'particles' ] )
123142 {
124- grunt . log . writeln ( "* " + exclude + ' - ' + modules [ exclude ] . description ) ;
143+ grunt . log . writeln ( "Warning: Particles rely on Arcade Physics which has been excluded. Removing Particles from build." ) ;
144+ excludes . push ( 'particles' ) ;
125145 }
126- else
146+
147+ if ( excludedKeys [ 'rendertexture' ] && ! excludedKeys [ 'retrofont' ] )
127148 {
128- grunt . fail . fatal ( "Unknown module '" + exclude + "'" ) ;
149+ grunt . log . writeln ( "Warning: RetroFonts rely on RenderTextures. Excluding from build." ) ;
150+ excludes . push ( 'retrofont' ) ;
129151 }
130152 }
131153
132- // Handle basic dependencies
154+ // Ok we know the excludes array is fine, let's get this show started
155+
156+ grunt . log . writeln ( "\nPackaging Globals ...\n" ) ;
157+
158+ var filelist = [ ] ;
159+
160+ // Clean the working folder
161+ var tasks = [ 'clean:build' ] ;
162+
163+ // Prepare the globals first, the libs that live outside of Phaser
164+
165+ // 1) Creature
166+
167+ if ( ! excludedKeys [ 'creature' ] )
168+ {
169+ grunt . log . writeln ( "-> Creature" ) ;
170+ tasks . push ( 'concat:creatureGlobal' ) ;
171+ filelist . push ( '<%= modules_dir %>/creature-global.js' ) ;
172+ }
173+
174+ // 2) P2
133175
134- if ( excludes [ 'arcade' ] && ! excludes [ 'particles '] )
176+ if ( ! excludedKeys [ 'p2 '] )
135177 {
136- grunt . log . writeln ( "Warning: Particles rely on Arcade Physics. Excluding from build." ) ;
137- excludes . push ( 'particles' ) ;
178+ grunt . log . writeln ( "-> P2.js" ) ;
179+ tasks . push ( 'concat:p2Global' ) ;
180+ filelist . push ( '<%= modules_dir %>/p2-global.js' ) ;
138181 }
139182
140- if ( excludes [ 'rendertexture' ] && ! excludes [ 'retrofont' ] )
183+ // 3) PIXI
184+
185+ grunt . log . writeln ( "-> PIXI" ) ;
186+ tasks . push ( 'concat:pixiIntro' ) ;
187+ filelist . push ( '<%= modules_dir %>/pixi-intro.js' ) ;
188+
189+ // Optional Rope
190+ if ( ! excludedKeys [ 'rope' ] )
141191 {
142- grunt . log . writeln ( "Warning: RetroFonts rely on RenderTextures. Excluding from build." ) ;
143- excludes . push ( 'retrofont' ) ;
192+ grunt . log . writeln ( "-> PIXI.Rope" ) ;
193+ tasks . push ( 'concat:pixiRope' ) ;
194+ filelist . push ( '<%= modules_dir %>/pixi-rope.js' ) ;
144195 }
145196
146- // Ok we know the excludes array is fine, let's get this show started
197+ // Optional Tilesprite
198+ if ( ! excludedKeys [ 'tilesprite' ] )
199+ {
200+ grunt . log . writeln ( "-> PIXI.TileSprite" ) ;
201+ tasks . push ( 'concat:pixiTileSprite' ) ;
202+ filelist . push ( '<%= modules_dir %>/pixi-tilesprite.js' ) ;
203+ }
147204
148- grunt . log . writeln ( "\nBuilding ...\n" ) ;
205+ // PIXI Outro
206+ tasks . push ( 'concat:pixiOutro' ) ;
207+ filelist . push ( '<%= modules_dir %>/pixi-outro.js' ) ;
149208
150- var filelist = [ ] ;
209+ // And now for Phaser
151210
152- // Clean the working folder
153- var tasks = [ 'clean:build' ] ;
211+ grunt . log . writeln ( "\nBuilding ..." ) ;
154212
155- for ( var key in modules )
213+ if ( excludes !== false )
156214 {
157- if ( modules [ key ] . stub && excludes . indexOf ( key ) !== - 1 )
215+ for ( var key in modules )
158216 {
159- // If the module IS excluded and has a stub, we need that
160- tasks . push ( 'concat:' + key + 'Stub' ) ;
217+ if ( modules [ key ] . stub && excludes . indexOf ( key ) !== - 1 )
218+ {
219+ // If the module IS excluded and has a stub, we need that
220+ tasks . push ( 'concat:' + key + 'Stub' ) ;
161221
162- filelist . push ( '<%= modules_dir %>/' + key + '.js' ) ;
163- }
164- else if ( modules [ key ] . optional === false || excludes . indexOf ( key ) === - 1 )
165- {
166- // If it's required or NOT excluded, add it to the tasks list
167- tasks . push ( 'concat:' + key ) ;
222+ filelist . push ( '<%= modules_dir %>/' + key + '.js' ) ;
223+ }
224+ else if ( modules [ key ] . optional === false || excludes . indexOf ( key ) === - 1 )
225+ {
226+ // If it's required or NOT excluded, add it to the tasks list
227+ tasks . push ( 'concat:' + key ) ;
168228
169- filelist . push ( '<%= modules_dir %>/' + key + '.js' ) ;
229+ filelist . push ( '<%= modules_dir %>/' + key + '.js' ) ;
170230
171- // Special case: If they have Arcade Physics AND Tilemaps we need to include the Tilemap Collision class
172- if ( key === 'arcade' && ! excludes [ 'tilemaps' ] )
173- {
174- tasks . push ( 'concat:arcadeTilemaps' ) ;
175- filelist . push ( '<%= modules_dir %>/arcadeTilemaps.js' ) ;
231+ // Special case: If they have Arcade Physics AND Tilemaps we need to include the Tilemap Collision class
232+ if ( key === 'arcade' && ! excludes [ 'tilemaps' ] )
233+ {
234+ tasks . push ( 'concat:arcadeTilemaps' ) ;
235+ filelist . push ( '<%= modules_dir %>/arcadeTilemaps.js' ) ;
236+ }
176237 }
177238 }
178239 }
240+ else
241+ {
242+ // The full monty ...
243+
244+ for ( var mkey in modules )
245+ {
246+ tasks . push ( 'concat:' + mkey ) ;
247+ filelist . push ( '<%= modules_dir %>/' + mkey + '.js' ) ;
248+ }
249+ }
179250
180251 grunt . config . set ( 'filelist' , filelist ) ;
181252
182253 tasks . push ( 'concat:custom' ) ;
183254
184- tasks . push ( 'uglify:custom' ) ;
255+ if ( grunt . option ( 'uglify' ) )
256+ {
257+ tasks . push ( 'uglify:custom' ) ;
258+ }
185259
186260 if ( grunt . option ( 'copy' ) )
187261 {
@@ -215,17 +289,57 @@ module.exports = function (grunt) {
215289 grunt . option ( 'filename' , 'phaser' ) ;
216290 grunt . option ( 'sourcemap' , true ) ;
217291 grunt . option ( 'copy' , false ) ;
292+ grunt . option ( 'uglify' , true ) ;
218293
219294 grunt . task . run ( 'custom' ) ;
220295
221296 } ) ;
222297
223- grunt . registerTask ( 'full' , 'Phaser complete ' , function ( ) {
298+ grunt . registerTask ( 'full' , 'Phaser (excluding Ninja and Creature) ' , function ( ) {
224299
225300 grunt . option ( 'exclude' , 'ninja,creature' ) ;
226301 grunt . option ( 'filename' , 'phaser' ) ;
227302 grunt . option ( 'sourcemap' , true ) ;
228303 grunt . option ( 'copy' , true ) ;
304+ grunt . option ( 'uglify' , true ) ;
305+
306+ grunt . task . run ( 'custom' ) ;
307+
308+ } ) ;
309+
310+ grunt . registerTask ( 'complete' , 'Phaser Build with all libs' , function ( ) {
311+
312+ grunt . option ( 'exclude' , 'null' ) ;
313+ grunt . option ( 'filename' , 'phaser-complete' ) ;
314+ grunt . option ( 'sourcemap' , false ) ;
315+ grunt . option ( 'copy' , true ) ;
316+ grunt . option ( 'copycustom' , true ) ;
317+ grunt . option ( 'uglify' , true ) ;
318+
319+ grunt . task . run ( 'custom' ) ;
320+
321+ } ) ;
322+
323+ grunt . registerTask ( 'test' , 'Phaser Test Build (all libs)' , function ( ) {
324+
325+ grunt . option ( 'exclude' , 'ninja,creature' ) ;
326+ grunt . option ( 'filename' , 'phaser-test' ) ;
327+ grunt . option ( 'sourcemap' , false ) ;
328+ grunt . option ( 'copy' , false ) ;
329+ grunt . option ( 'uglify' , false ) ;
330+
331+ grunt . task . run ( 'custom' ) ;
332+
333+ } ) ;
334+
335+ grunt . registerTask ( 'creature' , 'Phaser + Creature' , function ( ) {
336+
337+ grunt . option ( 'exclude' , 'ninja' ) ;
338+ grunt . option ( 'filename' , 'phaser-creature' ) ;
339+ grunt . option ( 'sourcemap' , true ) ;
340+ grunt . option ( 'copy' , true ) ;
341+ grunt . option ( 'copycustom' , true ) ;
342+ grunt . option ( 'uglify' , true ) ;
229343
230344 grunt . task . run ( 'custom' ) ;
231345
@@ -238,6 +352,20 @@ module.exports = function (grunt) {
238352 grunt . option ( 'sourcemap' , true ) ;
239353 grunt . option ( 'copy' , false ) ;
240354 grunt . option ( 'copycustom' , true ) ;
355+ grunt . option ( 'uglify' , true ) ;
356+
357+ grunt . task . run ( 'custom' ) ;
358+
359+ } ) ;
360+
361+ grunt . registerTask ( 'ninjaphysics' , 'Phaser with Ninja Physics and Tilemaps' , function ( ) {
362+
363+ grunt . option ( 'exclude' , 'p2,particles,creature' ) ;
364+ grunt . option ( 'filename' , 'phaser-ninja-physics' ) ;
365+ grunt . option ( 'sourcemap' , true ) ;
366+ grunt . option ( 'copy' , false ) ;
367+ grunt . option ( 'copycustom' , true ) ;
368+ grunt . option ( 'uglify' , true ) ;
241369
242370 grunt . task . run ( 'custom' ) ;
243371
@@ -250,18 +378,20 @@ module.exports = function (grunt) {
250378 grunt . option ( 'sourcemap' , true ) ;
251379 grunt . option ( 'copy' , false ) ;
252380 grunt . option ( 'copycustom' , true ) ;
381+ grunt . option ( 'uglify' , true ) ;
253382
254383 grunt . task . run ( 'custom' ) ;
255384
256385 } ) ;
257386
258- grunt . registerTask ( 'minimum' , 'Phaser without any optional modules except Pixi ' , function ( ) {
387+ grunt . registerTask ( 'minimum' , 'Phaser without any optional modules' , function ( ) {
259388
260389 grunt . option ( 'exclude' , 'gamepad,keyboard,bitmapdata,graphics,rendertexture,text,bitmaptext,retrofont,net,tweens,sound,debug,arcade,ninja,p2,tilemaps,particles,creature,video,rope,tilesprite' ) ;
261390 grunt . option ( 'filename' , 'phaser-minimum' ) ;
262391 grunt . option ( 'sourcemap' , true ) ;
263392 grunt . option ( 'copy' , false ) ;
264393 grunt . option ( 'copycustom' , true ) ;
394+ grunt . option ( 'uglify' , true ) ;
265395
266396 grunt . task . run ( 'custom' ) ;
267397
0 commit comments