]> source.dussan.org Git - jquery-ui.git/commitdiff
Grunt: New task for downloading themes using new themeroller. 730/head
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Thu, 13 Sep 2012 13:50:43 +0000 (15:50 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Mon, 24 Sep 2012 06:54:24 +0000 (08:54 +0200)
* Replaces the old theme tasks with generate_themes.
* Drops useless download_docs task
* Drops request module

build/tasks/build.js
grunt.js
package.json

index bbe63da2ce12595c7595d69d60e17975c26b1694..2f191b69a323cfd9ad3701249cba6d95b31727ea 100644 (file)
@@ -171,97 +171,68 @@ grunt.registerMultiTask( "md5", "Create list of md5 hashes for CDN uploads", fun
        grunt.log.writeln( "Wrote " + this.file.dest + " with " + hashes.length + " hashes" );
 });
 
-// only needed for 1.8
-grunt.registerTask( "download_docs", function() {
-       function capitalize(value) {
-               return value[0].toUpperCase() + value.slice(1);
+grunt.registerTask( "generate_themes", function() {
+       var download, files, done,
+               target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/",
+               distFolder = "dist/" + grunt.template.process( grunt.config( "files.dist" ), grunt.config() );
+       try {
+               require.resolve( "download.jqueryui.com" );
+       } catch( e ) {
+               throw "You need to manually install download.jqueryui.com for this task to work";
        }
-       // should be grunt.config("pkg.version")?
-       var version = "1.8",
-               docsDir = "dist/docs",
-               files = "draggable droppable resizable selectable sortable accordion autocomplete button datepicker dialog progressbar slider tabs position"
-               .split(" ").map(function(widget) {
-                       return {
-                               url: "http://docs.jquery.com/action/render/UI/API/" + version + "/" + capitalize(widget),
-                               dest: docsDir + '/' + widget + '.html'
-                       };
-               });
-       files = files.concat("animate addClass effect hide removeClass show switchClass toggle toggleClass".split(" ").map(function(widget) {
-               return {
-                       url: "http://docs.jquery.com/action/render/UI/Effects/" + widget,
-                       dest: docsDir + '/' + widget + '.html'
-               };
-       }));
-       files = files.concat("Blind Clip Drop Explode Fade Fold Puff Slide Scale Bounce Highlight Pulsate Shake Size Transfer".split(" ").map(function(widget) {
-               return {
-                       url: "http://docs.jquery.com/action/render/UI/Effects/" + widget,
-                       dest: docsDir + '/effect-' + widget.toLowerCase() + '.html'
-               };
-       }));
-       grunt.file.mkdir( "dist/docs" );
-       grunt.utils.async.forEach( files, function( file, done ) {
-               var out = fs.createWriteStream( file.dest );
-               out.on( "close", done );
-               request( file.url ).pipe( out );
-       }, this.async() );
-});
 
-grunt.registerTask( "download_themes", function() {
-       // var AdmZip = require('adm-zip');
-       var done = this.async(),
-               themes = grunt.file.read( "build/themes" ).split(","),
-               requests = 0;
-       grunt.file.mkdir( "dist/tmp" );
-       themes.forEach(function( theme, index ) {
-               requests += 1;
-               grunt.file.mkdir( "dist/tmp/" + index );
-               var zipFileName = "dist/tmp/" + index + ".zip",
-                       out = fs.createWriteStream( zipFileName );
-               out.on( "close", function() {
-                       grunt.log.writeln( "done downloading " + zipFileName );
-                       // TODO AdmZip produces "crc32 checksum failed", need to figure out why
-                       // var zip = new AdmZip(zipFileName);
-                       // zip.extractAllTo('dist/tmp/' + index + '/');
-                       // until then, using cli unzip...
-                       grunt.utils.spawn({
-                               cmd: "unzip",
-                               args: [ "-d", "dist/tmp/" + index, zipFileName ]
-                       }, function( err, result ) {
-                               grunt.log.writeln( "Unzipped " + zipFileName + ", deleting it now" );
-                               fs.unlinkSync( zipFileName );
-                               requests -= 1;
-                               if (requests === 0) {
-                                       done();
-                               }
-                       });
-               });
-               request( "http://ui-dev.jquery.com/download/?" + theme ).pipe( out );
+       // copy release files into download builder to avoid cloning again
+       grunt.file.expandFiles( distFolder + "/**" ).forEach(function( file ) {
+               grunt.file.copy( file, "node_modules/download.jqueryui.com/release/" + file.replace(/^dist/, "") );
        });
-});
 
-grunt.registerTask( "copy_themes", function() {
-       // each package includes the base theme, ignore that
-       var filter = /themes\/base/,
-               files = grunt.file.expandFiles( "dist/tmp/*/development-bundle/themes/**/*" ).filter(function( file ) {
-                       return !filter.test( file );
-               }),
-               // TODO the grunt.template.process call shouldn't be necessary
-               target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/",
-               distFolder = "dist/" + grunt.template.process( grunt.config( "files.dist" ), grunt.config() );
-       files.forEach(function( fileName ) {
-               var targetFile = fileName.replace( /dist\/tmp\/\d+\/development-bundle\//, "" ).replace( "jquery-ui-.custom", "jquery-ui" );
-               grunt.file.copy( fileName, target + targetFile );
-       });
+       download = new ( require( "download.jqueryui.com" ) )();
 
-       // copy minified base theme from regular release
        files = grunt.file.expandFiles( distFolder + "/themes/base/**/*" );
        files.forEach(function( fileName ) {
                grunt.file.copy( fileName, target + fileName.replace( distFolder, "" ) );
        });
+
+       done = this.async();
+       grunt.utils.async.forEach( download.themeroller.gallery(), function( theme, done ) {
+               var folderName = theme.folderName(),
+                       concatTarget = "css-" + folderName,
+                       cssContent = theme.css(),
+                       cssFolderName = target + "themes/" + folderName + "/",
+                       cssFileName = cssFolderName + "jquery.ui.theme.css",
+                       cssFiles = grunt.config.get( "concat.css.src" )[ 1 ].slice();
+
+               grunt.file.write( cssFileName, cssContent );
+
+               // get css components, replace the last file with the current theme
+               cssFiles.splice(-1);
+               cssFiles.push( "<strip_all_banners:" + cssFileName + ">" );
+               grunt.config.get( "concat" )[ concatTarget ] = {
+                       src: [ "<banner:meta.bannerCSS>", cssFiles ],
+                       dest: cssFolderName + "jquery-ui.css"
+               };
+               grunt.task.run( "concat:" + concatTarget );
+
+               theme.fetchImages(function( err, files ) {
+                       if ( err ) {
+                               done( err );
+                               return;
+                       }
+                       files.forEach(function( file ) {
+                               grunt.file.write( cssFolderName + "images/" + file.path, file.data );
+                       });
+                       done();
+               });
+       }, function( err ) {
+               if ( err ) {
+                       grunt.log.error( err );
+               }
+               done( !err );
+       });
 });
 
 grunt.registerTask( "clean", function() {
        require( "rimraf" ).sync( "dist" );
 });
 
-};
\ No newline at end of file
+};
index d244e21cc73fd1f64c420750c40159069a7a3cdc..548393b59941d003c976078bdc3fe9c82f1f0adf 100644 (file)
--- a/grunt.js
+++ b/grunt.js
@@ -1,11 +1,7 @@
 /*jshint node: true */
 module.exports = function( grunt ) {
 
-var // modules
-       fs = require( "fs" ),
-       path = require( "path" ),
-       request = require( "request" ),
-
+var
        // files
        coreFiles = [
                "jquery.ui.core.js",
@@ -345,7 +341,7 @@ grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size:a
 grunt.registerTask( "sizer_all", "concat:ui min compare_size" );
 grunt.registerTask( "build", "concat min cssmin copy:dist_units_images" );
 grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" );
-grunt.registerTask( "release_themes", "release download_themes copy_themes copy:themes md5:themes zip:themes" );
+grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes" );
 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" );
 
 };
index ca71cae2ce1858e7d0f1e9f0bbca516f993b71d1..554dfe0615bebefc5ae4264b4eb5793571033f1d 100644 (file)
@@ -54,7 +54,6 @@
                "grunt-html": "0.1.1",
                "grunt-junit": "0.1.4",
                "grunt-git-authors": "1.0.0",
-               "request": "2.9.153",
                "rimraf": "2.0.1",
                "testswarm": "0.2.3"
        },