@@ -124,11 +124,13 @@ uiFiles.forEach(function( file ) {
124
124
125
125
// grunt plugins
126
126
grunt . loadNpmTasks ( "grunt-compare-size" ) ;
127
+ grunt . loadNpmTasks ( "grunt-contrib-clean" ) ;
127
128
grunt . loadNpmTasks ( "grunt-contrib-concat" ) ;
128
129
grunt . loadNpmTasks ( "grunt-contrib-csslint" ) ;
129
130
grunt . loadNpmTasks ( "grunt-contrib-cssmin" ) ;
130
131
grunt . loadNpmTasks ( "grunt-contrib-jshint" ) ;
131
132
grunt . loadNpmTasks ( "grunt-contrib-qunit" ) ;
133
+ grunt . loadNpmTasks ( "grunt-contrib-requirejs" ) ;
132
134
grunt . loadNpmTasks ( "grunt-contrib-uglify" ) ;
133
135
grunt . loadNpmTasks ( "grunt-git-authors" ) ;
134
136
grunt . loadNpmTasks ( "grunt-html" ) ;
@@ -157,23 +159,6 @@ grunt.initConfig({
157
159
} ,
158
160
compare_size : compareFiles ,
159
161
concat : {
160
- ui : {
161
- options : {
162
- banner : createBanner ( uiFiles ) ,
163
- stripBanners : {
164
- block : true
165
- }
166
- } ,
167
- src : uiFiles ,
168
- dest : "dist/jquery-ui.js"
169
- } ,
170
- i18n : {
171
- options : {
172
- banner : createBanner ( allI18nFiles )
173
- } ,
174
- src : allI18nFiles ,
175
- dest : "dist/i18n/jquery-ui-i18n.js"
176
- } ,
177
162
css : {
178
163
options : {
179
164
banner : createBanner ( cssFiles ) ,
@@ -194,6 +179,11 @@ grunt.initConfig({
194
179
} )
195
180
} ,
196
181
copy : {
182
+ dist_bundle_js : {
183
+ src : "dist/build/jquery-ui.js" ,
184
+ strip : / ^ d i s t \/ b u i l d \/ / ,
185
+ dest : "dist/"
186
+ } ,
197
187
dist_units_images : {
198
188
src : "themes/base/images/*" ,
199
189
strip : / ^ t h e m e s \/ b a s e \/ / ,
@@ -208,6 +198,14 @@ grunt.initConfig({
208
198
} )
209
199
} ,
210
200
jshint : {
201
+ dist_bundle_js : {
202
+ options : {
203
+ jshintrc : ".bundlejshintrc"
204
+ } ,
205
+ files : {
206
+ src : "dist/jquery-ui.js"
207
+ }
208
+ } ,
211
209
ui : {
212
210
options : {
213
211
jshintrc : "ui/.jshintrc"
@@ -240,16 +238,92 @@ grunt.initConfig({
240
238
csslintrc : ".csslintrc"
241
239
}
242
240
}
241
+ } ,
242
+ "pre-requirejs" : {
243
+ all : {
244
+ components : coreFiles . concat ( uiFiles . map ( function ( file ) {
245
+ return file . replace ( / u i \/ / , "" ) ;
246
+ } ) ) ,
247
+ dest : "dist/tmp/main.js"
248
+ }
249
+ } ,
250
+ requirejs : {
251
+ all : {
252
+ options : {
253
+ dir : "dist/build" ,
254
+ appDir : "ui" ,
255
+ baseUrl : "." ,
256
+ optimize : "none" ,
257
+ optimizeCss : "none" ,
258
+ paths : {
259
+ "jquery" : "../jquery-1.9.1" ,
260
+ "jqueryui" : "." ,
261
+ "main" : "../dist/tmp/main" // FIXME replace to <%= %>
262
+ } ,
263
+ /* try use include: [] instead adding dist/tmp/main with require(...) */
264
+ modules : [ {
265
+ name : "jquery-ui" ,
266
+ include : [ "main" ] ,
267
+ exclude : [ "jquery" ] ,
268
+ create : true
269
+ } ] ,
270
+ wrap : {
271
+ start : createBanner ( ) + "(function( $ ) {" ,
272
+ end : "})( jQuery );"
273
+ } ,
274
+ onBuildWrite : function ( id , path , contents ) {
275
+ if ( ( / d e f i n e \( [ \s \S ] * ?f a c t o r y / ) . test ( contents ) ) {
276
+ // Remove UMD wrapper
277
+ contents = contents . replace ( / \( f u n c t i o n \( f a c t o r y [ \s \S ] * ?\( f u n c t i o n \( \$ \) \{ / , "" ) ;
278
+ contents = contents . replace ( / \} \) \) ; \s * ?$ / , "" ) ;
279
+ }
280
+ else if ( ( / ^ r e q u i r e \( \[ / ) . test ( contents ) ) {
281
+ // Replace require with comment `//` instead of null string, because of the mysterious semicolon
282
+ contents = contents . replace ( / ^ r e q u i r e [ \s \S ] * ?\] \) ; $ / , "// mysterious semicolon: " ) ;
283
+ }
284
+
285
+ return contents ;
286
+ }
287
+ }
288
+ }
289
+ } ,
290
+ "post-requirejs" : {
291
+ all : [
292
+ "dist/build/jquery-ui.js"
293
+ ]
294
+ } ,
295
+ clean : {
296
+ dist_garbage : [ "dist/build" , "dist/tmp" ]
243
297
}
244
298
} ) ;
245
299
300
+ grunt . registerMultiTask ( "pre-requirejs" , "Create require that will include appropriate components' dependencies" , function ( ) {
301
+ if ( this . data . components . length ) {
302
+ grunt . file . write ( this . data . dest , "require([\n\t\"jqueryui/" + this . data . components . map ( function ( file ) {
303
+ return file . replace ( / \. j s / , "" ) ;
304
+ } ) . join ( "\",\n\t\"jqueryui/" ) + "\"\n]);" ) ;
305
+ }
306
+ } ) ;
307
+
308
+ grunt . registerMultiTask ( 'post-requirejs' , "Strip define call from dist file" , function ( ) {
309
+ this . filesSrc . forEach ( function ( filepath ) {
310
+ // Remove `define("main" ...)` and `define("jquery-ui" ...)`
311
+ var contents = grunt . file . read ( filepath ) . replace ( / d e f i n e \( " ( m a i n | j q u e r y - u i ) " , f u n c t i o n \( \) \{ \} \) ; / g, "" ) ;
312
+
313
+ // Remove the mysterious semicolon `;` character left from require([...]);
314
+ contents = contents . replace ( / \/ \/ m y s t e r i o u s s e m i c o l o n .* / g, "" ) ;
315
+
316
+ grunt . file . write ( filepath , contents ) ;
317
+ } ) ;
318
+ } ) ;
319
+
246
320
grunt . registerTask ( "default" , [ "lint" , "test" ] ) ;
247
321
grunt . registerTask ( "lint" , [ "jshint" , "csslint" , "htmllint" ] ) ;
248
- grunt . registerTask ( "test" , [ "qunit" ] ) ;
322
+ grunt . registerTask ( "test" , [ "copy:dist_units_images" , " qunit" ] ) ;
249
323
grunt . registerTask ( "sizer" , [ "concat:ui" , "uglify:main" , "compare_size:all" ] ) ;
250
324
grunt . registerTask ( "sizer_all" , [ "concat:ui" , "uglify" , "compare_size" ] ) ;
251
325
252
- // " copy:dist_units_images" is used by unit tests
253
- grunt . registerTask ( "build" , [ "concat" , "uglify" , "cssmin" , "copy:dist_units_images" ] ) ;
326
+ grunt . registerTask ( "build" , [ "clean" , "pre-requirejs" , "requirejs" , "post-requirejs" , " copy:dist_bundle_js" , "clean:dist_garbage" , "jshint:dist_bundle_js" ] ) ;
327
+
254
328
255
329
} ;
0 commit comments