This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 203
/
build.xml
1530 lines (1433 loc) · 71.5 KB
/
build.xml
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
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="Boilerplate Build" default="build" basedir="../"><!-- one back since we're in build/ -->
<!-- load shell environment -->
<property environment="ENV" />
<!-- load property files -->
<property file="build/config/project.properties"/><property file="build/config/default.properties"/>
<!-- Load in Ant-Contrib to give us access to some very useful tasks! -->
<!-- the .jar file is located in the tools directory -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${basedir}/${dir.build.tools}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- merge the stylesheet properties -->
<var name="stylesheet-files" value="${file.default.stylesheets}, ${file.stylesheets}"/>
<!-- merge the pages properties -->
<var name="page-files" value="${file.pages}, ${file.pages.default.include}"/>
<!-- Test for Ant Version Delete this task and all instances of overwrite='no' if you can't upgrade to latest-->
<fail message="All features of the build script require Ant version 1.8.2 or greater. Please upgrade to the latest version or remove all instances of 'overwrite=no' (and this fail task) from the build script to continue">
<condition>
<not>
<antversion atleast="1.8.2"/>
</not>
</condition>
</fail>
<target name="version">
<echo message="H5BP Ant Build Script Version ${project.version}"/>
</target>
<!--
*************************************************
* BASE TARGETS *
*************************************************
-->
<target name="basics">
<if>
<equals arg1="${env}" arg2="dev"/>
<then>
<!-- Build a dev environment -->
<echo message="Building a Development Environment..."/>
<antcall target="-basics.dev"/>
</then>
<elseif>
<equals arg1="${env}" arg2="test"/>
<then>
<!-- Build a test environment -->
<echo message="Building a Test Environment..."/>
<antcall target="-basics.test"/>
</then>
</elseif>
<else>
<!-- Build a production environment -->
<echo message="Building a Production Environment..."/>
<antcall target="-basics.production"/>
</else>
</if>
</target>
<target name="text">
<if>
<equals arg1="${env}" arg2="dev"/>
<then>
<!-- Build a dev environment -->
<echo message="Building a Development Environment..."/>
<antcall target="-text.dev"/>
</then>
<elseif>
<equals arg1="${env}" arg2="test"/>
<then>
<!-- Build a test environment -->
<echo message="Building a Test Environment..."/>
<antcall target="-text.test"/>
</then>
</elseif>
<else>
<!-- Build a production environment -->
<echo message="Building a Production Environment..."/>
<antcall target="-text.production"/>
</else>
</if>
</target>
<target name="buildkit">
<if>
<equals arg1="${env}" arg2="dev"/>
<then>
<!-- Build a dev environment -->
<echo message="Building a Development Environment..."/>
<antcall target="-buildkit.dev"/>
</then>
<elseif>
<equals arg1="${env}" arg2="test"/>
<then>
<!-- Build a test environment -->
<echo message="Building a Test Environment..."/>
<antcall target="-buildkit.test"/>
</then>
</elseif>
<else>
<!-- Build a production environment -->
<echo message="Building a Production Environment..."/>
<antcall target="-buildkit.production"/>
</else>
</if>
</target>
<target name="build">
<if>
<equals arg1="${env}" arg2="dev"/>
<then>
<!-- Build a dev environment -->
<echo message="Building a Development Environment..."/>
<antcall target="-build.dev" />
</then>
<elseif>
<equals arg1="${env}" arg2="test"/>
<then>
<!-- Build a test environment -->
<echo message="Building a Test Environment..."/>
<antcall target="-build.test" />
</then>
</elseif>
<else>
<!-- Build a production environment -->
<echo message="Building a Production Environment..."/>
<antcall target="-build.production" />
</else>
</if>
</target>
<target name="minify">
<if>
<equals arg1="${env}" arg2="dev"/>
<then>
<!-- Build a dev environment -->
<echo message="Building a Development Environment..."/>
<antcall target="-minify.dev"/>
</then>
<elseif>
<equals arg1="${env}" arg2="test"/>
<then>
<!-- Build a test environment -->
<echo message="Building a Test Environment..."/>
<antcall target="-minify.test"/>
</then>
</elseif>
<else>
<!-- Build a production environment -->
<echo message="Building a Production Environment..."/>
<antcall target="-minify.production"/>
</else>
</if>
</target>
<target name="clean" depends="-clean"/>
<!-- JSLint target, run separately -->
<target name="jslint">
<apply dir="${dir.source}/${dir.js}" executable="java" parallel="false" failonerror="true">
<fileset dir="./${dir.source}/">
<include name="**/${dir.js}/*.js"/>
<exclude name="**/*.min.js"/>
<exclude name="${dir.intermediate}/**/*.js"/>
<exclude name="**/${dir.js.libs}/"/>
<exclude name="**/${dir.publish}/"/>
</fileset>
<arg value="-jar" />
<arg path="./${dir.build.tools}/${tool.rhino}" />
<arg path="./${dir.build.tools}/${tool.jslint}" />
<srcfile/>
<arg value="${tool.jslint.opts}" />
</apply>
<echo>JSLint Successful</echo>
</target>
<!-- JSHint target, run separately -->
<target name="jshint">
<apply dir="${dir.source}/${dir.js}" executable="java" parallel="false" failonerror="true">
<fileset dir="./${dir.source}/">
<include name="**/${dir.js}/*.js"/>
<exclude name="**/*.min.js"/>
<exclude name="${dir.intermediate}/**/*.js"/>
<exclude name="**/${dir.js.libs}/"/>
<exclude name="**/${dir.publish}/"/>
</fileset>
<arg value="-jar" />
<arg path="./${dir.build.tools}/${tool.rhino}" />
<arg path="./${dir.build.tools}/${tool.jshint}" />
<srcfile/>
<arg value="${tool.jshint.opts}" />
</apply>
<echo>JSHint Successful</echo>
</target>
<!-- CSSLint target, run separately -->
<target name="csslint">
<apply dir="${dir.source}/${dir.css}" executable="java" parallel="false" failonerror="true">
<fileset dir="./${dir.source}/">
<include name="**/${dir.css}/*.css"/>
<exclude name="**/*.min.css"/>
<exclude name="**/${dir.publish}/"/>
</fileset>
<arg value="-jar" />
<arg path="./${dir.build.tools}/${tool.rhino}" />
<arg path="./${dir.build.tools}/${tool.csslint}" />
<srcfile/>
<arg value="${tool.csslint.opts}" />
</apply>
<echo>CSSLint Successful</echo>
</target>
<!-- Validate target, run separately -->
<target name="validate">
<apply dir="${dir.source}/" executable="java" parallel="false">
<fileset dir="./${dir.source}/">
<include name="${file.root.page}"/>
</fileset>
<arg value="-jar" />
<arg path="./${dir.build.tools}/HTMLValidator.jar" />
<arg value="http://validator.nu" />
<srcfile/>
</apply>
<echo>HTML validator successful</echo>
</target>
<!-- qunit target Example only since this will fit very differently into different workflows -->
<target name="qunit" description="runs QUnit tests using PhantomJS">
<apply executable="${basedir}/${dir.build.tools}/${tool.phantomJS}" >
<fileset dir="${dir.tests}"/>
<arg value="${basedir}/${dir.build.tools}/${tool.qunitrunner.js}" />
<arg value="--qunit"/>
<arg path="${basedir}/${dir.build.tools}/${tool.qunit.js}" />
<arg value="--tests"/>
<arg path="${dir.tests}" />
<srcfile/>
</apply>
</target>
<!--
*************************************************
* BUILD TARGETS *
*************************************************
-->
<!-- Target: basics -->
<target name="-basics.dev"
depends="version,
-intro,
-copyall"/>
<target name="-basics.test"
depends="version,
-intro,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-copy,
-jsdoc3"/>
<target name="-basics.production"
depends="version,
-intro,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-copy,
-jsdoc3"/>
<!-- Target: text -->
<target name="-text.dev"
depends="version,
-intro,
-copyall"/>
<target name="-text.test"
depends="version,
-intro,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlclean,
-copy,
-jsdoc3"/>
<target name="-text.production"
depends="version,
-intro,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlclean,
-copy,
-jsdoc3"/>
<!-- Target: buildkit -->
<target name="-buildkit.dev"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-copyall"/>
<target name="-buildkit.test"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlbuildkit,
-copy,
-jsdoc3"/>
<target name="-buildkit.production"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlbuildkit,
-copy,
-jsdoc3"/>
<!-- Target: build -->
<target name="-build.dev"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-copyall"/>
<target name="-build.test"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlclean,
-copy,
-jsdoc3"/>
<target name="-build.production"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlclean,
-copy,
-jsdoc3"/>
<!-- Target: minify -->
<target name="-minify.dev"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-copyall"/>
<target name="-minify.test"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlcompress,
-copy,
-jsdoc3"/>
<target name="-minify.production"
depends="version,
-intro,
-imagespng,
-imagesjpg,
-usemin,
-js.all.minify,
-js.main.concat,
-js.scripts.concat,
-css,
-htmlcompress,
-copy,
-jsdoc3"/>
<!--
*************************************************
* FUNCTION TARGETS *
*************************************************
-->
<target name="-clean" description="(PRIVATE) Wipe the previous build (Deletes the dir.publish directory">
<!-- This is a private target -->
<echo message="Cleaning up previous build directory..."/>
<delete dir="./${dir.intermediate}/"/>
<delete dir="./${dir.publish}/"/>
</target>
<target name="compile">
<javac
target="1.5"
fork="true"
srcdir="${dir.build.tools}"
destdir="${dir.build.tools}"
includeantruntime="false" />
</target>
<target name="-intro" description="(PRIVATE) Kindly inform the developer about the impending magic">
<!-- This is a private target -->
<echo message="====================================================================="/>
<echo message="Welcome to the HTML5 Boilerplate Build Script!"/>
<echo message=" "/>
<echo message="We're going to get your site all ship-shape and ready for prime time."/>
<echo message=" "/>
<echo message="This should take somewhere between 15 seconds and a few minutes,"/>
<echo message="mostly depending on how many images we're going to compress."/>
<echo message=" "/>
<echo message="Feel free to come back or stay here and follow along."/>
<echo message="====================================================================="/>
<echo message=" "/>
<echo message=" "/>
</target>
<target name="-mkdirs">
<condition property="publish.exists">
<available file="${dir.publish}" type="dir"/>
</condition>
<condition property="intermediate.exists">
<available file="${dir.intermediate}" type="dir"/>
</condition>
<if>
<or>
<equals arg1="${dir.publish}" arg2="."/>
<equals arg1="${dir.publish}" arg2=".."/>
<equals arg1="${dir.publish}" arg2="/"/>
<equals arg1="${dir.publish}" arg2="./"/>
<equals arg1="${dir.publish}" arg2="../"/>
</or>
<then>
<fail message="Your dir.publish folder is set to ${dir.publish} which could delete your entire site or worse. Change it in project.properties"/>
</then>
<else>
<echo message="Creating directory structure... ${dir.publish}"/>
<if>
<and>
<equals arg1="${publish.exists}" arg2="true"/>
<equals arg1="${intermediate.exists}" arg2="true"/>
</and>
<then>
<echo message="The directories ${dir.publish} and ${dir.intermediate} already exist."/>
</then>
<else>
<mkdir dir="${dir.intermediate}"/>
<copy todir="${dir.intermediate}" includeEmptyDirs="true">
<dirset dir="${dir.source}/" excludes="${file.default.exclude}, ${file.exclude}"/>
</copy>
<mkdir dir="${dir.publish}"/>
<copy todir="${dir.publish}" includeEmptyDirs="true">
<dirset dir="${dir.source}/" excludes="${file.default.exclude}, ${file.exclude}" includes="*"/>
</copy>
</else>
</if>
</else>
</if>
</target>
<target name="-copy" depends="-mkdirs">
<!-- This is a private target -->
<echo message="Copying over new files..."/>
<copy todir="./${dir.publish}" includeEmptyDirs="false">
<fileset dir="${dir.source}/" excludes="${file.default.exclude}, ${file.exclude}">
<!-- exclude files that are superseded by optimized versions with different names -->
<!-- this is not strictly necessary, but it avoids putting unreferenced files into your server -->
<exclude name="${dir.js}/**/*.js"/>
<exclude name="${dir.js.modules}"/>
<exclude name="${dir.css}/**/*.css"/>
</fileset>
</copy>
<echo message="A copy of all new non-dev files are now in: ./${dir.publish}."/>
</target>
<target name="-copyall" depends="-mkdirs">
<!-- This is a private target -->
<!-- Copies all files, including .css and .js files for when you aren't minifying-->
<echo message="Copying over all files..."/>
<copy todir="./${dir.publish}">
<fileset dir="${dir.source}/" excludes="${file.default.exclude}, ${file.exclude}"></fileset>
</copy>
<echo message="A copy of all non-dev files are now in: ./${dir.publish}."/>
</target>
<!-- JAVASCRIPT -->
<!-- Alternative version of -js.main.concat target
uncomment this and comment out the next target to do a manual filelist
To use, add your files to the list of file names, e.g.
<file name="plugins.js"/>
<file name="scripts.js"/>
<file name="foo.js"/>
<file name="bar.js"/>
It's not magic, but at least now you can bypass the automatic concatenation.
<target name="-js.main.concat" depends="-js.all.minify" description="(PRIVATE) Concatenates the JS files in dir.js">
<filelist id="scripts.toconcat" dir="./${dir.intermediate}/">
<file name="js/plugins.js"/>
<file name="js/scripts.js"/>
</filelist>
<concat destfile="./${dir.intermediate}/${dir.js}/scripts-concat.min.js" overwrite="no">
<filelist refid="scripts.toconcat"/>
</concat>
</target>
-->
<target name="-js.main.concat" depends="-js.all.minify" description="(PRIVATE) Concatenates the JS files in dir.js">
<filelist id="file.root" dir="${dir.source}" files="${file.root.page}"/>
<echo message="Concatenating Main JS scripts based on ${file.root.page}..."/>
<exec executable="java" outputproperty="scriptsToConcat">
<arg value="-classpath" />
<arg value="${dir.build.tools}" />
<arg value="FindAttribute" />
<arg value="${file.root.page}" />
<arg value="${build.jstoken}" />
<arg value="script" />
<arg value="src" />
</exec>
<!-- Concatenate scripts to intermediate/js/libs/libs.js -->
<!-- overwrite=no here means not to overwrite if the target is newer than the sources -->
<!-- Filter out byte order marks (see http://stackoverflow.com/questions/2742735/get-ant-concat-to-ignore-boms) -->
<concat destfile="./${dir.intermediate}/${dir.js}/scripts-concat.min.js" overwrite="no">
<filelist dir="./${dir.intermediate}/" files="${scriptsToConcat}" />
<filterchain>
<deletecharacters chars="" />
</filterchain>
</concat>
</target>
<target name="-js.scripts.concat" depends="-js.main.concat" if="build.concat.scripts">
<echo message="Concatenating library file with main script file"/>
<if>
<available file="${dir.intermediate}/${dir.js}/scripts-concat.min.js"/>
<then>
<checksum file="${dir.intermediate}/${dir.js}/scripts-concat.min.js" algorithm="sha" property="scripts.fullsha" />
<propertyregex property="scripts.sha" input="${scripts.fullsha}" regexp=".{${hash.length}}" select="\0" />
<property name="scripts.js" value="${dir.js}/${scripts.sha}.js" />
<copy file="${dir.intermediate}/${dir.js}/scripts-concat.min.js" tofile="${dir.publish}/${dir.js}/${scripts.sha}.js" />
</then>
</if>
<!-- cachebust modules directory name -->
<!-- Concatinate only to generate checksum. Concatinated file not actually published. -->
<if>
<available file="./${dir.intermediate}/${dir.js.modules}"/>
<then>
<concat destfile="./${dir.intermediate}/${dir.js.modules}/_all.js" overwrite="no">
<fileset dir="./${dir.intermediate}/${dir.js.modules}/">
<include name="*.js"/>
</fileset>
</concat>
<if>
<available file="./${dir.intermediate}/${dir.js.modules}/_all.js"/>
<then>
<checksum file="${dir.intermediate}/${dir.js.modules}/_all.js" algorithm="sha" property="modules.fullsha" />
<propertyregex property="modules.sha" input="${modules.fullsha}" regexp=".{${hash.length}}" select="\0" />
<property name="modules.js.dir" value="${dir.js}/${modules.sha}" />
<move file="${dir.publish}/${dir.js.modules}/" tofile="${dir.publish}/${dir.js}/${modules.sha}/" />
<copy todir="${dir.publish}/${dir.js}/${modules.sha}/" >
<fileset dir="${dir.intermediate}/${dir.js.modules}" includes="**/**.js" excludes="_all.js" />
</copy>
</then>
</if>
</then>
</if>
</target>
<target name="-js.all.minify" depends="-mkdirs" description="(PRIVATE) Minifies the scripts.js files created by js.scripts.concat">
<echo message="Minifying scripts"/>
<copy todir="${dir.intermediate}/${dir.js}">
<fileset dir="${dir.source}/${dir.js}" includes="${file.js.bypass}, **/*.min.js"/>
</copy>
<apply executable="java" parallel="false">
<fileset dir="${dir.source}/${dir.js}" excludes="${file.js.bypass}, **/*.min.js" includes="**/*.js">
<exclude name="${dir.js}/otherscripts-concat.js"/>
<exclude name="${dir.js}/scripts-concat.js"/>
</fileset>
<arg line="-jar"/>
<arg path="./${dir.build.tools}/${tool.compiler}"/>
<arg line="--js"/>
<srcfile/>
<arg line="--compilation_level" />
<arg value="${scripts.compilation.level}" />
<arg line="--warning_level" />
<arg value="${scripts.compilation.warninglevel}" />
<arg line="--js_output_file" />
<mapper type="glob" from="*.js" to="${basedir}/${dir.intermediate}/${dir.js}/*.js"/>
<targetfile/>
</apply>
<!-- at this point all js files are minified with their original names -->
<copy todir="${dir.publish}/${dir.js}">
<fileset dir="${dir.intermediate}/${dir.js}" includes="${file.js.bypass}, ${slug.libs}/*, ${slug.modules}/*">
<exclude name="scripts-concat.js"/>
<exclude name="scripts-concat.min.js"/>
<exclude name="otherscripts-concat.js"/>
<exclude name="plugins.js"/>
<exclude name="${file.root.script}"/>
</fileset>
</copy>
</target>
<!-- HTML -->
<target name="-usemin" depends="-js.scripts.concat,-rev.image.filenames" description="(PRIVATE) Replaces references to non-minified scripts">
<echo message="Switching to minified js files..."/>
<!-- switch from a regular jquery to minified -->
<replaceregexp match="jquery-(\d|\d(\.\d)+)\.js" replace="jquery-\1.min.js" flags="g">
<fileset dir="./${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<!-- switch any google CDN reference to minified -->
<replaceregexp match="(\d|\d(\.\d)+)\/jquery\.js" replace="\1/jquery.min.js" flags="g">
<fileset dir="./${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<echo>Kill off those versioning flags: ?v=2</echo>
<replaceregexp match='\?v=\d+">' replace='">' flags="g">
<fileset dir="./${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<echo>Remove favicon.ico reference if it is pointing to the root</echo>
<replaceregexp match="<link rel=["']shortcut icon["'] href=["']/favicon\.ico["']>" replace="">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<!-- we maintain the apple-touch-icon reference for Android 2.2 www.ravelrumba.com/blog/android-apple-touch-icon
<replace token="<link rel="apple-touch-icon" href="/apple-touch-icon.png">" value="">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replace>
-->
<echo message="Update the HTML to reference our concatenated script file: ${scripts.js}"/>
<!-- Determines which Regex for AMD use -->
<var name="matchRegex" value=""/>
<var name="replaceRegex" value=""/>
<if>
<isset property="script.require.path"/>
<then>
<echo message="Updating HTML to reflect the use of RequireJS"/>
<var name="matchRegex" value="<!-- //-beg- ${build.jstoken} [\d\w\s\W]*<script.*data-main=['"]?(.*)/${file.root.script}(?:\?.*)?['"] src=['"]?(.*)${script.require.path}(?:\?.*)?['"]?\s*>\s*</script>[\d\w\s\W]**<!-- //-end- ${build.jstoken} -->"/>
<var name="replaceRegex" value="<script data-main='\1/${scripts.sha}.js\' src='${script.require.path}'></script>"/>
</then>
<else>
<replaceregexp
match="<!-- //-beg- ${build.jstoken} [\d\w\s\W]*<script.*src=['"]?(.*)/${file.root.script}(?:\?.*)?['"]?\s*>\s*</script>[\d\w\s\W]*<!-- //-end- ${build.jstoken} -->"
replace="<script src="\1/${scripts.sha}.js" ${scripts.async} ${scripts.defer} ></script>"
flags="gs">
<fileset dir="${dir.intermediate}" includes="${page-files}" />
</replaceregexp>
</else>
</if>
<!-- style.css replacement handled as a replacetoken above -->
<replaceregexp match="${matchRegex}" replace="${replaceRegex}" flags="m">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<!--[! use comments like this one to avoid having them get minified -->
<echo message="Update the HTML to reference our name-mangled modules directory"/>
<replaceregexp match="<script.*src=['"]?${dir.js.modules}/(.*)['"]\s*>"
replace="<script src='${modules.js.dir}/\1'>" flags="mg">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<!-- Save the concatenated and minified version of style.css, since we were working with it
earlier when revving image filenames [target: -rev.image.filenames] -->
<checksum file="${dir.intermediate}/${dir.css}/style-concat.min.css" algorithm="sha" property="css.fullsha" />
<propertyregex property="css.sha" input="${css.fullsha}" regexp=".{${hash.length}}" select="\0" />
<property name="style.css" value="${dir.css}/${css.sha}.css" />
<copy file="${dir.intermediate}/${dir.css}/style-concat.min.css" tofile="${dir.publish}/${dir.css}/${css.sha}.css" />
<echo message="Updating the HTML with the new css filename: ${style.css}"/>
<replaceregexp match="<link(.+)href=['"]?(.*)/${file.root.stylesheet}(?:\?.*)?['"\s]?(.*/?>)"
replace="<link\1href='\2/${css.sha}.css'\3" flags="m">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<!-- Tidy up HTML when compiling LESS -->
<if>
<equals arg1="${build.css.less}" arg2="true"/>
<then>
<echo message="Removing LESS CSS Script from HTML..."/>
<replaceregexp match="<!-- less script [\d\w\s\W]* end less script -->" replace="">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<echo message="Changing rel attribute to 'stylesheet' from 'stylesheet/less'"/>
<replaceregexp match="rel=['"]stylesheet/less['"]" replace="rel='stylesheet'">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
</then>
</if>
<foreach list="${file.stylesheets}" param="css_file" target="-css-remove-concatenated-stylesheets" />
</target>
<target name="-htmlclean" depends="-usemin">
<echo message="Run htmlcompressor on the HTML"/>
<echo message=" - maintaining whitespace"/>
<echo message=" - removing html comments"/>
<echo message=" - compressing inline style/script tag contents"/>
<apply executable="java" parallel="false">
<fileset dir="${dir.intermediate}/" includes="${page-files}"/>
<arg value="-jar"/>
<arg path="${dir.build.tools}/${tool.htmlcompressor}"/>
<arg line="${tool.htmlcompressor.opts} ${tool.htmlcompressor.javascript} ${tool.htmlcompressor.opts.extra}"/>
<srcfile/>
<arg value="-o"/>
<mapper type="glob" from="*" to="${basedir}/${dir.publish}/*"/>
<targetfile/>
</apply>
</target>
<target name="-htmlbuildkit" depends="-usemin">
<echo message="Run htmlcompressor on the HTML"/>
<echo message=" - maintaining whitespace"/>
<echo message=" - retain html comments"/>
<echo message=" - compressing inline style/script tag contents"/>
<apply executable="java" parallel="false">
<fileset dir="${dir.intermediate}/" includes="${page-files}"/>
<arg value="-jar"/>
<arg path="${dir.build.tools}/${tool.htmlcompressor}"/>
<arg value="--preserve-comments"/>
<arg line="--preserve-multi-spaces"/>
<arg line="--compress-js"/>
<arg line="--compress-css"/>
<arg line="--preserve-php"/>
<arg line="--preserve-ssi"/>
<srcfile/>
<arg value="-o"/>
<mapper type="glob" from="*" to="${basedir}/${dir.publish}/*"/>
<targetfile/>
</apply>
</target>
<target name="-htmlcompress" depends="-usemin">
<echo message="Run htmlcompressor on the HTML"/>
<echo message=" - removing unnecessary whitespace"/>
<echo message=" - removing html comments"/>
<echo message=" - compressing inline style/script tag contents"/>
<apply executable="java" parallel="false">
<fileset dir="${dir.intermediate}/" includes="${page-files}"/>
<arg value="-jar"/>
<arg path="${dir.build.tools}/${tool.htmlcompressor}"/>
<arg line="--remove-quotes"/>
<arg line="--compress-js"/>
<arg line="--compress-css"/>
<arg line="--preserve-php"/>
<arg line="--preserve-ssi"/>
<srcfile/>
<arg value="-o"/>
<mapper type="glob" from="*" to="${basedir}/${dir.publish}/*"/>
<targetfile/>
</apply>
</target>
<!-- CSS -->
<target name="-css-remove-concatenated-stylesheets">
<echo>Removing ${css_file} from html</echo>
<replaceregexp match="<link.+href=".*${css_file}".*>" replace=" " byline="true">
<fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
</target>
<target name="css-split" description="turns style.css into multiple files @imported together">
<copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${file.root.stylesheet}.temp"/>
<replaceregexp file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp"
match=".*"
replace="/* remove me */" flags="s" />
<loadfile property="root" srcfile="${dir.source}/${dir.css}/${file.root.stylesheet}"/>
<var name="curr.buffer" value=""/>
<for delimiter="${line.separator}" param="currline" list="${root}">
<sequential>
<!-- does this line contain an h5bp-import? -->
<propertyregex property="export.name" input="@{currline}" regexp="^\/\*==\|== +(.*) +====\*\/+$" select="\1" casesensitive="true" override="true" />
<if>
<isset property="export.name"/>
<then>
<propertyregex property="export.name" input="${export.name}" regexp=" " replace="." global="true" override="true" />
<var name="export.name" value="${export.name}.css"/>
<if>
<isset property="curr.file"/>
<then>
<!-- create curr.file -->
<copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${curr.file}" overwrite="true"/>
<!-- write the curr.buffer into the curr.file -->
<replaceregexp file="${dir.source}/${dir.css}/${curr.file}"
match=".*"
replace="${curr.buffer}" flags="s" />
<var name="curr.buffer" value=""/>
<var name="curr.file" unset="true"/>
</then>
</if>
<var name="curr.file" value="${export.name}"/>
<var name="export.name" unset="true"/>
<!-- insert import line into new root -->
<replace file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp" token="/* remove me */" value="@import url(${curr.file});${line.separator}/* remove me */"/>
</then>
</if>
<var name="curr.buffer" value="${curr.buffer}@{currline}${line.separator}" />
</sequential>
</for>
<!-- one more time to write out the last file -->
<if>
<isset property="curr.file"/>
<then>
<!-- create curr.file -->
<copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${curr.file}" overwrite="true"/>
<!-- write the curr.buffer into the curr.file -->
<replaceregexp file="${dir.source}/${dir.css}/${curr.file}"
match=".*"
replace="${curr.buffer}" flags="s" />
<var name="curr.buffer" value=""/>
<var name="curr.file" unset="true"/>
</then>
</if>
<replace file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp" token="/* remove me */" value="${curr.buffer}"/>
<copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${file.root.stylesheet}.orig" overwrite="false"/>
<move file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp" tofile="${dir.source}/${dir.css}/${file.root.stylesheet}" overwrite="false"/>
</target>
<target name="-css" depends="-mkdirs" description="Concatenates and Minifies any stylesheets @imported via the file.stylesheets">
<echo message="Concatenating any @imports..."/>
<!-- copy source file to intermediate directory -->
<copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"/>
<!-- replace imports with h5bp-import tags (part 1) this one wraps @media types -->
<replaceregexp file="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"
match="^@import\s+(?:url\s*\(\s*['"]?|['"])((?!http:|https:|ftp:|\/\/)[^"^'^\s]+)(?:['"]?\s*\)|['"])\s*([\w\s\(\)\d\:,\-]*);.*$"
replace="@media \2{ /* h5bp-import: \1 */ }" byline="true" />
<!-- replace imports with h5bp-import tags (part 2) -->
<replaceregexp file="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"
match="^@media \{ (/\* .* \*/) \}" replace="\1" byline="true" />
<!-- copy skeleton to concat file -->
<copy file="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"
tofile="${dir.intermediate}/${dir.css}/style-concat.css" overwrite="true"/>
<!-- load the file into a property -->
<loadfile property="imports" srcfile="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"/>
<var name="concat-files" value="${file.root.stylesheet}"/>
<!-- go over the file line by line -->
<for delimiter="${line.separator}" param="import" list="${imports}">
<sequential>
<!-- does this line contain an h5bp-import? -->
<propertyregex property="file.name" input="@{import}" regexp="/\* h5bp-import: (.*) \*/" select="\1" casesensitive="true" override="true" />
<if>
<isset property="file.name"/>
<then>
<var name="concat-files" value="${file.name},${concat-files}"/>
<!-- load the file into a variable -->
<loadfile property="file.contents" srcFile="${dir.source}/${dir.css}/${file.name}"/>
<!-- Get base filename -->
<basename property="base.file.name" file="${file.name}"/>
<!-- Get relative path from file.name -->
<propertyregex property="relative.path" input="${file.name}" regexp="(.*)(?=${base.file.name})" select="\0" override="true"/>
<!--
Set the relative path to images within the imported file if the path
does not start with data, http, https, ftp or // -->
<propertyregex property="file.contents" input="${file.contents}" override="true" regexp="(url\((?!['\u0022])|url\(['\u0022])(?!data|http:|https:|ftp:|\/\/)" replace="\0${relative.path}"/>
<!-- pop that file into the concatenated output file -->
<replace file="${dir.intermediate}/${dir.css}/style-concat.css" token="/* h5bp-import: ${file.name} */" value="${file.contents}"/>
<var name="file.contents" unset="true"/>
</then>
</if>
</sequential>
</for>
<if>
<equals arg1="${build.css.less}" arg2="true"/>
<then>
<echo message="Processing LESS CSS..."/>
<lessjs input="${dir.intermediate}/${dir.css}/style-concat.css" output="${dir.intermediate}/${dir.css}/style-concat.css" />
<!-- load the generated LESS file and check if it contains errors -->
<loadfile property="generatedLESS" srcfile="${dir.intermediate}/${dir.css}/style-concat.css" />
<propertyregex property="errorLESS" input="${generatedLESS}" regexp="Error :" select="\1" casesensitive="true" />
<if>
<equals arg1="${errorLESS}" arg2="\1" />
<then>
<fail message="LESS Compilation Error: ${generatedLESS}" />
</then>
</if>
</then>
<else>
<echo message="NOT Processing LESS CSS"/>
</else>
</if>
<if>
<equals arg1="${build.css.scss}" arg2="true"/>
<then>
<echo message="Processing SASS (SCSS) CSS..."/>
<copy file="${dir.intermediate}/${dir.css}/style-concat.css" tofile="${dir.intermediate}/${dir.css}/style-concat.scss" />
<scss input="${dir.intermediate}/${dir.css}/style-concat.scss" output="${dir.intermediate}/${dir.css}/style-concat.css" />
</then>
<else>
<echo message="NOT Processing SASS (SCSS) CSS"/>
</else>
</if>
<echo message="Minifying css..."/>
<apply executable="java" parallel="false">
<fileset dir="${dir.intermediate}/${dir.css}/" includes="style-concat.css"/>
<arg line="-jar"/>
<arg path="${dir.build.tools}/${tool.yuicompressor}"/>
<srcfile/>
<arg line="-o"/>
<mapper type="merge" to="${basedir}/${dir.intermediate}/${dir.css}/style-concat.min.css"/>
<targetfile/>
</apply>
<echo message="Minifying any unconcatenated css files..."/>
<apply executable="java" parallel="false">
<fileset dir="${dir.source}/${dir.css}/" excludes="${concat-files}" includes="**/*.css"/>
<arg line="-jar"/>
<arg path="${dir.build.tools}/${tool.yuicompressor}"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.css" to="${basedir}/${dir.publish}/${dir.css}/*.css"/>
<targetfile/>
</apply>
</target>
<!-- bring back the glory of hot pink -->
<target name="hawterize">
<replace file="${dir.source}/${dir.css}/${file.root.stylesheet}"
token="#b3d4fc"
value="#fe57a1" />
</target>
<!-- IMAGES -->
<target name="-imagespng" depends="-mkdirs" description="(PRIVATE) Optimizes .png images using optipng and advpng">
<echo message="Optimizing images..."/>
<echo message="This part might take a while."/>
<echo message=" "/>
<echo message="First, we run optipng on the .png files..."/>
<if>
<equals arg1="${images.strip.metadata}" arg2="true"/>
<then>
<var name="strip-meta-tags" value="-strip all"/>
</then>
<else>
<var name="strip-meta-tags" value="-strip all"/>
</else>
</if>
<if>
<os family="windows"/>
<then>
<var name="optipng.available" value="true"/>
<var name="optipng.executable" value="${basedir}/${dir.build.tools}/${tool.optipng}"/>
</then>
</if>
<if>
<os family="unix"/>
<then>
<var name="optipng.executable" value="optipng"/>
</then>
</if>
<if>
<not>
<available file="optipng" filepath="${ENV.PATH}"/>
</not>
<then>
<var name="optipng.inpath" value="false"/>
</then>
<else>
<var name="optipng.inpath" value="true"/>
</else>
</if>
<if>
<and>
<equals arg1="${images.optipng.newer}" arg2="true"/>
<os family="unix"/>
<equals arg1="${optipng.inpath}" arg2="true"/>
</and>
<then>
<var name="optipng.available" value="true"/>
</then>