Skip to content

Commit 7821c3f

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 e21fc29 commit 7821c3f

File tree

4 files changed

+131
-106
lines changed

4 files changed

+131
-106
lines changed

grunt.js renamed to Gruntfile.js

+106-72
Original file line numberDiff line numberDiff line change
@@ -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
]
@@ -66,84 +92,95 @@ function mapMinFile( file ) {
6692
}
6793

6894
uiFiles.concat( allI18nFiles ).forEach(function( file ) {
69-
minify[ mapMinFile( file ) ] = [ "<banner>", file ];
95+
minify[ file ] = {
96+
options: {
97+
banner: createBanner()
98+
},
99+
files: {}
100+
};
101+
minify[ file ].files[ mapMinFile( file ) ] = file;
70102
});
71103

72104
cssFiles.forEach(function( file ) {
73-
minifyCSS[ "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" ) ] = [ "<banner>", "<strip_all_banners:" + file + ">" ];
105+
minifyCSS[ file ] = {
106+
options: {
107+
banner: createBanner()
108+
},
109+
src: file,
110+
dest: "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" )
111+
};
74112
});
75113

76114
uiFiles.forEach(function( file ) {
115+
// TODO this doesn't do anything until https://github.com/rwldrn/grunt-compare-size/issues/13
77116
compareFiles[ file ] = [ file, mapMinFile( file ) ];
78117
});
79118

80119
// grunt plugins
120+
grunt.loadNpmTasks( "grunt-contrib-jshint" );
121+
grunt.loadNpmTasks( "grunt-contrib-uglify" );
122+
grunt.loadNpmTasks( "grunt-contrib-concat" );
123+
grunt.loadNpmTasks( "grunt-contrib-qunit" );
81124
grunt.loadNpmTasks( "grunt-css" );
82125
grunt.loadNpmTasks( "grunt-html" );
83126
grunt.loadNpmTasks( "grunt-compare-size" );
84-
grunt.loadNpmTasks( "grunt-junit" );
85127
grunt.loadNpmTasks( "grunt-git-authors" );
86128
// local testswarm and build tasks
87129
grunt.loadTasks( "build/tasks" );
88130

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

107135
function createBanner( files ) {
108136
// strip folders
109137
var fileNames = files && files.map( stripDirectory );
110138
return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
111139
"<%= grunt.template.today('isoDate') %>\n" +
112-
"<%= pkg.homepage ? '* ' + pkg.homepage + '\n' : '' %>" +
113-
"* Includes: " + (files ? fileNames.join(", ") : "<%= stripDirectory(grunt.task.current.file.src[1]) %>") + "\n" +
140+
"<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" +
141+
(files ? "* Includes: " + fileNames.join(", ") + "\n" : "")+
114142
"* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
115-
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */";
143+
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n";
116144
}
117145

118146
grunt.initConfig({
119-
pkg: "<json:package.json>",
147+
pkg: grunt.file.readJSON("package.json"),
120148
files: {
121149
dist: "<%= pkg.name %>-<%= pkg.version %>",
122150
cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
123151
themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
124152
},
125-
meta: {
126-
banner: createBanner(),
127-
bannerAll: createBanner( uiFiles ),
128-
bannerI18n: createBanner( allI18nFiles ),
129-
bannerCSS: createBanner( cssFiles )
130-
},
131153
compare_size: compareFiles,
132154
concat: {
133155
ui: {
134-
src: [ "<banner:meta.bannerAll>", stripBanner( uiFiles ) ],
156+
options: {
157+
banner: createBanner( uiFiles ),
158+
stripBanners: {
159+
block: true
160+
}
161+
},
162+
src: uiFiles,
135163
dest: "dist/jquery-ui.js"
136164
},
137165
i18n: {
138-
src: [ "<banner:meta.bannerI18n>", allI18nFiles ],
166+
options: {
167+
banner: createBanner( allI18nFiles )
168+
},
169+
src: allI18nFiles,
139170
dest: "dist/i18n/jquery-ui-i18n.js"
140171
},
141172
css: {
142-
src: [ "<banner:meta.bannerCSS>", stripBanner( cssFiles ) ],
173+
options: {
174+
banner: createBanner( cssFiles ),
175+
stripBanners: {
176+
block: true
177+
}
178+
},
179+
src: cssFiles,
143180
dest: "dist/jquery-ui.css"
144181
}
145182
},
146-
min: minify,
183+
uglify: minify,
147184
cssmin: minifyCSS,
148185
htmllint: {
149186
// ignore files that contain invalid html, used only for ajax content testing
@@ -158,7 +195,7 @@ grunt.initConfig({
158195
"jquery-*.js",
159196
"MIT-LICENSE.txt",
160197
"README.md",
161-
"grunt.js",
198+
"Gruntfile.js",
162199
"package.json",
163200
"*.jquery.json",
164201
"ui/**/*",
@@ -284,10 +321,31 @@ grunt.initConfig({
284321
return !( /(all|index|test|dialog|dialog_deprecated|tabs|tooltip)\.html$/ ).test( file );
285322
})
286323
},
287-
lint: {
288-
ui: "ui/*.js",
289-
grunt: [ "grunt.js", "build/**/*.js" ],
290-
tests: "tests/unit/**/*.js"
324+
jshint: {
325+
ui: {
326+
options: {
327+
jshintrc: "ui/.jshintrc"
328+
},
329+
files: {
330+
src: "ui/*.js"
331+
}
332+
},
333+
grunt: {
334+
options: {
335+
jshintrc: ".jshintrc"
336+
},
337+
files: {
338+
src: [ "Gruntfile.js", "build/**/*.js" ]
339+
}
340+
},
341+
tests: {
342+
options: {
343+
jshintrc: "tests/.jshintrc"
344+
},
345+
files: {
346+
src: "tests/unit/**/*.js"
347+
}
348+
}
291349
},
292350
csslint: {
293351
// nothing: []
@@ -307,39 +365,15 @@ grunt.initConfig({
307365
"compatible-vendor-prefixes": false
308366
}
309367
}
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-
})()
368+
}
335369
});
336370

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" );
371+
grunt.registerTask( "default", [ "jshint", "csslint", "htmllint", "qunit" ] );
372+
grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ] );
373+
grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ] );
374+
grunt.registerTask( "build", [ "concat", "uglify", "cssmin", "copy:dist_units_images" ] );
375+
grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist".split( " " ) );
376+
grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes".split( " " ) );
377+
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( " " ) );
344378

345379
};

build/release/release.js

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ function cloneRepo() {
7777
if ( exec( "npm install download.jqueryui.com" ).code !== 0 ) {
7878
abort( "Error installing dependencies." );
7979
}
80+
if ( exec( "cd node_modules/download.jqueryui.com && grunt prepare" ).code !== 0 ) {
81+
abort( "Error installing dependencies." );
82+
}
8083
}
8184
echo();
8285
}

build/tasks/build.js

+13-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ module.exports = function( grunt ) {
33
"use strict";
44

55
var path = require( "path" ),
6-
fs = require( "fs" );
6+
fs = require( "fs" ),
7+
// support: node <0.8
8+
existsSync = fs.existsSync || path.existsSync;
79

810
grunt.registerTask( "manifest", "Generate jquery.json manifest files", function() {
911
var pkg = grunt.config( "pkg" ),
@@ -121,28 +123,11 @@ grunt.registerMultiTask( "copy", "Copy files to destination folder and replace @
121123

122124

123125
grunt.registerMultiTask( "zip", "Create a zip file for release", function() {
124-
// TODO switch back to adm-zip for better cross-platform compability once it actually works
125-
// 0.1.3 works, but result can't be unzipped
126-
// its also a lot slower then zip program, probably due to how its used...
127-
// var files = grunt.file.expandFiles( "dist/" + this.file.src + "/**/*" );
128-
// grunt.log.writeln( "Creating zip file " + this.file.dest );
129-
130-
//var AdmZip = require( "adm-zip" );
131-
//var zip = new AdmZip();
132-
//files.forEach(function( file ) {
133-
// grunt.verbose.writeln( "Zipping " + file );
134-
// // rewrite file names from dist folder (created by build), drop the /dist part
135-
// zip.addFile(file.replace(/^dist/, "" ), fs.readFileSync( file ) );
136-
//});
137-
//zip.writeZip( "dist/" + this.file.dest );
138-
//grunt.log.writeln( "Wrote " + files.length + " files to " + this.file.dest );
139-
140126
var done = this.async(),
141-
dest = this.file.dest,
142-
src = grunt.template.process( this.file.src, grunt.config() );
143-
grunt.utils.spawn({
127+
dest = this.data.dest;
128+
grunt.util.spawn({
144129
cmd: "zip",
145-
args: [ "-r", dest, src ],
130+
args: [ "-r", dest, this.data.src ],
146131
opts: {
147132
cwd: 'dist'
148133
}
@@ -159,7 +144,7 @@ grunt.registerMultiTask( "zip", "Create a zip file for release", function() {
159144

160145
grunt.registerMultiTask( "md5", "Create list of md5 hashes for CDN uploads", function() {
161146
// remove dest file before creating it, to make sure itself is not included
162-
if ( path.existsSync( this.file.dest ) ) {
147+
if ( existsSync( this.file.dest ) ) {
163148
fs.unlinkSync( this.file.dest );
164149
}
165150
var crypto = require( "crypto" ),
@@ -197,23 +182,23 @@ grunt.registerTask( "generate_themes", function() {
197182
});
198183

199184
done = this.async();
200-
grunt.utils.async.forEach( download.themeroller.gallery(), function( theme, done ) {
185+
grunt.util.async.forEach( download.themeroller.gallery(), function( theme, done ) {
201186
var folderName = theme.folderName(),
202187
concatTarget = "css-" + folderName,
203188
cssContent = theme.css(),
204189
cssFolderName = target + "themes/" + folderName + "/",
205190
cssFileName = cssFolderName + "jquery.ui.theme.css",
206-
cssFiles = grunt.config.get( "concat.css.src" )[ 1 ].slice();
191+
cssFiles = grunt.config.get( "concat.css.src" ).slice();
207192

208193
grunt.file.write( cssFileName, cssContent );
209194

210195
// get css components, replace the last file with the current theme
211196
cssFiles.splice(-1);
212-
cssFiles.push( "<strip_all_banners:" + cssFileName + ">" );
213-
grunt.config.get( "concat" )[ concatTarget ] = {
214-
src: [ "<banner:meta.bannerCSS>", cssFiles ],
197+
cssFiles.push( cssFileName );
198+
grunt.config.set( "concat." + concatTarget, {
199+
src: cssFiles,
215200
dest: cssFolderName + "jquery-ui.css"
216-
};
201+
});
217202
grunt.task.run( "concat:" + concatTarget );
218203

219204
theme.fetchImages(function( err, files ) {

package.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@
4343
],
4444
"dependencies": {},
4545
"devDependencies": {
46-
"grunt": "~0.3.17",
47-
"grunt-css": "0.2.0",
48-
"grunt-compare-size": "0.1.4",
49-
"grunt-html": "0.1.1",
50-
"grunt-junit": "0.1.5",
51-
"grunt-git-authors": "1.0.0",
46+
"grunt": "0.4.x",
47+
"grunt-contrib-jshint": "0.1.0",
48+
"grunt-contrib-uglify": "0.1.0",
49+
"grunt-contrib-concat": "0.1.1",
50+
"grunt-contrib-qunit": "0.1.0",
51+
"grunt-css": "0.5.1",
52+
"grunt-compare-size": "0.3.1",
53+
"grunt-html": "0.3.0",
54+
"grunt-git-authors": "1.1.0-beta.1",
5255
"rimraf": "2.0.1",
5356
"testswarm": "0.3.0"
5457
},

0 commit comments

Comments
 (0)