@@ -4,107 +4,172 @@ var fs = require( 'fs' ),
44 glob = require ( 'glob-whatev' ) ;
55
66module . exports = function ( grunt ) {
7- var global = {
8- dirs : {
9- output : 'compiled' ,
10- temp : 'tmp'
11- } ,
7+ var dirs , names ;
128
13- files : {
14- license : 'LICENSE-INFO.txt'
15- } ,
9+ dirs = {
10+ output : 'compiled' ,
11+ temp : 'tmp'
12+ } ;
1613
17- names : {
18- base : 'jquery.mobile' ,
19- // this will change for the deploy target to include version information
20- root : 'jquery.mobile' ,
21- structure : 'jquery.mobile.structure' ,
22- theme : 'jquery.mobile.theme'
23- } ,
14+ names = {
15+ base : 'jquery.mobile' ,
16+ // this will change for the deploy target to include version information
17+ root : 'jquery.mobile' ,
18+ structure : 'jquery.mobile.structure' ,
19+ theme : 'jquery.mobile.theme'
20+ } ;
2421
25- // other version information is added via the asyncConfig helper that
26- // depends on git commands (eg ver.min, ver.header)
27- ver : {
28- official : grunt . file . read ( 'version.txt' ) . replace ( / \n / , '' ) ,
29- min : "/*! jQuery Mobile v<%= build_sha %> jquerymobile.com | jquery.org/license !*/"
22+ function outputPath ( name ) {
23+ return path . join ( dirs . output , name ) ;
24+ }
25+
26+ // Project configuration.
27+ grunt . config . init ( {
28+ jshint : {
29+ options : {
30+ curly : true ,
31+ eqeqeq : true ,
32+
33+ // (function(){})() seems acceptable
34+ immed : false ,
35+ latedef : true ,
36+ newcap : true ,
37+ noarg : true ,
38+ sub : true ,
39+ undef : true ,
40+ boss : true ,
41+ eqnull : true ,
42+ browser : true
43+ } ,
44+ globals : {
45+ jQuery : true ,
46+ "$" : true ,
47+
48+ // qunit globals
49+ // TODO would be nice to confine these to test files
50+ module : true ,
51+ ok : true ,
52+ test : true ,
53+ asyncTest : true ,
54+ same : true ,
55+ start : true ,
56+ stop : true ,
57+ expect : true ,
58+
59+ // require js global
60+ define : true
61+ }
3062 } ,
3163
32- shas : { } ,
64+ lint : {
65+ files : [ 'grunt.js' , 'js/*.js' , 'tests/**/*.js' ]
66+ } ,
3367
34- helpers : {
35- // in place
36- sed : function ( file , filter ) {
37- var id , inputString = fs . readFileSync ( file ) . toString ( ) ;
68+ // NOTE these configuration settings are used _after_ compilation has taken place
69+ // using requirejs. Thus the .compiled extensions. The exception being the theme concat
70+ concat : {
71+ js : {
72+ src : [ '<banner:global.ver.header>' , outputPath ( names . root ) + '.compiled.js' ] ,
73+ dest : outputPath ( names . root ) + '.js'
74+ } ,
3875
39- inputString = filter ? filter ( inputString ) : inputString ;
76+ structure : {
77+ src : [ '<banner:global.ver.header>' , outputPath ( names . structure ) + '.compiled.css' ] ,
78+ dest : outputPath ( names . structure ) + '.css'
79+ } ,
4080
41- grunt . file . write ( file , inputString ) ;
81+ regular : {
82+ src : [ '<banner:global.ver.header>' , outputPath ( names . root ) + '.compiled.css' ] ,
83+ dest : outputPath ( names . root ) + '.css'
4284 } ,
4385
44- configExtend : function ( prop , extension ) {
45- var config = grunt . config . get ( prop ) || { } ;
86+ theme : {
87+ src : [
88+ '<banner:global.ver.header>' ,
89+ 'css/themes/default/jquery.mobile.theme.css'
90+ ] ,
91+ dest : outputPath ( names . theme ) + '.css'
92+ }
93+ } ,
94+
95+ global : {
96+ dirs : dirs ,
4697
47- for ( p in extension ) {
48- config [ p ] = extension [ p ] ;
49- }
98+ names : names ,
5099
51- grunt . config . set ( prop , config ) ;
100+ files : {
101+ license : 'LICENSE-INFO.txt'
52102 } ,
53103
54- // NOTE cargo culting my way to the top :(
55- rmdirRecursive : function ( dir ) {
56- if ( ! path . existsSync ( dir ) ) {
57- return ;
58- }
59-
60- var list = fs . readdirSync ( dir ) ;
61- for ( var i = 0 ; i < list . length ; i ++ ) {
62- var filename = path . join ( dir , list [ i ] ) ;
63- var stat = fs . statSync ( filename ) ;
64-
65- if ( filename == "." || filename == ".." ) {
66- // pass these files
67- } else if ( stat . isDirectory ( ) ) {
68- // rmdir recursively
69- this . rmdirRecursive ( filename ) ;
70- } else {
71- // rm fiilename
72- fs . unlinkSync ( filename ) ;
73- }
74- }
75- fs . rmdirSync ( dir ) ;
104+ // other version information is added via the asyncConfig helper that
105+ // depends on git commands (eg ver.min, ver.header)
106+ ver : {
107+ official : grunt . file . read ( 'version.txt' ) . replace ( / \n / , '' ) ,
108+ min : "/*! jQuery Mobile v<%= build_sha %> jquerymobile.com | jquery.org/license !*/"
76109 } ,
77110
78- asyncConfig : function ( callback ) {
79- child_process . exec ( 'git log -1 --format=format:"Git Build: SHA1: %H <> Date: %cd"' , function ( err , stdout , stderr ) {
80- global . shas . build_sha = stdout ;
81- global . ver . min = grunt . template . process ( global . ver . min , global . shas ) ;
111+ shas : { } ,
82112
83- child_process . exec ( 'git log -1 --format=format:"%H"' , function ( err , stdout , stderr ) {
84- global . shas . head_sha = stdout ;
113+ helpers : {
114+ // in place file alteration
115+ sed : function ( file , filter ) {
116+ var id , inputString = fs . readFileSync ( file ) . toString ( ) ;
85117
86- // NOTE not using a template here because the Makefile depends on the v@VERSION
87- global . ver . header = grunt . file . read ( global . files . license )
88- . replace ( / v @ V E R S I O N / , global . shas . build_sha ) ;
89- callback ( global ) ;
90- } ) ;
91- } ) ;
118+ inputString = filter ? filter ( inputString ) : inputString ;
119+
120+ grunt . file . write ( file , inputString ) ;
121+ } ,
122+
123+ // NOTE cargo culting my way to the top :(
124+ rmdirRecursive : function ( dir ) {
125+ if ( ! path . existsSync ( dir ) ) {
126+ return ;
127+ }
128+
129+ var list = fs . readdirSync ( dir ) ;
130+ for ( var i = 0 ; i < list . length ; i ++ ) {
131+ var filename = path . join ( dir , list [ i ] ) ;
132+ var stat = fs . statSync ( filename ) ;
133+
134+ if ( filename == "." || filename == ".." ) {
135+ // pass these files
136+ } else if ( stat . isDirectory ( ) ) {
137+ // rmdir recursively
138+ this . rmdirRecursive ( filename ) ;
139+ } else {
140+ // rm fiilename
141+ fs . unlinkSync ( filename ) ;
142+ }
143+ }
144+ fs . rmdirSync ( dir ) ;
145+ }
92146 }
93147 }
94- } ;
95-
96- grunt . config . set ( 'global' , global ) ;
148+ } ) ;
97149
98150 grunt . registerTask ( 'config:async' , 'git hashes for output headers' , function ( ) {
99- var done = this . async ( ) ;
151+ var done = this . async ( ) , global = grunt . config . get ( 'global' ) ;
100152
101- grunt . config . get ( 'global' ) . helpers . asyncConfig ( function ( config ) {
102- grunt . config . set ( 'global' , config ) ;
103- done ( ) ;
153+ child_process . exec ( 'git log -1 --format=format:"Git Build: SHA1: %H <> Date: %cd"' , function ( err , stdout , stderr ) {
154+ global . shas . build_sha = stdout ;
155+ global . ver . min = grunt . template . process ( global . ver . min , global . shas ) ;
156+
157+ child_process . exec ( 'git log -1 --format=format:"%H"' , function ( err , stdout , stderr ) {
158+ global . shas . head_sha = stdout ;
159+
160+ // NOTE not using a template here because the Makefile depends on the v@VERSION
161+ global . ver . header = grunt . file . read ( global . files . license )
162+ . replace ( / v @ V E R S I O N / , global . shas . build_sha ) ;
163+
164+ grunt . config . set ( 'global' , global ) ;
165+ done ( ) ;
166+ } ) ;
104167 } ) ;
105168 } ) ;
106169
107- grunt . registerTask ( 'test:config' , 'glob all the test files' , function ( ) {
170+ // TODO could use some cleanup. Eg, can we use grunt's parameter passing functionality
171+ // in place of environment variables
172+ grunt . registerTask ( 'config:test' , 'glob all the test files' , function ( ) {
108173 var done = this . async ( ) , test_paths , server_paths = [ ] , env = process . env ;
109174
110175
0 commit comments