Skip to content

Commit 9bac5bb

Browse files
committed
Grunt: New task for downloading themes using new themeroller.
* Replaces the old theme tasks with generate_themes. * Drops useless download_docs task * Drops request module
1 parent a638acb commit 9bac5bb

File tree

3 files changed

+52
-86
lines changed

3 files changed

+52
-86
lines changed

build/tasks/build.js

Lines changed: 50 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -171,97 +171,68 @@ grunt.registerMultiTask( "md5", "Create list of md5 hashes for CDN uploads", fun
171171
grunt.log.writeln( "Wrote " + this.file.dest + " with " + hashes.length + " hashes" );
172172
});
173173

174-
// only needed for 1.8
175-
grunt.registerTask( "download_docs", function() {
176-
function capitalize(value) {
177-
return value[0].toUpperCase() + value.slice(1);
174+
grunt.registerTask( "generate_themes", function() {
175+
var download, files, done,
176+
target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/",
177+
distFolder = "dist/" + grunt.template.process( grunt.config( "files.dist" ), grunt.config() );
178+
try {
179+
require.resolve( "download.jqueryui.com" );
180+
} catch( e ) {
181+
throw "You need to manually install download.jqueryui.com for this task to work";
178182
}
179-
// should be grunt.config("pkg.version")?
180-
var version = "1.8",
181-
docsDir = "dist/docs",
182-
files = "draggable droppable resizable selectable sortable accordion autocomplete button datepicker dialog progressbar slider tabs position"
183-
.split(" ").map(function(widget) {
184-
return {
185-
url: "http://docs.jquery.com/action/render/UI/API/" + version + "/" + capitalize(widget),
186-
dest: docsDir + '/' + widget + '.html'
187-
};
188-
});
189-
files = files.concat("animate addClass effect hide removeClass show switchClass toggle toggleClass".split(" ").map(function(widget) {
190-
return {
191-
url: "http://docs.jquery.com/action/render/UI/Effects/" + widget,
192-
dest: docsDir + '/' + widget + '.html'
193-
};
194-
}));
195-
files = files.concat("Blind Clip Drop Explode Fade Fold Puff Slide Scale Bounce Highlight Pulsate Shake Size Transfer".split(" ").map(function(widget) {
196-
return {
197-
url: "http://docs.jquery.com/action/render/UI/Effects/" + widget,
198-
dest: docsDir + '/effect-' + widget.toLowerCase() + '.html'
199-
};
200-
}));
201-
grunt.file.mkdir( "dist/docs" );
202-
grunt.utils.async.forEach( files, function( file, done ) {
203-
var out = fs.createWriteStream( file.dest );
204-
out.on( "close", done );
205-
request( file.url ).pipe( out );
206-
}, this.async() );
207-
});
208183

209-
grunt.registerTask( "download_themes", function() {
210-
// var AdmZip = require('adm-zip');
211-
var done = this.async(),
212-
themes = grunt.file.read( "build/themes" ).split(","),
213-
requests = 0;
214-
grunt.file.mkdir( "dist/tmp" );
215-
themes.forEach(function( theme, index ) {
216-
requests += 1;
217-
grunt.file.mkdir( "dist/tmp/" + index );
218-
var zipFileName = "dist/tmp/" + index + ".zip",
219-
out = fs.createWriteStream( zipFileName );
220-
out.on( "close", function() {
221-
grunt.log.writeln( "done downloading " + zipFileName );
222-
// TODO AdmZip produces "crc32 checksum failed", need to figure out why
223-
// var zip = new AdmZip(zipFileName);
224-
// zip.extractAllTo('dist/tmp/' + index + '/');
225-
// until then, using cli unzip...
226-
grunt.utils.spawn({
227-
cmd: "unzip",
228-
args: [ "-d", "dist/tmp/" + index, zipFileName ]
229-
}, function( err, result ) {
230-
grunt.log.writeln( "Unzipped " + zipFileName + ", deleting it now" );
231-
fs.unlinkSync( zipFileName );
232-
requests -= 1;
233-
if (requests === 0) {
234-
done();
235-
}
236-
});
237-
});
238-
request( "http://ui-dev.jquery.com/download/?" + theme ).pipe( out );
184+
// copy release files into download builder to avoid cloning again
185+
grunt.file.expandFiles( distFolder + "/**" ).forEach(function( file ) {
186+
grunt.file.copy( file, "node_modules/download.jqueryui.com/release/" + file.replace(/^dist/, "") );
239187
});
240-
});
241188

242-
grunt.registerTask( "copy_themes", function() {
243-
// each package includes the base theme, ignore that
244-
var filter = /themes\/base/,
245-
files = grunt.file.expandFiles( "dist/tmp/*/development-bundle/themes/**/*" ).filter(function( file ) {
246-
return !filter.test( file );
247-
}),
248-
// TODO the grunt.template.process call shouldn't be necessary
249-
target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/",
250-
distFolder = "dist/" + grunt.template.process( grunt.config( "files.dist" ), grunt.config() );
251-
files.forEach(function( fileName ) {
252-
var targetFile = fileName.replace( /dist\/tmp\/\d+\/development-bundle\//, "" ).replace( "jquery-ui-.custom", "jquery-ui" );
253-
grunt.file.copy( fileName, target + targetFile );
254-
});
189+
download = new ( require( "download.jqueryui.com" ) )();
255190

256-
// copy minified base theme from regular release
257191
files = grunt.file.expandFiles( distFolder + "/themes/base/**/*" );
258192
files.forEach(function( fileName ) {
259193
grunt.file.copy( fileName, target + fileName.replace( distFolder, "" ) );
260194
});
195+
196+
done = this.async();
197+
grunt.utils.async.forEach( download.themeroller.gallery(), function( theme, done ) {
198+
var folderName = theme.folderName(),
199+
concatTarget = "css-" + folderName,
200+
cssContent = theme.css(),
201+
cssFolderName = target + "themes/" + folderName + "/",
202+
cssFileName = cssFolderName + "jquery.ui.theme.css",
203+
cssFiles = grunt.config.get( "concat.css.src" )[ 1 ].slice();
204+
205+
grunt.file.write( cssFileName, cssContent );
206+
207+
// get css components, replace the last file with the current theme
208+
cssFiles.splice(-1);
209+
cssFiles.push( "<strip_all_banners:" + cssFileName + ">" );
210+
grunt.config.get( "concat" )[ concatTarget ] = {
211+
src: [ "<banner:meta.bannerCSS>", cssFiles ],
212+
dest: cssFolderName + "jquery-ui.css"
213+
};
214+
grunt.task.run( "concat:" + concatTarget );
215+
216+
theme.fetchImages(function( err, files ) {
217+
if ( err ) {
218+
done( err );
219+
return;
220+
}
221+
files.forEach(function( file ) {
222+
grunt.file.write( cssFolderName + "images/" + file.path, file.data );
223+
});
224+
done();
225+
});
226+
}, function( err ) {
227+
if ( err ) {
228+
grunt.log.error( err );
229+
}
230+
done( !err );
231+
});
261232
});
262233

263234
grunt.registerTask( "clean", function() {
264235
require( "rimraf" ).sync( "dist" );
265236
});
266237

267-
};
238+
};

grunt.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
/*jshint node: true */
22
module.exports = function( grunt ) {
33

4-
var // modules
5-
fs = require( "fs" ),
6-
path = require( "path" ),
7-
request = require( "request" ),
8-
4+
var
95
// files
106
coreFiles = [
117
"jquery.ui.core.js",
@@ -345,7 +341,7 @@ grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size:a
345341
grunt.registerTask( "sizer_all", "concat:ui min compare_size" );
346342
grunt.registerTask( "build", "concat min cssmin copy:dist_units_images" );
347343
grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" );
348-
grunt.registerTask( "release_themes", "release download_themes copy_themes copy:themes md5:themes zip:themes" );
344+
grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes" );
349345
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" );
350346

351347
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"grunt-html": "0.1.1",
5555
"grunt-junit": "0.1.4",
5656
"grunt-git-authors": "1.0.0",
57-
"request": "2.9.153",
5857
"rimraf": "2.0.1",
5958
"testswarm": "0.2.3"
6059
},

0 commit comments

Comments
 (0)