mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Grunt: update generate_themes task to use the new DownloadBuilder API
- DownloadBuilder accepts the config file as an option. It's not necessary to workaround it by changing the DownloadBuilder config file anymore; - DownloadBuilder has exposed a method to generate the theme gallery bundle;
This commit is contained in:
parent
0be269d32c
commit
822520ece7
@ -175,67 +175,42 @@ grunt.registerMultiTask( "md5", "Create list of md5 hashes for CDN uploads", fun
|
|||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask( "generate_themes", function() {
|
grunt.registerTask( "generate_themes", function() {
|
||||||
var download, files, done, configContent,
|
var download, done,
|
||||||
target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/",
|
|
||||||
distFolder = "dist/" + grunt.template.process( grunt.config( "files.dist" ), grunt.config() ),
|
distFolder = "dist/" + grunt.template.process( grunt.config( "files.dist" ), grunt.config() ),
|
||||||
configFile = "node_modules/download.jqueryui.com/config.json";
|
target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
require.resolve( "download.jqueryui.com" );
|
require.resolve( "download.jqueryui.com" );
|
||||||
} catch( error ) {
|
} catch( error ) {
|
||||||
throw new Error( "You need to manually install download.jqueryui.com for this task to work" );
|
throw new Error( "You need to manually install download.jqueryui.com for this task to work" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy release files into download builder to avoid cloning again
|
download = require( "download.jqueryui.com" )({
|
||||||
grunt.file.expandFiles( distFolder + "/**" ).forEach(function( file ) {
|
config: {
|
||||||
grunt.file.copy( file, "node_modules/download.jqueryui.com/release/" + file.replace(/^dist\/jquery-ui-/, "") );
|
"jqueryUi": {
|
||||||
});
|
"stable": { "path": path.resolve( __dirname + "/../../" + distFolder ) }
|
||||||
// make it look for the right version
|
},
|
||||||
configContent = grunt.file.readJSON( configFile );
|
"jquery": "skip"
|
||||||
configContent.jqueryUi.stable.version = grunt.config( "pkg.version" );
|
}
|
||||||
grunt.file.write( configFile, JSON.stringify( configContent, null, "\t" ) + "\n" );
|
|
||||||
|
|
||||||
download = new ( require( "download.jqueryui.com" ) )();
|
|
||||||
|
|
||||||
files = grunt.file.expandFiles( distFolder + "/themes/base/**/*" );
|
|
||||||
files.forEach(function( fileName ) {
|
|
||||||
grunt.file.copy( fileName, target + fileName.replace( distFolder, "" ) );
|
|
||||||
});
|
});
|
||||||
|
|
||||||
done = this.async();
|
done = this.async();
|
||||||
grunt.utils.async.forEach( download.themeroller.gallery(), function( theme, done ) {
|
download.buildThemesBundle(function( err, files ) {
|
||||||
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 ) {
|
if ( err ) {
|
||||||
grunt.log.error( err );
|
grunt.log.error( err );
|
||||||
|
return done( false );
|
||||||
}
|
}
|
||||||
done( !err );
|
done(
|
||||||
|
files.every(function( file ) {
|
||||||
|
try {
|
||||||
|
grunt.file.write( target + file.path, file.data );
|
||||||
|
} catch( err ) {
|
||||||
|
grunt.log.error( err );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}) && grunt.log.writeln( "Generated at " + target )
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user