fixing librejs on defectivebydesign.org
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules / civicrm / packages / jquery / jquery-ui-1.9.0 / development-bundle / grunt.js
1 /*jshint node: true */
2 module.exports = function( grunt ) {
3
4 var
5 // files
6 coreFiles = [
7 "jquery.ui.core.js",
8 "jquery.ui.widget.js",
9 "jquery.ui.mouse.js",
10 "jquery.ui.draggable.js",
11 "jquery.ui.droppable.js",
12 "jquery.ui.resizable.js",
13 "jquery.ui.selectable.js",
14 "jquery.ui.sortable.js",
15 "jquery.ui.effect.js"
16 ],
17
18 uiFiles = coreFiles.map(function( file ) {
19 return "ui/" + file;
20 }).concat( grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
21 return coreFiles.indexOf( file.substring(3) ) === -1;
22 })),
23
24 allI18nFiles = grunt.file.expandFiles( "ui/i18n/*.js" ),
25
26 cssFiles = [
27 "core",
28 "accordion",
29 "autocomplete",
30 "button",
31 "datepicker",
32 "dialog",
33 "menu",
34 "progressbar",
35 "resizable",
36 "selectable",
37 "slider",
38 "spinner",
39 "tabs",
40 "tooltip",
41 "theme"
42 ].map(function( component ) {
43 return "themes/base/jquery.ui." + component + ".css";
44 }),
45
46 // minified files
47 minify = {
48 "dist/jquery-ui.min.js": [ "<banner:meta.bannerAll>", "dist/jquery-ui.js" ],
49 "dist/i18n/jquery-ui-i18n.min.js": [ "<banner:meta.bannerI18n>", "dist/i18n/jquery-ui-i18n.js" ]
50 },
51
52 minifyCSS = {
53 "dist/jquery-ui.min.css": "dist/jquery-ui.css"
54 },
55
56 compareFiles = {
57 all: [
58 "dist/jquery-ui.js",
59 "dist/jquery-ui.min.js"
60 ]
61 };
62
63 function mapMinFile( file ) {
64 return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
65 }
66
67 uiFiles.concat( allI18nFiles ).forEach(function( file ) {
68 minify[ mapMinFile( file ) ] = [ "<banner>", file ];
69 });
70
71 cssFiles.forEach(function( file ) {
72 minifyCSS[ "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" ) ] = [ "<banner>", "<strip_all_banners:" + file + ">" ];
73 });
74
75 uiFiles.forEach(function( file ) {
76 compareFiles[ file ] = [ file, mapMinFile( file ) ];
77 });
78
79 // grunt plugins
80 grunt.loadNpmTasks( "grunt-css" );
81 grunt.loadNpmTasks( "grunt-html" );
82 grunt.loadNpmTasks( "grunt-compare-size" );
83 grunt.loadNpmTasks( "grunt-junit" );
84 grunt.loadNpmTasks( "grunt-git-authors" );
85 // local testswarm and build tasks
86 grunt.loadTasks( "build/tasks" );
87
88 grunt.registerHelper( "strip_all_banners", function( filepath ) {
89 return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" );
90 });
91
92 function stripBanner( files ) {
93 return files.map(function( file ) {
94 return "<strip_all_banners:" + file + ">";
95 });
96 }
97
98 function stripDirectory( file ) {
99 // TODO: we're receiving the directive, so we need to strip the trailing >
100 // we should be receving a clean path without the directive
101 return file.replace( /.+\/(.+?)>?$/, "$1" );
102 }
103 // allow access from banner template
104 global.stripDirectory = stripDirectory;
105
106 function createBanner( files ) {
107 // strip folders
108 var fileNames = files && files.map( stripDirectory );
109 return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
110 "<%= grunt.template.today('isoDate') %>\n" +
111 "<%= pkg.homepage ? '* ' + pkg.homepage + '\n' : '' %>" +
112 "* Includes: " + (files ? fileNames.join(", ") : "<%= stripDirectory(grunt.task.current.file.src[1]) %>") + "\n" +
113 "* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
114 " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */";
115 }
116
117 grunt.initConfig({
118 pkg: "<json:package.json>",
119 files: {
120 dist: "<%= pkg.name %>-<%= pkg.version %>",
121 cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
122 themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
123 },
124 meta: {
125 banner: createBanner(),
126 bannerAll: createBanner( uiFiles ),
127 bannerI18n: createBanner( allI18nFiles ),
128 bannerCSS: createBanner( cssFiles )
129 },
130 compare_size: compareFiles,
131 concat: {
132 ui: {
133 src: [ "<banner:meta.bannerAll>", stripBanner( uiFiles ) ],
134 dest: "dist/jquery-ui.js"
135 },
136 i18n: {
137 src: [ "<banner:meta.bannerI18n>", allI18nFiles ],
138 dest: "dist/i18n/jquery-ui-i18n.js"
139 },
140 css: {
141 src: [ "<banner:meta.bannerCSS>", stripBanner( cssFiles ) ],
142 dest: "dist/jquery-ui.css"
143 }
144 },
145 min: minify,
146 cssmin: minifyCSS,
147 htmllint: {
148 // ignore files that contain invalid html, used only for ajax content testing
149 all: grunt.file.expand( [ "demos/**/*.html", "tests/**/*.html" ] ).filter(function( file ) {
150 return !/(?:ajax\/content\d\.html|tabs\/data\/test\.html|tests\/unit\/core\/core\.html)/.test( file );
151 })
152 },
153 copy: {
154 dist: {
155 src: [
156 "AUTHORS.txt",
157 "jquery-*.js",
158 "MIT-LICENSE.txt",
159 "README.md",
160 "grunt.js",
161 "package.json",
162 "*.jquery.json",
163 "ui/**/*",
164 "demos/**/*",
165 "themes/**/*",
166 "external/**/*",
167 "tests/**/*"
168 ],
169 renames: {
170 "dist/jquery-ui.js": "ui/jquery-ui.js",
171 "dist/jquery-ui.min.js": "ui/minified/jquery-ui.min.js",
172 "dist/i18n/jquery-ui-i18n.js": "ui/i18n/jquery-ui-i18n.js",
173 "dist/i18n/jquery-ui-i18n.min.js": "ui/minified/i18n/jquery-ui-i18n.min.js",
174 "dist/jquery-ui.css": "themes/base/jquery-ui.css",
175 "dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
176 },
177 dest: "dist/<%= files.dist %>"
178 },
179 dist_min: {
180 src: "dist/minified/**/*",
181 strip: /^dist/,
182 dest: "dist/<%= files.dist %>/ui"
183 },
184 dist_css_min: {
185 src: "dist/themes/base/minified/*.css",
186 strip: /^dist/,
187 dest: "dist/<%= files.dist %>"
188 },
189 dist_units_images: {
190 src: "themes/base/images/*",
191 strip: /^themes\/base\//,
192 dest: "dist/"
193 },
194 dist_min_images: {
195 src: "themes/base/images/*",
196 strip: /^themes\/base\//,
197 dest: "dist/<%= files.dist %>/themes/base/minified"
198 },
199 cdn: {
200 src: [
201 "AUTHORS.txt",
202 "MIT-LICENSE.txt",
203 "ui/*.js",
204 "package.json"
205 ],
206 renames: {
207 "dist/jquery-ui.js": "jquery-ui.js",
208 "dist/jquery-ui.min.js": "jquery-ui.min.js",
209 "dist/i18n/jquery-ui-i18n.js": "i18n/jquery-ui-i18n.js",
210 "dist/i18n/jquery-ui-i18n.min.js": "i18n/jquery-ui-i18n.min.js",
211 "dist/jquery-ui.css": "themes/base/jquery-ui.css",
212 "dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
213 },
214 dest: "dist/<%= files.cdn %>"
215 },
216 cdn_i18n: {
217 src: "ui/i18n/jquery.ui.datepicker-*.js",
218 strip: "ui/",
219 dest: "dist/<%= files.cdn %>"
220 },
221 cdn_i18n_min: {
222 src: "dist/minified/i18n/jquery.ui.datepicker-*.js",
223 strip: "dist/minified",
224 dest: "dist/<%= files.cdn %>"
225 },
226 cdn_min: {
227 src: "dist/minified/*.js",
228 strip: /^dist\/minified/,
229 dest: "dist/<%= files.cdn %>/ui"
230 },
231 cdn_min_images: {
232 src: "themes/base/images/*",
233 strip: /^themes\/base\//,
234 dest: "dist/<%= files.cdn %>/themes/base/minified"
235 },
236 cdn_themes: {
237 src: "dist/<%= files.themes %>/themes/**/*",
238 strip: "dist/<%= files.themes %>",
239 dest: "dist/<%= files.cdn %>"
240 },
241 themes: {
242 src: [
243 "AUTHORS.txt",
244 "MIT-LICENSE.txt",
245 "package.json"
246 ],
247 dest: "dist/<%= files.themes %>"
248 }
249 },
250 zip: {
251 dist: {
252 src: "<%= files.dist %>",
253 dest: "<%= files.dist %>.zip"
254 },
255 cdn: {
256 src: "<%= files.cdn %>",
257 dest: "<%= files.cdn %>.zip"
258 },
259 themes: {
260 src: "<%= files.themes %>",
261 dest: "<%= files.themes %>.zip"
262 }
263 },
264 md5: {
265 dist: {
266 src: "dist/<%= files.dist %>",
267 dest: "dist/<%= files.dist %>/MANIFEST"
268 },
269 cdn: {
270 src: "dist/<%= files.cdn %>",
271 dest: "dist/<%= files.cdn %>/MANIFEST"
272 },
273 themes: {
274 src: "dist/<%= files.themes %>",
275 dest: "dist/<%= files.themes %>/MANIFEST"
276 }
277 },
278 qunit: {
279 files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
280 // disabling everything that doesn't (quite) work with PhantomJS for now
281 // TODO except for all|index|test, try to include more as we go
282 return !( /(all|all-active|index|test|draggable|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tabs_deprecated)\.html$/ ).test( file );
283 })
284 },
285 lint: {
286 ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
287 // TODO remove items from this list once rewritten
288 return !( /(mouse|datepicker|draggable|droppable|resizable|selectable|sortable)\.js$/ ).test( file );
289 }),
290 grunt: [ "grunt.js", "build/**/*.js" ],
291 tests: "tests/unit/**/*.js"
292 },
293 csslint: {
294 // nothing: []
295 // TODO figure out what to check for, then fix and enable
296 base_theme: {
297 src: grunt.file.expandFiles( "themes/base/*.css" ).filter(function( file ) {
298 // TODO remove items from this list once rewritten
299 return !( /(button|datepicker|core|dialog|theme)\.css$/ ).test( file );
300 }),
301 // TODO consider reenabling some of these rules
302 rules: {
303 "import": false,
304 "important": false,
305 "outline-none": false,
306 // especially this one
307 "overqualified-elements": false
308 }
309 }
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 // TODO: use "faux strict mode" https://github.com/jshint/jshint/issues/504
329 // TODO: limit `smarttabs` to multi-line comments https://github.com/jshint/jshint/issues/503
330 options: parserc(),
331 ui: parserc( "ui/" ),
332 // TODO: `evil: true` is only for document.write() https://github.com/jshint/jshint/issues/519
333 // TODO: don't create so many globals in tests
334 tests: parserc( "tests/" )
335 };
336 })()
337 });
338
339 grunt.registerTask( "default", "lint csslint htmllint qunit" );
340 grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size:all" );
341 grunt.registerTask( "sizer_all", "concat:ui min compare_size" );
342 grunt.registerTask( "build", "concat min cssmin copy:dist_units_images" );
343 grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" );
344 grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes" );
345 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" );
346
347 };