@@ -2,6 +2,65 @@ module.exports = function( grunt ) {
2
2
"use strict" ;
3
3
4
4
var _ = grunt . util . _ ,
5
+
6
+ // Ensure that modules specified via the --modules option are in the same
7
+ // order as the one in which they appear in js/jquery.mobile.js. To achieve
8
+ // this, we parse js/jquery.mobile.js and reconstruct the array of
9
+ // dependencies listed therein.
10
+ makeModulesList = function ( modules ) {
11
+ var start , end , index ,
12
+ modulesHash = { } ,
13
+ fixedModules = [ ] ,
14
+ jsFile = grunt . file . read ( path . join ( "js" , "jquery.mobile.js" ) ) ;
15
+
16
+ modules = modules . split ( "," ) ;
17
+
18
+ // This is highly dependent on the contents of js/jquery.mobile.js
19
+ if ( jsFile ) {
20
+ start = jsFile . indexOf ( "[" ) ;
21
+ if ( start > - 1 ) {
22
+ start ++ ;
23
+ end = jsFile . indexOf ( "]" ) ;
24
+ if ( start < jsFile . length &&
25
+ end > - 1 && end < jsFile . length && end > start ) {
26
+
27
+ // Convert list of desired modules to a hash
28
+ for ( index = 0 ; index < modules . length ; index ++ ) {
29
+ modulesHash [ modules [ index ] ] = true ;
30
+ }
31
+
32
+ // Split list of modules from js/jquery.mobile.js into an array
33
+ jsFile = jsFile
34
+ . slice ( start , end )
35
+ . match ( / " [ ^ " ] * " / gm ) ;
36
+
37
+ // Add each desired module to the fixed list of modules in the
38
+ // correct order
39
+ for ( index = 0 ; index < jsFile . length ; index ++ ) {
40
+
41
+ // First we need to touch up each module from js/jquery.mobile.js
42
+ jsFile [ index ] = jsFile [ index ]
43
+ . replace ( / " / g, "" )
44
+ . replace ( / ^ .\/ / , "" ) ;
45
+
46
+ // Then, if it's in the hash of desired modules, add it to the
47
+ // list containing the desired modules in the correct order
48
+ if ( modulesHash [ jsFile [ index ] ] ) {
49
+ fixedModules . push ( jsFile [ index ] ) ;
50
+ }
51
+ }
52
+
53
+ // If we've found all the desired modules, we re-create the comma-
54
+ // separated list and return it.
55
+ if ( fixedModules . length === modules . length ) {
56
+ modules = fixedModules ;
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ return modules ;
63
+ } ,
5
64
path = require ( "path" ) ,
6
65
httpPort = Math . floor ( 9000 + Math . random ( ) * 1000 ) ,
7
66
name = "jquery.mobile" ,
@@ -186,7 +245,9 @@ module.exports = function( grunt ) {
186
245
187
246
mainConfigFile : "js/requirejs.config.js" ,
188
247
189
- include : ( grunt . option ( "modules" ) || "jquery.mobile" ) . split ( "," ) ,
248
+ include : ( grunt . option ( "modules" ) ?
249
+ makeModulesList ( grunt . option ( "modules" ) ) :
250
+ [ "jquery.mobile" ] ) ,
190
251
191
252
exclude : [
192
253
"jquery" ,
0 commit comments