forked from jquery-archive/jquery-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
1116 lines (991 loc) · 28.6 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module.exports = function( grunt ) {
"use strict";
var _ = require( "underscore" ),
cheerio = require( "cheerio" ),
replaceCombinedCssReference = function( href, processedName ) {
return href
.replace( /^css/, "demos/css")
.replace( /\.\.\/css/, "css" )
.replace( /jquery\.mobile\.css/, processedName + ".min.css" );
},
// Ensure that modules specified via the --modules option are in the same
// order as the one in which they appear in js/jquery.mobile.js. To achieve
// this, we parse js/jquery.mobile.js and reconstruct the array of
// dependencies listed therein.
makeModulesList = function( modules ) {
var start, end, index,
modulesHash = {},
fixedModules = [],
jsFile = grunt.file.read( path.join( "js", "jquery.mobile.js" ) );
modules = modules.split( "," );
// This is highly dependent on the contents of js/jquery.mobile.js
if ( jsFile ) {
start = jsFile.indexOf( "[" );
if ( start > -1 ) {
start++;
end = jsFile.indexOf( "]" );
if ( start < jsFile.length &&
end > -1 && end < jsFile.length && end > start ) {
// Convert list of desired modules to a hash
for ( index = 0 ; index < modules.length ; index++ ) {
modulesHash[ modules[ index ] ] = true;
}
// Split list of modules from js/jquery.mobile.js into an array
jsFile = jsFile
.slice( start, end )
.match( /"[^"]*"/gm );
// Add each desired module to the fixed list of modules in the
// correct order
for ( index = 0 ; index < jsFile.length ; index++ ) {
// First we need to touch up each module from js/jquery.mobile.js
jsFile[ index ] = jsFile[ index ]
.replace( /"/g, "" )
.replace( /^.\//, "" );
// Then, if it's in the hash of desired modules, add it to the
// list containing the desired modules in the correct order
if ( modulesHash[ jsFile[ index ] ] ) {
fixedModules.push( jsFile[ index ] );
}
}
// If we've found all the desired modules, we re-create the comma-
// separated list and return it.
if ( fixedModules.length === modules.length ) {
modules = fixedModules;
}
}
}
}
return modules;
},
processDemos = function( content, srcPath ) {
var processedName, $;
content = content.replace( /^\s*<\?php include\(\s*['"]([^'"]+)['"].*$/gmi,
function( match, includePath /*, offset, string */ ) {
var newSrcPath = srcPath;
// If we've already handled the nested includes use the version
// that was copied to the dist folder
// TODO use the config from copy:demos.nested.files
if( includePath.match(/jqm\-(contents|navmenu|search)\.php/) ) {
newSrcPath = "dist/" + newSrcPath;
}
return grunt.file.read( path.resolve( path.join(
path.dirname( newSrcPath ), includePath ) ) );
}
);
if ( content.substring( 0, 15 ).toLowerCase() === "<!doctype html>" ||
srcPath.match( /\.php$/ ) ) {
processedName = grunt.config.process( name + "<%= versionSuffix %>" );
$ = cheerio.load( content );
$( "script" ).each( function() {
var text,
element = $( this ),
src = element.attr( "src" );
if ( src ) {
element.attr( "src", src
.replace( /_assets\/js\/?$/, "_assets/js/index.js" )
.replace( /\.\.\/external\/jquery\/jquery.js$/,
"js/jquery.js" )
.replace( /\.\.\/js\/?$/,
"js/" + processedName + ".min.js" )
.replace( /external\/jquery\/jquery.js$/,
"demos/js/jquery.min.js" )
.replace( /^js\/?$/, "demos/js/" + processedName + ".min.js" ) );
} else {
text = element.text();
// References to stylesheets via grunticon need to be updated
text = text.replace( /(grunticon\( \[([^\]]*))/,
function( match, group ) {
var index,
offset = group.indexOf( "[" ),
prefix = group.substring( 0, offset + 1 );
group = group.substring( offset + 1 ).split( "," );
for ( index in group ) {
group[ index ] = "\"" + group[ index ]
.trim()
.replace( /(^['"])|(['"]$)/g, "" )
.replace( /\.\.\/css\//, "css/" )
.replace( /\.css$/, ".min.css" ) + "\"";
}
return prefix + " " + group.join( "," ) + " ";
});
//element.html( text );
element[ 0 ].children[ 0 ].data = text;
}
});
$( "link[rel='stylesheet'][href]" ).each( function() {
var element = $( this );
element.attr( "href",
replaceCombinedCssReference( element.attr( "href" ),
processedName )
// Demos that separately refer to the structure need to be
// processed here
.replace( /css\/structure\/jquery\.mobile\.structure\.css/gi,
path.join( "css", "themes", "default",
grunt.config.process( name + ".structure" +
"<%= versionSuffix %>" ) + ".min.css" ) )
// References to the icons CSS file need to be processed here
.replace( /css\/themes\/default\/jquery\.mobile\.icons\.css/,
path.join( "css/themes/default", "jquery.mobile.icons.min.css" )
));
});
$( "a[href]" ).each( function() {
var element = $( this );
element.attr( "href",
element.attr( "href" ).replace( /\.php$/, ".html" ) );
});
content = $.html();
}
return content;
},
path = require( "path" ),
httpPort = Math.floor( 9000 + Math.random()*1000 ),
phpPort = Math.floor( 8000 + Math.random()*1000 ),
name = "jquery.mobile",
dist = "dist" + path.sep,
copyrightYear = grunt.template.today( "UTC:yyyy" ),
banner = {
normal: [
"/*!",
"* jQuery Mobile <%= version %>",
"* <%if ( headHash ) {%>Git HEAD hash: <%= headHash %> <> <% } %>Date: " +
grunt.template.today( "UTC:ddd mmm d yyyy HH:MM:ss Z" ),
"* http://jquerymobile.com",
"*",
"* Copyright 2010, " + copyrightYear + " jQuery Foundation, Inc. and other" +
"contributors",
"* Released under the MIT license.",
"* http://jquery.org/license",
"*",
"*/",
"",
"",
"" ].join( grunt.util.linefeed ),
minified: "/*! jQuery Mobile <%= version %> | <%if ( headShortHash ) {%>Git HEAD" +
"hash: <%= headShortHash %> <> <% } %>" + grunt.template.today( "UTC:yyyy-mm-dd" ) +
"T" + grunt.template.today( "UTC:HH:MM:ss" ) + "Z | (c) 2010, " + copyrightYear +
" jQuery Foundation, Inc. | jquery.org/license */\n"
},
dirs = {
dist: dist,
cdn: {
google: path.join( dist, "cdn-google" ),
jquery: path.join( dist, "cdn" ),
git: path.join( dist, "git" )
},
tmp: path.join( dist, "tmp" )
},
files = {
css: {
structure: {
src: "css/structure/jquery.mobile.structure.css",
unminified: name + ".structure<%= versionSuffix %>.css"
},
theme: {
src: "css/themes/default/jquery.mobile.theme.css",
unminified: name + ".theme<%= versionSuffix %>.css"
},
bundle: {
src: "css/themes/default/jquery.mobile.css",
unminified: name + "<%= versionSuffix %>.css"
},
inlinesvg: {
src: "css/themes/default/jquery.mobile.inline-svg.css",
unminified: name + ".inline-svg<%= versionSuffix %>.css"
},
inlinepng: {
src: "css/themes/default/jquery.mobile.inline-png.css",
unminified: name + ".inline-png<%= versionSuffix %>.css"
},
externalpng: {
src: "css/themes/default/jquery.mobile.external-png.css",
unminified: name + ".external-png<%= versionSuffix %>.css"
},
icons: {
src: "css/themes/default/jquery.mobile.icons.css",
unminified: name + ".icons<%= versionSuffix %>.css"
}
},
getCSSFiles: function( destDir ) {
destDir = destDir || ".";
var list = [];
_.values( files.css ).forEach( function( value ) {
list.push({
src: value.src,
dest: path.join( destDir, value.unminified )
});
});
return list;
},
getMinifiedCSSFiles: function( destDir ) {
destDir = destDir || ".";
var list = [];
_.values( files.css ).forEach( function( value ) {
list.push({
src: path.join( destDir, value.unminified ),
dest: path.join( destDir, value.minified )
});
});
return list;
},
cdn: [
name + "<%= versionSuffix %>.js",
name + "<%= versionSuffix %>.min.js",
name + "<%= versionSuffix %>.min.map",
"<%= files.css.structure.unminified %>",
"<%= files.css.structure.minified %>",
"<%= files.css.bundle.unminified %>",
"<%= files.css.bundle.minified %>",
"<%= files.css.inlinesvg.unminified %>",
"<%= files.css.inlinesvg.minified %>",
"<%= files.css.inlinepng.unminified %>",
"<%= files.css.inlinepng.minified %>",
"<%= files.css.externalpng.unminified %>",
"<%= files.css.externalpng.minified %>",
"<%= files.css.icons.unminified %>",
"<%= files.css.icons.minified %>",
"images/*.*",
"images/icons-png/**"
],
distZipContent: [
"<%= files.cdn %>",
"<%= files.css.theme.unminified %>",
"<%= files.css.theme.minified %>",
"images/icons-svg/**",
"demos/**"
],
zipFileName: name + "<%= versionSuffix %>.zip",
distZipOut: path.join( dist, name + "<%= versionSuffix %>.zip" ),
imagesZipOut: path.join( dist, name + ".images<%= versionSuffix %>.zip" ),
googleCDNZipOut: path.join( "<%= dirs.cdn.google %>","<%= files.zipFileName %>" )
};
// Add minified property to files.css.*
_.forEach( files.css, function( o ) {
o.minified = o.unminified.replace( /\.css$/, ".min.css" );
});
// Project configuration.
grunt.config.init({
pkg: grunt.file.readJSON( "package.json" ),
version: "<%= pkg.version %>",
versionSuffix: "",
headHash: "",
headShortHash: "",
dirs: dirs,
files: files,
jshint: {
js: {
options: {
jshintrc: "js/.jshintrc"
},
files: {
src: [
"js/**/*.js",
"!js/jquery.js",
"!js/jquery.ui.widget.js",
"!js/widgets/jquery.ui.tabs.js",
"!js/jquery.ui.core.js"
]
}
},
grunt: {
options: {
jshintrc: ".jshintrc"
},
files: {
src: [ "Gruntfile.js" ]
}
}
},
requirejs: {
js: {
options: {
baseUrl: "js",
optimize: "none",
//Finds require() dependencies inside a require() or define call.
findNestedDependencies: true,
//If skipModuleInsertion is false, then files that do not use define()
//to define modules will get a define() placeholder inserted for them.
//Also, require.pause/resume calls will be inserted.
//Set it to true to avoid this. This is useful if you are building code that
//does not use require() in the built project or in the JS files, but you
//still want to use the optimization tool from RequireJS to concatenate
//modules together.
skipModuleInsertion: true,
mainConfigFile: "js/requirejs.config.js",
include: ( grunt.option( "modules" ) ?
makeModulesList( grunt.option( "modules" ) ) :
[ "jquery.mobile" ] ),
exclude: [
"jquery",
"json",
"json!../package.json"
],
out: path.join( dist, name ) + "<%= versionSuffix %>.js",
pragmasOnSave: {
jqmBuildExclude: true
},
//File paths are relative to the build file, or if running a commmand
//line build, the current directory.
wrap: {
startFile: "build/wrap.start",
endFile: "build/wrap.end"
},
onBuildWrite: function (moduleName, path, contents) {
return contents.replace(/__version__/g, grunt.config.process(
"\"<%= version %>\""
));
}
}
}
},
concat: {
js: {
options: {
banner: banner.normal
},
src: [ path.join( dist, name ) + "<%= versionSuffix %>.js" ],
dest: path.join( dist, name ) + "<%= versionSuffix %>.js"
},
demos: {
src: [ "demos/_assets/js/*.js" ],
dest: path.join( dist, "demos/_assets/js/index.js" )
}
},
uglify: {
all: {
options: {
banner: banner.minified,
sourceMap: path.join( dist, name ) + "<%= versionSuffix %>.min.map",
sourceMappingURL: name + "<%= versionSuffix %>.min.map",
beautify: {
ascii_only: true
}
},
files: {
"dist/jquery.mobile<%= versionSuffix %>.min.js": path.join( dist, name ) +
"<%= versionSuffix %>.js"
}
}
},
cssbuild: {
options: {
banner: banner.normal,
//Allow CSS optimizations. Allowed values:
//- "standard": @import inlining, comment removal and line returns.
//Removing line returns may have problems in IE, depending on the type
//of CSS.
//- "standard.keepLines": like "standard" but keeps line returns.
//- "none": skip CSS optimizations.
//- "standard.keepComments": keeps the file comments, but removes line
//returns. (r.js 1.0.8+)
//- "standard.keepComments.keepLines": keeps the file comments and line
//returns. (r.js 1.0.8+)
optimizeCss: "standard.keepComments.keepLines",
//If optimizeCss is in use, a list of of files to ignore for the @import
//inlining. The value of this option should be a string of comma separated
//CSS file names to ignore (like 'a.css,b.css'. The file names should match
//whatever strings are used in the @import calls.
cssImportIgnore: null
},
all: {
files: files.getCSSFiles( dist )
}
},
cssmin: {
options: {
banner: banner.minified,
keepSpecialComments: 0
},
minify: {
files: files.getMinifiedCSSFiles( dist )
}
},
copy: {
images: {
expand: true,
cwd: "css/themes/default/images",
src: "**",
dest: path.join( dist, "images/" )
},
"demos.nested-includes": {
options: {
// TODO duplicated in demos.firstpass
processContent: function( content, srcPath ) {
content = content.replace( /^\s*<\?php include\(\s*['"]([^'"]+)['"].*$/gmi,
function( match, includePath /*, offset, string */ ) {
var fileToInclude = path.resolve(
path.join( path.dirname( srcPath ), includePath )
);
return grunt.file.read( fileToInclude );
}
);
return content;
}
},
files: [
{
expand: true,
src: [
"demos/jqm-contents.php",
"demos/jqm-navmenu.php",
"demos/jqm-search.php"
],
dest: dist
}
]
},
"demos.processed": {
options: {
processContent: function( content, srcPath ) {
return processDemos( content, srcPath );
}
},
files: [
{
expand: true,
src: [
"index.php",
"demos/**/*.php",
"demos/**/*.html",
"!demos/navigation-php-redirect/**",
"demos/navigation-php-redirect/index.php"
],
dest: dist,
ext: ".html"
}
]
},
"demos.php": {
options: {
processContent: function( content, srcPath ) {
return processDemos( content, srcPath );
}
},
files: [
{
expand: true,
src: [
"demos/navigation-php-redirect/*.php",
"!demos/navigation-php-redirect/index.php",
"demos/page-events/*.php",
"!demos/page-events/index.php"
],
dest: dist
}
]
},
"demos.backbone": {
options: {
processContent: function( content, srcPath ) {
var $,
processedName = grunt.config.process( name + "<%= versionSuffix %>" );
if ( /\.html$/.test( srcPath ) ) {
$ = cheerio.load( content );
$( "link[rel='stylesheet'][href]" ).each( function() {
var element = $( this );
element.attr( "href",
replaceCombinedCssReference( element.attr( "href" ),
processedName ) );
});
$( "script" ).each( function ( idx, element ) {
var script = $( element );
if ( /requirejs\.config\.js$/.test( script.attr( "src" ) ) ) {
// Get rid of the requirejs.config.js script tag since we're
// using the built bundle
script.remove();
} else if ( /require.js$/.test( script.attr( "src" ) ) ) {
// Use the CDN version for requirejs
script.attr( "src",
"//cdn.jsdelivr.net/requirejs/" +
grunt.
template.
process( "<%= pkg.devDependencies.requirejs %>" ) +
"/require.min.js" );
}
});
// write out newly created file contents
content = $.html();
} else if ( /\.js$/.test( srcPath ) ) {
// Redifines paths for compiled demos
content = content.replace( /baseUrl:.*$/m, "baseUrl: \"../js\"," );
content = content.replace( /\.\.\/external\/jquery\//, "" );
content = content.replace( /jquery\.mobile/, processedName );
content = content.replace(
/"backbone-requirejs-demos".*$/m,
"\"backbone-requirejs-demos\": \"../backbone-requirejs/js\"" );
}
return content;
}
},
files: [
{
expand: true,
src: [
"demos/backbone-requirejs/**/*",
"!demos/backbone-requirejs/index.php"
],
dest: dist
}
]
},
"demos.unprocessed": {
files: [
{
expand: true,
cwd: "external/jquery",
src: [ "jquery.js", "jquery.min.js", "jquery.min.map.js" ],
dest: path.join( dist, "demos/js/" )
},
{
expand: true,
cwd: dist,
src: [ "*.js", "*.map" ],
dest: path.join( dist, "demos/js/" )
},
{
expand: true,
cwd: dist,
src: [
"images/**"
].concat( _.pluck( files.getMinifiedCSSFiles(), "dest" ) ),
dest: path.join( dist, "demos/css/themes/default/" )
},
{
expand: true,
src: [
"demos/**/*",
"!**/*.php",
"!**/*.html",
"!demos/backbone-requirejs/js/*"
],
dest: dist
}
]
},
sourcemap: {
// Processes the sourceMap to fix
// issue: https://github.com/mishoo/UglifyJS2/issues/47
options: {
processContent: function( content /*, srcPath*/ ) {
content = content.replace( /"dist\//g, "\"" );
return content;
}
},
files: [
{
src: "<%= uglify.all.options.sourceMap %>",
dest: "<%= uglify.all.options.sourceMap %>"
}
]
},
"jqueryCDN": {
files: [{
expand: true,
cwd: dist,
src: "<%= files.cdn %>",
dest: "<%= dirs.cdn.jquery %>/"
}]
},
"googleCDN": {
options: {
processContent: function( content, srcPath ) {
if ( /\.min.js$|\.min.map$/.test( srcPath ) ) {
// We need to rewrite the map info
var re = new RegExp(
grunt.template.process( "<%= versionSuffix %>" ),
"g" );
content = content.replace( re, "" );
}
return content;
},
processContentExclude: [ "**/*.+(gif|png)" ]
},
files: {
// WARNING: This will be modified by the config:copy:noversion task
cwd: dist,
src: "<%= files.cdn %>",
dest: "<%= dirs.tmp %>"
}
},
git: {
options: {
processContent: function( content, srcPath ) {
if ( /\.min.js$|\.min.map$/.test( srcPath ) ) {
// We need to rewrite the map info
var re = new RegExp( grunt.template.process( name ), "g" );
content = content.replace( re, name + "-git" );
}
return content;
},
processContentExclude: [ "**/*.zip", "**/*.gif", "**/*.png" ]
},
files: {
// WARNING: This will be modified by the config:copy:git task
cwd: dist,
src: "<%= files.cdn %>",
dest: "<%= dirs.cdn.git %>"
}
}
},
"hash-manifest": {
googleCDN: {
options: {
algo: "md5",
cwd: "<%= dirs.tmp %>"
},
src: [ "**/*" ],
dest: "MANIFEST"
}
},
compress: {
dist: {
options: {
archive: "<%= files.distZipOut %>"
},
files: [
{
expand: true,
cwd: dist,
src: "<%= files.distZipContent %>"
}
]
},
images: {
options: {
archive: "<%= files.imagesZipOut %>"
},
files: [
{
expand: true,
cwd: dist,
src: [ "images/**" ]
}
]
},
"googleCDN": {
options: {
archive: "<%= files.googleCDNZipOut %>"
},
files: [
{
expand: true,
cwd: "<%= dirs.tmp %>",
src: [ "**/*" ]
}
]
}
},
php: {
server: {
options: {
port: phpPort,
baseUrl: "."
}
}
},
casper: {
options: {
test: true,
verbose : true,
"log-level": "error",
parallel: false
},
"demos.src": {
options: {
args: [ "--port=" + phpPort ]
},
src: [ "tests/casperjs/**/*.js" ]
},
"demos.dist": {
options: {
args: [ "--port=" + phpPort , "--path=dist" ]
},
src: [ "tests/casperjs/**/*.js" ]
}
},
connect: {
server: {
options: {
port: httpPort,
base: ".",
middleware: function( connect, options ) {
return [
// For requests to "[...]/js/" return the built jquery.mobile.js
// as opposed to the php combined version
function(req, res, next){
var bundle = grunt.config.process(
"<%= requirejs.js.options.out %>"
);
if (req.url === "/js/") {
grunt.log.debug( req.url + " requested, serving: " + bundle );
res.end( grunt.file.read( bundle ) );
} else {
next();
}
},
// Serve static files.
connect[ "static" ](options.base),
// Make empty directories browsable.
connect.directory(options.base)
];
}
}
}
},
qunit_junit: {
options: {
dest: "build/test-results",
namer: function (url) {
var match = url.match(/tests\/([^\/]*)\/(.*)$/);
return match[2].replace(/\//g, ".").replace(/\.html/, "" ).replace(/\?/, "-");
}
}
},
qunit: {
options: {
timeout: 30000,
"--web-security": "no",
coverage: {
baseUrl: ".",
src: [
"js/**/*.js",
"!js/jquery.tag.inserter.js",
"!js/requirejs.config.js"
],
instrumentedFiles: "temp/",
htmlReport: "_tests/reports/coverage",
lcovReport: "_tests/reports/lcov",
linesThresholdPct: 0
}
},
http: {
options: {
urls: (function() {
var allSuites, patterns, paths,
testDirs = [ "unit", "integration", "css" ],
suites = ( grunt.option( "suites" ) || process.env.SUITES || "" )
.split( "," ),
types = ( grunt.option( "types" ) || process.env.TYPES || "" )
.split( "," ),
versionedPaths = [],
jQueries = ( grunt.option( "jqueries" ) || process.env.JQUERIES || "" )
.split( "," ),
excludes = _.chain( suites )
.filter( function( suite ) { return ( /^!/.test( suite ) ); } )
.map( function( suite ) { return suite.substring( 1 ); } )
.value();
// Trim empties
suites = _.without( suites, "" );
types = _.without( types, "" );
jQueries = _.without( jQueries, "" );
// So that unit suites runs before integration suites
types = types.sort().reverse();
allSuites = _.chain( grunt.file.expand(
{
filter: "isDirectory",
cwd: "tests"
},
_.map( testDirs, function( dir ) {
return dir + "/*";
})
))
.map( function( dir ) { return dir.split( "/" )[ 1 ]; } )
.difference( excludes )
.unique()
.value();
// Remove negations from list of suites
suites = _.filter( suites, function( suite ) {
return ( !/^!/.test( suite ) );
});
if ( types.length ){
testDirs = [];
types.forEach(function( type ) {
testDirs.push( type );
});
}
patterns = [];
if ( !suites.length ) {
suites = allSuites;
}
_.chain( suites )
.difference( excludes )
.forEach( function( suite ) {
testDirs.forEach( function( dir ) {
dir = "tests/" + dir;
if ( suite.indexOf( "/" ) >= 0 ) {
// If the suite is a path, then append it exactly
patterns.push( dir + "/" + suite );
} else {
// If not, append all patterns we care about
patterns = patterns.concat([
dir + "/" + suite + "/index.html",
dir + "/" + suite + "/*/index.html",
dir + "/" + suite + "/**/*-tests.html"
]);
}
});
});
paths = grunt.file.expand( patterns )
.filter( function( testPath ) {
if ( grunt.file.isDir( testPath ) ) {
testPath = path.join( testPath, "index.html" );
}
return grunt.file.exists( testPath );
})
.map( function( path ) {
// Some of our tests (ie. navigation) don't like having the
// index.html too much
return path.replace( /\/index.html$/, "/" );
});
paths = grunt.util._.uniq( paths );
if ( jQueries.length ) {
paths.forEach( function( path ) {
versionedPaths = versionedPaths.concat(
jQueries.map( function( jQVersion ) {
return path + "?jquery=" + jQVersion;
}) );
});
}
if ( versionedPaths.length ) {
paths = versionedPaths;
}
return paths.map( function( path ) {
return "http://localhost:<%= connect.server.options.port %>/" + path;
});
}())
}
}
},
coveralls: {
options: {
force: true
},
all: {
// LCOV coverage file relevant to every target
src: "_tests/reports/lcov/lcov.info"
}
},
bowercopy: {
options: {
// Bower components folder will be removed afterwards
clean: true,
destPrefix: "external"
},
tests: {
files: {
"qunit/qunit.js": "qunit/qunit/qunit.js",
"qunit/qunit.css": "qunit/qunit/qunit.css",
"qunit/MIT-LICENSE.txt": "qunit/MIT-LICENSE.txt",
"jshint/jshint.js": "jshint/dist/jshint.js"
}
},
requirejs: {
files: {
"requirejs/require.js": "requirejs/require.js",
"requirejs/plugins/text.js": "requirejs-text/text.js",
"requirejs/plugins/json.js": "requirejs-plugins/src/json.js"
}
},
jquery: {
files: {
"jquery/": "jquery/dist/"
}