Skip to content

Commit 822520e

Browse files
committed
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;
1 parent 0be269d commit 822520e

File tree

1 file changed

+23
-48
lines changed

1 file changed

+23
-48
lines changed

build/tasks/build.js

+23-48
Original file line numberDiff line numberDiff line change
@@ -175,67 +175,42 @@ grunt.registerMultiTask( "md5", "Create list of md5 hashes for CDN uploads", fun
175175
});
176176

177177
grunt.registerTask( "generate_themes", function() {
178-
var download, files, done, configContent,
179-
target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/",
178+
var download, done,
180179
distFolder = "dist/" + grunt.template.process( grunt.config( "files.dist" ), grunt.config() ),
181-
configFile = "node_modules/download.jqueryui.com/config.json";
180+
target = "dist/" + grunt.template.process( grunt.config( "files.themes" ), grunt.config() ) + "/";
181+
182182
try {
183183
require.resolve( "download.jqueryui.com" );
184184
} catch( error ) {
185185
throw new Error( "You need to manually install download.jqueryui.com for this task to work" );
186186
}
187187

188-
// copy release files into download builder to avoid cloning again
189-
grunt.file.expandFiles( distFolder + "/**" ).forEach(function( file ) {
190-
grunt.file.copy( file, "node_modules/download.jqueryui.com/release/" + file.replace(/^dist\/jquery-ui-/, "") );
191-
});
192-
// make it look for the right version
193-
configContent = grunt.file.readJSON( configFile );
194-
configContent.jqueryUi.stable.version = grunt.config( "pkg.version" );
195-
grunt.file.write( configFile, JSON.stringify( configContent, null, "\t" ) + "\n" );
196-
197-
download = new ( require( "download.jqueryui.com" ) )();
198-
199-
files = grunt.file.expandFiles( distFolder + "/themes/base/**/*" );
200-
files.forEach(function( fileName ) {
201-
grunt.file.copy( fileName, target + fileName.replace( distFolder, "" ) );
188+
download = require( "download.jqueryui.com" )({
189+
config: {
190+
"jqueryUi": {
191+
"stable": { "path": path.resolve( __dirname + "/../../" + distFolder ) }
192+
},
193+
"jquery": "skip"
194+
}
202195
});
203196

204197
done = this.async();
205-
grunt.utils.async.forEach( download.themeroller.gallery(), function( theme, done ) {
206-
var folderName = theme.folderName(),
207-
concatTarget = "css-" + folderName,
208-
cssContent = theme.css(),
209-
cssFolderName = target + "themes/" + folderName + "/",
210-
cssFileName = cssFolderName + "jquery.ui.theme.css",
211-
cssFiles = grunt.config.get( "concat.css.src" )[ 1 ].slice();
212-
213-
grunt.file.write( cssFileName, cssContent );
214-
215-
// get css components, replace the last file with the current theme
216-
cssFiles.splice(-1);
217-
cssFiles.push( "<strip_all_banners:" + cssFileName + ">" );
218-
grunt.config.get( "concat" )[ concatTarget ] = {
219-
src: [ "<banner:meta.bannerCSS>", cssFiles ],
220-
dest: cssFolderName + "jquery-ui.css"
221-
};
222-
grunt.task.run( "concat:" + concatTarget );
223-
224-
theme.fetchImages(function( err, files ) {
225-
if ( err ) {
226-
done( err );
227-
return;
228-
}
229-
files.forEach(function( file ) {
230-
grunt.file.write( cssFolderName + "images/" + file.path, file.data );
231-
});
232-
done();
233-
});
234-
}, function( err ) {
198+
download.buildThemesBundle(function( err, files ) {
235199
if ( err ) {
236200
grunt.log.error( err );
201+
return done( false );
237202
}
238-
done( !err );
203+
done(
204+
files.every(function( file ) {
205+
try {
206+
grunt.file.write( target + file.path, file.data );
207+
} catch( err ) {
208+
grunt.log.error( err );
209+
return false;
210+
}
211+
return true;
212+
}) && grunt.log.writeln( "Generated at " + target )
213+
);
239214
});
240215
});
241216

0 commit comments

Comments
 (0)