Skip to content

Commit f87b4e0

Browse files
committed
Build: Migrate to grunt 0.4. Rename to Gruntfile, upgrade to newer grunt-css and grunt-html, update custom tasks. Drop qunit-junit plugin, not worth the trouble. Update release script to run grunt-prepare after npm-install.
1 parent 4d67f4f commit f87b4e0

File tree

4 files changed

+153
-111
lines changed

4 files changed

+153
-111
lines changed

grunt.js renamed to Gruntfile.js

Lines changed: 116 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ var
1818

1919
uiFiles = coreFiles.map(function( file ) {
2020
return "ui/" + file;
21-
}).concat( grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
21+
}).concat( expandFiles( "ui/*.js" ).filter(function( file ) {
2222
return coreFiles.indexOf( file.substring(3) ) === -1;
2323
})),
2424

25-
allI18nFiles = grunt.file.expandFiles( "ui/i18n/*.js" ),
25+
allI18nFiles = expandFiles( "ui/i18n/*.js" ),
2626

2727
cssFiles = [
2828
"core",
@@ -46,16 +46,42 @@ var
4646

4747
// minified files
4848
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+
}
5168
},
5269

5370
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+
}
5581
},
5682

5783
compareFiles = {
58-
all: [
84+
files: [
5985
"dist/jquery-ui.js",
6086
"dist/jquery-ui.min.js"
6187
]
@@ -65,85 +91,102 @@ function mapMinFile( file ) {
6591
return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
6692
}
6793

94+
function expandFiles( files ) {
95+
return grunt.util._.pluck( grunt.file.expandMapping( files ), "src" ).map(function( values ) {
96+
return values[ 0 ];
97+
});
98+
}
99+
68100
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;
70108
});
71109

72110
cssFiles.forEach(function( file ) {
73-
minifyCSS[ "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "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( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" )
117+
};
74118
});
75119

76120
uiFiles.forEach(function( file ) {
121+
// TODO this doesn't do anything until https://github.com/rwldrn/grunt-compare-size/issues/13
77122
compareFiles[ file ] = [ file, mapMinFile( file ) ];
78123
});
79124

80125
// 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" );
81130
grunt.loadNpmTasks( "grunt-css" );
82131
grunt.loadNpmTasks( "grunt-html" );
83132
grunt.loadNpmTasks( "grunt-compare-size" );
84-
grunt.loadNpmTasks( "grunt-junit" );
85133
grunt.loadNpmTasks( "grunt-git-authors" );
86134
// local testswarm and build tasks
87135
grunt.loadTasks( "build/tasks" );
88136

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-
99137
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
102138
return file.replace( /.+\/(.+?)>?$/, "$1" );
103139
}
104-
// allow access from banner template
105-
global.stripDirectory = stripDirectory;
106140

107141
function createBanner( files ) {
108142
// strip folders
109143
var fileNames = files && files.map( stripDirectory );
110144
return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
111145
"<%= 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" : "")+
114148
"* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
115-
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */";
149+
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n";
116150
}
117151

118152
grunt.initConfig({
119-
pkg: "<json:package.json>",
153+
pkg: grunt.file.readJSON("package.json"),
120154
files: {
121155
dist: "<%= pkg.name %>-<%= pkg.version %>",
122156
cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
123157
themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
124158
},
125-
meta: {
126-
banner: createBanner(),
127-
bannerAll: createBanner( uiFiles ),
128-
bannerI18n: createBanner( allI18nFiles ),
129-
bannerCSS: createBanner( cssFiles )
130-
},
131159
compare_size: compareFiles,
132160
concat: {
133161
ui: {
134-
src: [ "<banner:meta.bannerAll>", stripBanner( uiFiles ) ],
162+
options: {
163+
banner: createBanner( uiFiles ),
164+
stripBanners: {
165+
block: true
166+
}
167+
},
168+
src: uiFiles,
135169
dest: "dist/jquery-ui.js"
136170
},
137171
i18n: {
138-
src: [ "<banner:meta.bannerI18n>", allI18nFiles ],
172+
options: {
173+
banner: createBanner( allI18nFiles )
174+
},
175+
src: allI18nFiles,
139176
dest: "dist/i18n/jquery-ui-i18n.js"
140177
},
141178
css: {
142-
src: [ "<banner:meta.bannerCSS>", stripBanner( cssFiles ) ],
179+
options: {
180+
banner: createBanner( cssFiles ),
181+
stripBanners: {
182+
block: true
183+
}
184+
},
185+
src: cssFiles,
143186
dest: "dist/jquery-ui.css"
144187
}
145188
},
146-
min: minify,
189+
uglify: minify,
147190
cssmin: minifyCSS,
148191
htmllint: {
149192
// ignore files that contain invalid html, used only for ajax content testing
@@ -158,7 +201,7 @@ grunt.initConfig({
158201
"jquery-*.js",
159202
"MIT-LICENSE.txt",
160203
"README.md",
161-
"grunt.js",
204+
"Gruntfile.js",
162205
"package.json",
163206
"*.jquery.json",
164207
"ui/**/*",
@@ -278,22 +321,43 @@ grunt.initConfig({
278321
}
279322
},
280323
qunit: {
281-
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
324+
files: expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
282325
// disabling everything that doesn't (quite) work with PhantomJS for now
283326
// TODO except for all|index|test, try to include more as we go
284327
return !( /(all|index|test|dialog|dialog_deprecated|tabs|tooltip)\.html$/ ).test( file );
285328
})
286329
},
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+
}
291355
},
292356
csslint: {
293357
// nothing: []
294358
// TODO figure out what to check for, then fix and enable
295359
base_theme: {
296-
src: grunt.file.expandFiles( "themes/base/*.css" ).filter(function( file ) {
360+
src: expandFiles( "themes/base/*.css" ).filter(function( file ) {
297361
// TODO remove items from this list once rewritten
298362
return !( /(button|datepicker|core|dialog|theme)\.css$/ ).test( file );
299363
}),
@@ -307,39 +371,15 @@ grunt.initConfig({
307371
"compatible-vendor-prefixes": false
308372
}
309373
}
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+
}
335375
});
336376

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( " " ) );
344384

345385
};

build/release/release.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ function cloneRepo() {
7272
if ( exec( "npm install download.jqueryui.com" ).code !== 0 ) {
7373
abort( "Error installing dependencies." );
7474
}
75+
if ( exec( "cd node_modules/download.jqueryui.com && grunt prepare" ).code !== 0 ) {
76+
abort( "Error installing dependencies." );
77+
}
7578
}
7679
echo();
7780
}

0 commit comments

Comments
 (0)