7
|
1 module.exports = function( grunt ) {
|
|
2
|
|
3 "use strict";
|
|
4
|
|
5 var
|
|
6 // files
|
|
7 coreFiles = [
|
|
8 "jquery.ui.core.js",
|
|
9 "jquery.ui.widget.js",
|
|
10 "jquery.ui.mouse.js",
|
|
11 "jquery.ui.draggable.js",
|
|
12 "jquery.ui.droppable.js",
|
|
13 "jquery.ui.resizable.js",
|
|
14 "jquery.ui.selectable.js",
|
|
15 "jquery.ui.sortable.js",
|
|
16 "jquery.ui.effect.js"
|
|
17 ],
|
|
18
|
|
19 uiFiles = coreFiles.map(function( file ) {
|
|
20 return "ui/" + file;
|
|
21 }).concat( expandFiles( "ui/*.js" ).filter(function( file ) {
|
|
22 return coreFiles.indexOf( file.substring(3) ) === -1;
|
|
23 })),
|
|
24
|
|
25 allI18nFiles = expandFiles( "ui/i18n/*.js" ),
|
|
26
|
|
27 cssFiles = [
|
|
28 "core",
|
|
29 "accordion",
|
|
30 "autocomplete",
|
|
31 "button",
|
|
32 "datepicker",
|
|
33 "dialog",
|
|
34 "menu",
|
|
35 "progressbar",
|
|
36 "resizable",
|
|
37 "selectable",
|
|
38 "slider",
|
|
39 "spinner",
|
|
40 "tabs",
|
|
41 "tooltip",
|
|
42 "theme"
|
|
43 ].map(function( component ) {
|
|
44 return "themes/base/jquery.ui." + component + ".css";
|
|
45 }),
|
|
46
|
|
47 // minified files
|
|
48 minify = {
|
|
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 }
|
|
68 },
|
|
69
|
|
70 minifyCSS = {
|
|
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 }
|
|
81 },
|
|
82
|
|
83 compareFiles = {
|
|
84 all: [
|
|
85 "dist/jquery-ui.js",
|
|
86 "dist/jquery-ui.min.js"
|
|
87 ]
|
|
88 };
|
|
89
|
|
90 function mapMinFile( file ) {
|
|
91 return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
|
|
92 }
|
|
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
|
|
100 uiFiles.concat( allI18nFiles ).forEach(function( file ) {
|
|
101 minify[ file ] = {
|
|
102 options: {
|
|
103 banner: createBanner()
|
|
104 },
|
|
105 files: {}
|
|
106 };
|
|
107 minify[ file ].files[ mapMinFile( file ) ] = file;
|
|
108 });
|
|
109
|
|
110 cssFiles.forEach(function( file ) {
|
|
111 minifyCSS[ file ] = {
|
|
112 options: {
|
|
113 banner: createBanner()
|
|
114 },
|
|
115 src: file,
|
|
116 dest: "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" )
|
|
117 };
|
|
118 });
|
|
119
|
|
120 uiFiles.forEach(function( file ) {
|
|
121 // TODO this doesn't do anything until https://github.com/rwldrn/grunt-compare-size/issues/13
|
|
122 compareFiles[ file ] = [ file, mapMinFile( file ) ];
|
|
123 });
|
|
124
|
|
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" );
|
|
130 grunt.loadNpmTasks( "grunt-contrib-csslint" );
|
|
131 grunt.loadNpmTasks( "grunt-contrib-cssmin" );
|
|
132 grunt.loadNpmTasks( "grunt-html" );
|
|
133 grunt.loadNpmTasks( "grunt-compare-size" );
|
|
134 grunt.loadNpmTasks( "grunt-git-authors" );
|
|
135 // local testswarm and build tasks
|
|
136 grunt.loadTasks( "build/tasks" );
|
|
137
|
|
138 function stripDirectory( file ) {
|
|
139 return file.replace( /.+\/(.+?)>?$/, "$1" );
|
|
140 }
|
|
141
|
|
142 function createBanner( files ) {
|
|
143 // strip folders
|
|
144 var fileNames = files && files.map( stripDirectory );
|
|
145 return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
|
|
146 "<%= grunt.template.today('isoDate') %>\n" +
|
|
147 "<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" +
|
|
148 (files ? "* Includes: " + fileNames.join(", ") + "\n" : "")+
|
|
149 "* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
|
|
150 " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n";
|
|
151 }
|
|
152
|
|
153 grunt.initConfig({
|
|
154 pkg: grunt.file.readJSON("package.json"),
|
|
155 files: {
|
|
156 dist: "<%= pkg.name %>-<%= pkg.version %>",
|
|
157 cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
|
|
158 themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
|
|
159 },
|
|
160 compare_size: compareFiles,
|
|
161 concat: {
|
|
162 ui: {
|
|
163 options: {
|
|
164 banner: createBanner( uiFiles ),
|
|
165 stripBanners: {
|
|
166 block: true
|
|
167 }
|
|
168 },
|
|
169 src: uiFiles,
|
|
170 dest: "dist/jquery-ui.js"
|
|
171 },
|
|
172 i18n: {
|
|
173 options: {
|
|
174 banner: createBanner( allI18nFiles )
|
|
175 },
|
|
176 src: allI18nFiles,
|
|
177 dest: "dist/i18n/jquery-ui-i18n.js"
|
|
178 },
|
|
179 css: {
|
|
180 options: {
|
|
181 banner: createBanner( cssFiles ),
|
|
182 stripBanners: {
|
|
183 block: true
|
|
184 }
|
|
185 },
|
|
186 src: cssFiles,
|
|
187 dest: "dist/jquery-ui.css"
|
|
188 }
|
|
189 },
|
|
190 uglify: minify,
|
|
191 cssmin: minifyCSS,
|
|
192 htmllint: {
|
|
193 // ignore files that contain invalid html, used only for ajax content testing
|
|
194 all: grunt.file.expand( [ "demos/**/*.html", "tests/**/*.html" ] ).filter(function( file ) {
|
|
195 return !/(?:ajax\/content\d\.html|tabs\/data\/test\.html|tests\/unit\/core\/core\.html)/.test( file );
|
|
196 })
|
|
197 },
|
|
198 copy: {
|
|
199 dist: {
|
|
200 src: [
|
|
201 "AUTHORS.txt",
|
|
202 "jquery-*.js",
|
|
203 "MIT-LICENSE.txt",
|
|
204 "README.md",
|
|
205 "Gruntfile.js",
|
|
206 "package.json",
|
|
207 "*.jquery.json",
|
|
208 "ui/**/*",
|
|
209 "ui/.jshintrc",
|
|
210 "demos/**/*",
|
|
211 "themes/**/*",
|
|
212 "external/**/*",
|
|
213 "tests/**/*"
|
|
214 ],
|
|
215 renames: {
|
|
216 "dist/jquery-ui.js": "ui/jquery-ui.js",
|
|
217 "dist/jquery-ui.min.js": "ui/minified/jquery-ui.min.js",
|
|
218 "dist/i18n/jquery-ui-i18n.js": "ui/i18n/jquery-ui-i18n.js",
|
|
219 "dist/i18n/jquery-ui-i18n.min.js": "ui/minified/i18n/jquery-ui-i18n.min.js",
|
|
220 "dist/jquery-ui.css": "themes/base/jquery-ui.css",
|
|
221 "dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
|
|
222 },
|
|
223 dest: "dist/<%= files.dist %>"
|
|
224 },
|
|
225 dist_min: {
|
|
226 src: "dist/minified/**/*",
|
|
227 strip: /^dist/,
|
|
228 dest: "dist/<%= files.dist %>/ui"
|
|
229 },
|
|
230 dist_css_min: {
|
|
231 src: "dist/themes/base/minified/*.css",
|
|
232 strip: /^dist/,
|
|
233 dest: "dist/<%= files.dist %>"
|
|
234 },
|
|
235 dist_units_images: {
|
|
236 src: "themes/base/images/*",
|
|
237 strip: /^themes\/base\//,
|
|
238 dest: "dist/"
|
|
239 },
|
|
240 dist_min_images: {
|
|
241 src: "themes/base/images/*",
|
|
242 strip: /^themes\/base\//,
|
|
243 dest: "dist/<%= files.dist %>/themes/base/minified"
|
|
244 },
|
|
245 cdn: {
|
|
246 src: [
|
|
247 "AUTHORS.txt",
|
|
248 "MIT-LICENSE.txt",
|
|
249 "ui/*.js",
|
|
250 "package.json"
|
|
251 ],
|
|
252 renames: {
|
|
253 "dist/jquery-ui.js": "jquery-ui.js",
|
|
254 "dist/jquery-ui.min.js": "jquery-ui.min.js",
|
|
255 "dist/i18n/jquery-ui-i18n.js": "i18n/jquery-ui-i18n.js",
|
|
256 "dist/i18n/jquery-ui-i18n.min.js": "i18n/jquery-ui-i18n.min.js"
|
|
257 },
|
|
258 dest: "dist/<%= files.cdn %>"
|
|
259 },
|
|
260 cdn_i18n: {
|
|
261 src: "ui/i18n/jquery.ui.datepicker-*.js",
|
|
262 strip: "ui/",
|
|
263 dest: "dist/<%= files.cdn %>"
|
|
264 },
|
|
265 cdn_i18n_min: {
|
|
266 src: "dist/minified/i18n/jquery.ui.datepicker-*.js",
|
|
267 strip: "dist/minified",
|
|
268 dest: "dist/<%= files.cdn %>"
|
|
269 },
|
|
270 cdn_min: {
|
|
271 src: "dist/minified/*.js",
|
|
272 strip: /^dist\/minified/,
|
|
273 dest: "dist/<%= files.cdn %>/ui"
|
|
274 },
|
|
275 cdn_themes: {
|
|
276 src: "dist/<%= files.themes %>/themes/**/*",
|
|
277 strip: "dist/<%= files.themes %>",
|
|
278 dest: "dist/<%= files.cdn %>"
|
|
279 },
|
|
280 themes: {
|
|
281 src: [
|
|
282 "AUTHORS.txt",
|
|
283 "MIT-LICENSE.txt",
|
|
284 "package.json"
|
|
285 ],
|
|
286 dest: "dist/<%= files.themes %>"
|
|
287 }
|
|
288 },
|
|
289 zip: {
|
|
290 dist: {
|
|
291 src: "<%= files.dist %>",
|
|
292 dest: "<%= files.dist %>.zip"
|
|
293 },
|
|
294 cdn: {
|
|
295 src: "<%= files.cdn %>",
|
|
296 dest: "<%= files.cdn %>.zip"
|
|
297 },
|
|
298 themes: {
|
|
299 src: "<%= files.themes %>",
|
|
300 dest: "<%= files.themes %>.zip"
|
|
301 }
|
|
302 },
|
|
303 md5: {
|
|
304 dist: {
|
|
305 src: "dist/<%= files.dist %>",
|
|
306 dest: "dist/<%= files.dist %>/MANIFEST"
|
|
307 },
|
|
308 cdn: {
|
|
309 src: "dist/<%= files.cdn %>",
|
|
310 dest: "dist/<%= files.cdn %>/MANIFEST"
|
|
311 },
|
|
312 themes: {
|
|
313 src: "dist/<%= files.themes %>",
|
|
314 dest: "dist/<%= files.themes %>/MANIFEST"
|
|
315 }
|
|
316 },
|
|
317 qunit: {
|
|
318 files: expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
|
|
319 // disabling everything that doesn't (quite) work with PhantomJS for now
|
|
320 // TODO except for all|index|test, try to include more as we go
|
|
321 return !( /(all|index|test|dialog|dialog_deprecated|tooltip)\.html$/ ).test( file );
|
|
322 })
|
|
323 },
|
|
324 jshint: {
|
|
325 options: {
|
|
326 jshintrc: true
|
|
327 },
|
|
328 all: [
|
|
329 "ui/*.js",
|
|
330 "Gruntfile.js",
|
|
331 "build/**/*.js",
|
|
332 "tests/unit/**/*.js"
|
|
333 ]
|
|
334 },
|
|
335 csslint: {
|
|
336 base_theme: {
|
|
337 src: "themes/base/*.css",
|
|
338 options: {
|
|
339 csslintrc: ".csslintrc"
|
|
340 }
|
|
341 }
|
|
342 }
|
|
343 });
|
|
344
|
|
345 grunt.registerTask( "default", [ "lint", "test" ] );
|
|
346 grunt.registerTask( "lint", [ "asciilint", "jshint", "csslint", "htmllint" ] );
|
|
347 grunt.registerTask( "test", [ "qunit" ] );
|
|
348 grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ] );
|
|
349 grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ] );
|
|
350
|
|
351 // "copy:dist_units_images" is used by unit tests
|
|
352 grunt.registerTask( "build", [ "concat", "uglify", "cssmin", "copy:dist_units_images" ] );
|
|
353 grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist".split( " " ) );
|
|
354 grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes".split( " " ) );
|
|
355 grunt.registerTask( "release_cdn", "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_themes md5:cdn zip:cdn".split( " " ) );
|
|
356
|
|
357 };
|