18
18
19
19
uiFiles = coreFiles . map ( function ( file ) {
20
20
return "ui/" + file ;
21
- } ) . concat ( grunt . file . expandFiles ( "ui/*.js" ) . filter ( function ( file ) {
21
+ } ) . concat ( expandFiles ( "ui/*.js" ) . filter ( function ( file ) {
22
22
return coreFiles . indexOf ( file . substring ( 3 ) ) === - 1 ;
23
23
} ) ) ,
24
24
25
- allI18nFiles = grunt . file . expandFiles ( "ui/i18n/*.js" ) ,
25
+ allI18nFiles = expandFiles ( "ui/i18n/*.js" ) ,
26
26
27
27
cssFiles = [
28
28
"core" ,
46
46
47
47
// minified files
48
48
minify = {
49
- "dist/jquery-ui.min.js" : [ "<banner:meta.bannerAll>" , "dist/jquery-ui.js" ] ,
50
- "dist/i18n/jquery-ui-i18n.min.js" : [ "<banner:meta.bannerI18n>" , "dist/i18n/jquery-ui-i18n.js" ]
49
+ options : {
50
+ preserveComments : false
51
+ } ,
52
+ main : {
53
+ options : {
54
+ banner : createBanner ( uiFiles )
55
+ } ,
56
+ files : {
57
+ "dist/jquery-ui.min.js" : "dist/jquery-ui.js"
58
+ }
59
+ } ,
60
+ i18n : {
61
+ options : {
62
+ banner : createBanner ( allI18nFiles )
63
+ } ,
64
+ files : {
65
+ "dist/i18n/jquery-ui-i18n.min.js" : "dist/i18n/jquery-ui-i18n.js"
66
+ }
67
+ }
51
68
} ,
52
69
53
70
minifyCSS = {
54
- "dist/jquery-ui.min.css" : "dist/jquery-ui.css"
71
+ options : {
72
+ keepSpecialComments : 0
73
+ } ,
74
+ main : {
75
+ options : {
76
+ keepSpecialComments : '*'
77
+ } ,
78
+ src : "dist/jquery-ui.css" ,
79
+ dest : "dist/jquery-ui.min.css"
80
+ }
55
81
} ,
56
82
57
83
compareFiles = {
58
- all : [
84
+ files : [
59
85
"dist/jquery-ui.js" ,
60
86
"dist/jquery-ui.min.js"
61
87
]
@@ -65,85 +91,102 @@ function mapMinFile( file ) {
65
91
return "dist/" + file . replace ( / \. j s $ / , ".min.js" ) . replace ( / u i \/ / , "minified/" ) ;
66
92
}
67
93
94
+ function expandFiles ( files ) {
95
+ return grunt . util . _ . pluck ( grunt . file . expandMapping ( files ) , "src" ) . map ( function ( values ) {
96
+ return values [ 0 ] ;
97
+ } ) ;
98
+ }
99
+
68
100
uiFiles . concat ( allI18nFiles ) . forEach ( function ( file ) {
69
- minify [ mapMinFile ( file ) ] = [ "<banner>" , file ] ;
101
+ minify [ file ] = {
102
+ options : {
103
+ banner : createBanner ( )
104
+ } ,
105
+ files : { }
106
+ } ;
107
+ minify [ file ] . files [ mapMinFile ( file ) ] = file ;
70
108
} ) ;
71
109
72
110
cssFiles . forEach ( function ( file ) {
73
- minifyCSS [ "dist/" + file . replace ( / \. c s s $ / , ".min.css" ) . replace ( / t h e m e s \/ b a s e \/ / , "themes/base/minified/" ) ] = [ "<banner>" , "<strip_all_banners:" + file + ">" ] ;
111
+ minifyCSS [ file ] = {
112
+ options : {
113
+ banner : createBanner ( )
114
+ } ,
115
+ src : file ,
116
+ dest : "dist/" + file . replace ( / \. c s s $ / , ".min.css" ) . replace ( / t h e m e s \/ b a s e \/ / , "themes/base/minified/" )
117
+ } ;
74
118
} ) ;
75
119
76
120
uiFiles . forEach ( function ( file ) {
121
+ // TODO this doesn't do anything until https://github.com/rwldrn/grunt-compare-size/issues/13
77
122
compareFiles [ file ] = [ file , mapMinFile ( file ) ] ;
78
123
} ) ;
79
124
80
125
// grunt plugins
126
+ grunt . loadNpmTasks ( "grunt-contrib-jshint" ) ;
127
+ grunt . loadNpmTasks ( "grunt-contrib-uglify" ) ;
128
+ grunt . loadNpmTasks ( "grunt-contrib-concat" ) ;
129
+ grunt . loadNpmTasks ( "grunt-contrib-qunit" ) ;
81
130
grunt . loadNpmTasks ( "grunt-css" ) ;
82
131
grunt . loadNpmTasks ( "grunt-html" ) ;
83
132
grunt . loadNpmTasks ( "grunt-compare-size" ) ;
84
- grunt . loadNpmTasks ( "grunt-junit" ) ;
85
133
grunt . loadNpmTasks ( "grunt-git-authors" ) ;
86
134
// local testswarm and build tasks
87
135
grunt . loadTasks ( "build/tasks" ) ;
88
136
89
- grunt . registerHelper ( "strip_all_banners" , function ( filepath ) {
90
- return grunt . file . read ( filepath ) . replace ( / ^ \s * \/ \* [ \s \S ] * ?\* \/ \s * / g, "" ) ;
91
- } ) ;
92
-
93
- function stripBanner ( files ) {
94
- return files . map ( function ( file ) {
95
- return "<strip_all_banners:" + file + ">" ;
96
- } ) ;
97
- }
98
-
99
137
function stripDirectory ( file ) {
100
- // TODO: we're receiving the directive, so we need to strip the trailing >
101
- // we should be receving a clean path without the directive
102
138
return file . replace ( / .+ \/ ( .+ ?) > ? $ / , "$1" ) ;
103
139
}
104
- // allow access from banner template
105
- global . stripDirectory = stripDirectory ;
106
140
107
141
function createBanner ( files ) {
108
142
// strip folders
109
143
var fileNames = files && files . map ( stripDirectory ) ;
110
144
return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
111
145
"<%= grunt.template.today('isoDate') %>\n" +
112
- "<%= pkg.homepage ? '* ' + pkg.homepage + '\n' : '' %>" +
113
- "* Includes: " + ( files ? fileNames . join ( ", " ) : "<%= stripDirectory(grunt.task.current.file.src[1]) %>" ) + "\n" +
146
+ "<%= pkg.homepage ? '* ' + pkg.homepage + '\\ n' : '' %>" +
147
+ ( files ? "* Includes: " + fileNames . join ( ", " ) + "\n" : "" ) +
114
148
"* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
115
- " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */" ;
149
+ " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n " ;
116
150
}
117
151
118
152
grunt . initConfig ( {
119
- pkg : "<json: package.json>" ,
153
+ pkg : grunt . file . readJSON ( " package.json" ) ,
120
154
files : {
121
155
dist : "<%= pkg.name %>-<%= pkg.version %>" ,
122
156
cdn : "<%= pkg.name %>-<%= pkg.version %>-cdn" ,
123
157
themes : "<%= pkg.name %>-themes-<%= pkg.version %>"
124
158
} ,
125
- meta : {
126
- banner : createBanner ( ) ,
127
- bannerAll : createBanner ( uiFiles ) ,
128
- bannerI18n : createBanner ( allI18nFiles ) ,
129
- bannerCSS : createBanner ( cssFiles )
130
- } ,
131
159
compare_size : compareFiles ,
132
160
concat : {
133
161
ui : {
134
- src : [ "<banner:meta.bannerAll>" , stripBanner ( uiFiles ) ] ,
162
+ options : {
163
+ banner : createBanner ( uiFiles ) ,
164
+ stripBanners : {
165
+ block : true
166
+ }
167
+ } ,
168
+ src : uiFiles ,
135
169
dest : "dist/jquery-ui.js"
136
170
} ,
137
171
i18n : {
138
- src : [ "<banner:meta.bannerI18n>" , allI18nFiles ] ,
172
+ options : {
173
+ banner : createBanner ( allI18nFiles )
174
+ } ,
175
+ src : allI18nFiles ,
139
176
dest : "dist/i18n/jquery-ui-i18n.js"
140
177
} ,
141
178
css : {
142
- src : [ "<banner:meta.bannerCSS>" , stripBanner ( cssFiles ) ] ,
179
+ options : {
180
+ banner : createBanner ( cssFiles ) ,
181
+ stripBanners : {
182
+ block : true
183
+ }
184
+ } ,
185
+ src : cssFiles ,
143
186
dest : "dist/jquery-ui.css"
144
187
}
145
188
} ,
146
- min : minify ,
189
+ uglify : minify ,
147
190
cssmin : minifyCSS ,
148
191
htmllint : {
149
192
// ignore files that contain invalid html, used only for ajax content testing
@@ -158,7 +201,7 @@ grunt.initConfig({
158
201
"jquery-*.js" ,
159
202
"MIT-LICENSE.txt" ,
160
203
"README.md" ,
161
- "grunt .js" ,
204
+ "Gruntfile .js" ,
162
205
"package.json" ,
163
206
"*.jquery.json" ,
164
207
"ui/**/*" ,
@@ -278,22 +321,43 @@ grunt.initConfig({
278
321
}
279
322
} ,
280
323
qunit : {
281
- files : grunt . file . expandFiles ( "tests/unit/**/*.html" ) . filter ( function ( file ) {
324
+ files : expandFiles ( "tests/unit/**/*.html" ) . filter ( function ( file ) {
282
325
// disabling everything that doesn't (quite) work with PhantomJS for now
283
326
// TODO except for all|index|test, try to include more as we go
284
327
return ! ( / ( a l l | i n d e x | t e s t | d i a l o g | d i a l o g _ d e p r e c a t e d | t a b s | t o o l t i p ) \. h t m l $ / ) . test ( file ) ;
285
328
} )
286
329
} ,
287
- lint : {
288
- ui : "ui/*.js" ,
289
- grunt : [ "grunt.js" , "build/**/*.js" ] ,
290
- tests : "tests/unit/**/*.js"
330
+ jshint : {
331
+ ui : {
332
+ options : {
333
+ jshintrc : "ui/.jshintrc"
334
+ } ,
335
+ files : {
336
+ src : "ui/*.js"
337
+ }
338
+ } ,
339
+ grunt : {
340
+ options : {
341
+ jshintrc : ".jshintrc"
342
+ } ,
343
+ files : {
344
+ src : [ "Gruntfile.js" , "build/**/*.js" ]
345
+ }
346
+ } ,
347
+ tests : {
348
+ options : {
349
+ jshintrc : "tests/.jshintrc"
350
+ } ,
351
+ files : {
352
+ src : "tests/unit/**/*.js"
353
+ }
354
+ }
291
355
} ,
292
356
csslint : {
293
357
// nothing: []
294
358
// TODO figure out what to check for, then fix and enable
295
359
base_theme : {
296
- src : grunt . file . expandFiles ( "themes/base/*.css" ) . filter ( function ( file ) {
360
+ src : expandFiles ( "themes/base/*.css" ) . filter ( function ( file ) {
297
361
// TODO remove items from this list once rewritten
298
362
return ! ( / ( b u t t o n | d a t e p i c k e r | c o r e | d i a l o g | t h e m e ) \. c s s $ / ) . test ( file ) ;
299
363
} ) ,
@@ -307,39 +371,15 @@ grunt.initConfig({
307
371
"compatible-vendor-prefixes" : false
308
372
}
309
373
}
310
- } ,
311
- jshint : ( function ( ) {
312
- function parserc ( path ) {
313
- var rc = grunt . file . readJSON ( ( path || "" ) + ".jshintrc" ) ,
314
- settings = {
315
- options : rc ,
316
- globals : { }
317
- } ;
318
-
319
- ( rc . predef || [ ] ) . forEach ( function ( prop ) {
320
- settings . globals [ prop ] = true ;
321
- } ) ;
322
- delete rc . predef ;
323
-
324
- return settings ;
325
- }
326
-
327
- return {
328
- grunt : parserc ( ) ,
329
- ui : parserc ( "ui/" ) ,
330
- // TODO: `evil: true` is only for document.write() https://github.com/jshint/jshint/issues/519
331
- // TODO: don't create so many globals in tests
332
- tests : parserc ( "tests/" )
333
- } ;
334
- } ) ( )
374
+ }
335
375
} ) ;
336
376
337
- grunt . registerTask ( "default" , "lint csslint htmllint qunit" ) ;
338
- grunt . registerTask ( "sizer" , "concat:ui min:dist/jquery-ui.min.js compare_size:all" ) ;
339
- grunt . registerTask ( "sizer_all" , "concat:ui min compare_size" ) ;
340
- grunt . registerTask ( "build" , "concat min cssmin copy:dist_units_images" ) ;
341
- grunt . registerTask ( "release" , "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" ) ;
342
- grunt . registerTask ( "release_themes" , "release generate_themes copy:themes md5:themes zip:themes" ) ;
343
- grunt . registerTask ( "release_cdn" , "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_min_images copy:cdn_themes md5:cdn zip:cdn" ) ;
377
+ grunt . registerTask ( "default" , [ "jshint" , " csslint" , " htmllint" , " qunit" ] ) ;
378
+ grunt . registerTask ( "sizer" , [ "concat:ui" , "uglify:main" , " compare_size:all" ] ) ;
379
+ grunt . registerTask ( "sizer_all" , [ "concat:ui" , "uglify" , " compare_size" ] ) ;
380
+ grunt . registerTask ( "build" , [ "concat" , "uglify" , " cssmin" , " copy:dist_units_images" ] ) ;
381
+ grunt . registerTask ( "release" , "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" . split ( " " ) ) ;
382
+ grunt . registerTask ( "release_themes" , "release generate_themes copy:themes md5:themes zip:themes" . split ( " " ) ) ;
383
+ grunt . registerTask ( "release_cdn" , "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_min_images copy:cdn_themes md5:cdn zip:cdn" . split ( " " ) ) ;
344
384
345
385
} ;
0 commit comments