1
- var _basename , demoIndexTemplate , docsTemplate , flatten , stripBanner ,
1
+ var _basename , bundleJsIntro , bundleI18nIntro , bundleOutro , demoIndexTemplate , docsTemplate , flatten , stripBanner ,
2
+ async = require ( "async" ) ,
2
3
banner = require ( "./banner" ) ,
3
4
Files = require ( "./files" ) ,
4
5
fs = require ( "fs" ) ,
5
6
handlebars = require ( "handlebars" ) ,
6
7
path = require ( "path" ) ,
8
+ rjs = require ( "./rjs" ) ,
7
9
sqwish = require ( "sqwish" ) ,
8
10
ThemeRoller = require ( "./themeroller" ) ,
9
11
util = require ( "./util" ) ;
10
12
13
+ bundleJsIntro = "(function( factory ) {\n" +
14
+ " if ( typeof define === \"function\" && define.amd ) {\n" +
15
+ "\n" +
16
+ " // AMD. Register as an anonymous module.\n" +
17
+ " define([ \"jquery\" ], factory );\n" +
18
+ " } else {\n" +
19
+ "\n" +
20
+ " // Browser globals\n" +
21
+ " factory( jQuery );\n" +
22
+ " }\n" +
23
+ "}(function( $ ) {" ;
24
+
25
+ bundleI18nIntro = "(function( factory ) {\n" +
26
+ " if ( typeof define === \"function\" && define.amd ) {\n" +
27
+ "\n" +
28
+ " // AMD. Register as an anonymous module.\n" +
29
+ " define([ \"jquery\" ], factory );\n" +
30
+ " } else {\n" +
31
+ "\n" +
32
+ " // Browser globals\n" +
33
+ " factory( jQuery );\n" +
34
+ " }\n" +
35
+ "}(function( $ ) {\n" +
36
+ "\n" +
37
+ "var datepicker = $.datepicker;\n" ;
38
+
39
+ bundleOutro = "}));" ;
11
40
demoIndexTemplate = handlebars . compile ( fs . readFileSync ( __dirname + "/../template/zip/demos_index.html" , "utf8" ) ) ;
12
41
docsTemplate = handlebars . compile ( fs . readFileSync ( __dirname + "/../template/zip/docs.html" , "utf8" ) ) ;
13
42
flatten = util . flatten ;
@@ -20,11 +49,51 @@ path.basename = function() {
20
49
return _basename . apply ( _basename , arguments ) . replace ( / \/ $ / , "" ) ;
21
50
} ;
22
51
52
+ function camelCase ( input ) {
53
+ return input . toLowerCase ( ) . replace ( / [ - / ] ( .) / g, function ( match , group1 ) {
54
+ return group1 . toUpperCase ( ) ;
55
+ } ) ;
56
+ }
57
+
58
+ function rjsConfig ( attributes ) {
59
+ return {
60
+ files : attributes . files ,
61
+ config : {
62
+ appDir : "ui" ,
63
+ baseUrl : "." ,
64
+ paths : {
65
+ jquery : "../" + attributes . files . jqueryCore [ 0 ] . path . replace ( / \. j s $ / , "" )
66
+ } ,
67
+ wrap : {
68
+ start : attributes . intro ,
69
+ end : bundleOutro
70
+ } ,
71
+ modules : [ {
72
+ name : "output" ,
73
+ include : attributes . include ,
74
+ exclude : attributes . exclude ,
75
+ create : true
76
+ } ] ,
77
+ onBuildWrite : function ( id , path , contents ) {
78
+ var name = camelCase ( id . replace ( / u i \/ / , "" ) . replace ( / \. j s $ / , "" ) ) ;
79
+ return contents
80
+
81
+ // Remove UMD wrapper.
82
+ . 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 \( [ ^ \) ] * \) \{ / , "" )
83
+ . replace ( / \} \) \) ; \s * ?$ / , "" )
84
+
85
+ // Replace return exports for var =.
86
+ . replace ( / \n r e t u r n / , "\nvar " + name + " =" ) ;
87
+ }
88
+ }
89
+ } ;
90
+ }
91
+
23
92
/**
24
93
* Builder 1.11
25
94
*/
26
- function Builder_1_11_0 ( build , jqueryUi , components , options ) {
27
- var _bundleCss , baseCss , baseCssMin , cssComponentFileNames , docsCategories , existingCss , jsComponentFileNames , selectedDemoRe , selectedRe ,
95
+ function Builder_1_11_0 ( build , jqueryUi , components , options , callback ) {
96
+ var _bundleCss , baseCss , baseCssMin , cssComponentFileNames , docsCategories , existingCss , selectedDemoRe , selectedRe ,
28
97
files = jqueryUi . files ( ) ,
29
98
min = function ( file ) {
30
99
return files . min ( file ) ;
@@ -69,41 +138,6 @@ function Builder_1_11_0( build, jqueryUi, components, options ) {
69
138
return ( / i m a g e s / ) . test ( file . path ) ;
70
139
} ) ;
71
140
72
- // I18n files
73
- if ( components . indexOf ( "datepicker" ) >= 0 ) {
74
- build . i18nFiles = files . i18nFiles ;
75
- build . i18nMinFiles = files . i18nFiles . map ( min ) ;
76
- build . bundleI18n = Files ( {
77
- path : "jquery-ui-i18n.js" ,
78
- data : files . i18nFiles . reduce ( function ( sum , file ) {
79
- return sum + stripBanner ( file ) ;
80
- } , banner ( jqueryUi . pkg , files . i18nFiles . paths ( ) . map ( path . basename ) ) )
81
- } ) ;
82
- build . bundleI18nMin = Files ( {
83
- path : "jquery-ui-i18n.min.js" ,
84
- data : banner ( jqueryUi . pkg , files . i18nFiles . paths ( ) . map ( path . basename ) , { minify : true } ) + stripBanner ( files . min ( build . bundleI18n [ 0 ] ) )
85
- } ) ;
86
- } else {
87
- build . i18nFiles = build . i18nMinFiles = build . bundleI18n = build . bundleI18nMin = Files ( ) ;
88
- }
89
-
90
- // Bundle JS (and minified)
91
- jsComponentFileNames = components . map ( function ( component ) {
92
- return component + ".js" ;
93
- } ) ;
94
- build . bundleJs = Files ( {
95
- path : "jquery-ui.js" ,
96
- data : build . components . reduce ( function ( sum , component ) {
97
- return sum + stripBanner ( files . get ( "ui/" + component + ".js" ) ) ;
98
- } , banner ( jqueryUi . pkg , jsComponentFileNames ) )
99
- } ) ;
100
- build . bundleJsMin = Files ( {
101
- path : "jquery-ui.min.js" ,
102
- data : build . components . reduce ( function ( sum , component ) {
103
- return sum + stripBanner ( files . min ( files . get ( "ui/" + component + ".js" ) ) ) ;
104
- } , banner ( jqueryUi . pkg , jsComponentFileNames , { minify : true } ) )
105
- } ) ;
106
-
107
141
// Bundle CSS (and minified)
108
142
existingCss = function ( component ) {
109
143
return files . get ( "themes/base/" + component + ".css" ) !== undefined ;
@@ -208,7 +242,82 @@ function Builder_1_11_0( build, jqueryUi, components, options ) {
208
242
// Ad hoc
209
243
build . jqueryCore = files . jqueryCore ;
210
244
211
- return build ;
245
+ // I18n files
246
+ function i18nFiles ( callback ) {
247
+ if ( components . indexOf ( "datepicker" ) >= 0 ) {
248
+ build . i18nFiles = files . i18nFiles ;
249
+ build . i18nMinFiles = files . i18nFiles . map ( min ) ;
250
+ async . series ( [
251
+ function ( callback ) {
252
+ rjs ( rjsConfig ( {
253
+ files : files ,
254
+ intro : bundleI18nIntro ,
255
+ include : files . i18nFiles . rename ( / u i \/ / , "" ) . rename ( / \. j s $ / , "" ) . paths ( ) ,
256
+ exclude : [ "jquery" , "core" , "datepicker" ]
257
+ } ) , function ( error , data ) {
258
+ if ( error ) {
259
+ return callback ( error ) ;
260
+ }
261
+ build . bundleI18n = Files ( {
262
+ path : "jquery-ui-i18n.js" ,
263
+ data : banner ( jqueryUi . pkg , files . i18nFiles . paths ( ) . map ( path . basename ) ) + data
264
+ } ) ;
265
+ callback ( ) ;
266
+ } ) ;
267
+ } ,
268
+ function ( callback ) {
269
+ build . bundleI18nMin = Files ( {
270
+ path : "jquery-ui-i18n.min.js" ,
271
+ data : banner ( jqueryUi . pkg , files . i18nFiles . paths ( ) . map ( path . basename ) , { minify : true } ) + stripBanner ( files . min ( build . bundleI18n [ 0 ] ) )
272
+ } ) ;
273
+ callback ( ) ;
274
+ }
275
+ ] , callback ) ;
276
+ } else {
277
+ build . i18nFiles = build . i18nMinFiles = build . bundleI18n = build . bundleI18nMin = Files ( ) ;
278
+ callback ( ) ;
279
+ }
280
+ }
281
+
282
+ // Bundle JS (and minified)
283
+ function bundleJs ( callback ) {
284
+ var jsComponentFileNames = components . map ( function ( component ) {
285
+ return component + ".js" ;
286
+ } ) ;
287
+ async . series ( [
288
+ function ( callback ) {
289
+ rjs ( rjsConfig ( {
290
+ files : files ,
291
+ intro : bundleJsIntro ,
292
+ include : components ,
293
+ exclude : [ "jquery" ]
294
+ } ) , function ( error , data ) {
295
+ if ( error ) {
296
+ return callback ( error ) ;
297
+ }
298
+ build . bundleJs = Files ( {
299
+ path : "jquery-ui.js" ,
300
+ data : banner ( jqueryUi . pkg , jsComponentFileNames ) + data
301
+ } ) ;
302
+ callback ( ) ;
303
+ } ) ;
304
+ } ,
305
+ function ( callback ) {
306
+ build . bundleJsMin = Files ( {
307
+ path : "jquery-ui.min.js" ,
308
+ data : banner ( jqueryUi . pkg , jsComponentFileNames , { minify : true } ) + stripBanner ( files . min ( build . bundleJs [ 0 ] ) )
309
+ } ) ;
310
+ callback ( ) ;
311
+ }
312
+ ] , callback ) ;
313
+ }
314
+
315
+ async . series ( [
316
+ i18nFiles ,
317
+ bundleJs
318
+ ] , function ( error ) {
319
+ callback ( error , build ) ;
320
+ } ) ;
212
321
}
213
322
214
323
module . exports = Builder_1_11_0 ;
0 commit comments