Skip to content

Export DownloadBuilder, so jQueryUI Release Script can use it #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ $ npm link download.jqueryui.com

Temporarily change its `grunt.js` to use localhost instead of http://download.jqueryui.com.
```diff
var downloadBuilder = require( "download.jqueryui.com" )({
var frontend = require( "download.jqueryui.com" ).frontend({
- host: "http://download.jqueryui.com"
+ host: "http://localhost:8088",
env: "production"
Expand Down
15 changes: 15 additions & 0 deletions frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@ var _ = require( "underscore" ),
var errorTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/500.html", "utf-8" ) ),
rootTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/root.html", "utf-8" ) );

/**
* Frontend( options )
* - options [ Object ]: key-value pairs detailed below.
*
* options
* - config [ Object ]: optional, if present used instead of the `config.json` file;
* - env [ String ]: optional, specify whether in development or production environment. Default: "development".
* - host [ String ]: optional, specify the host where download.jqueryui.com server is running. Default: "" (empty string).
*
*/
var Frontend = function( options ) {
options = _.extend( {}, Frontend.defaults, options );
if ( options.config && typeof options.config === "object" ) {
require( "./lib/config" ).get = function() {
return options.config;
};
}
this.download = new Download( options );
this.themeroller = new ThemeRoller( options );
};
Expand Down
3 changes: 0 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ Config = module.exports = function() {
jqueryUi.push( config.jqueryUi.legacy );
}
config.jqueryUi = jqueryUi.map(function( entry ) {
if ( entry.path && !entry.version ) {
entry.version = "skip";
}
if ( typeof entry !== "object" || !entry.version ) {
throw new Error( "Invalid jqueryUi entry " + JSON.stringify( entry ) + " in config.json" );
}
Expand Down
2 changes: 1 addition & 1 deletion lib/jquery-ui.files.1.10.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ commonFiles = [
];
componentFiles = [
"*jquery.json",
"ui/**",
"ui/*.js",
"themes/base/jquery*"
];
testFiles = [
Expand Down
2 changes: 1 addition & 1 deletion lib/jquery-ui.files.1.9.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ commonFiles = [
];
componentFiles = [
"*jquery.json",
"ui/**",
"ui/*.js",
"themes/base/jquery*"
];
testFiles = [
Expand Down
3 changes: 1 addition & 2 deletions lib/jquery-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ function JqueryUi( path, options ) {
JqueryUi.all = function() {
if ( !JqueryUi._all ) {
JqueryUi._all = config().jqueryUi.map(function( jqueryUi ) {
// 1: Allow config to override path, used by jQuery UI release process to generate themes.
var path = ( jqueryUi.path /* 1 */ || __dirname + "/../jquery-ui/" + jqueryUi.ref ) + "/";
var path = __dirname + "/../jquery-ui/" + jqueryUi.ref + "/";
if ( !fs.existsSync( path ) ) {
throw new Error( "Missing ./" + require( "path" ).relative( __dirname, path ) + " folder. Run `grunt prepare` first, or fix your config file." );
}
Expand Down
8 changes: 6 additions & 2 deletions lib/packer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Packer.prototype = {
output = [],
theme = this.theme;

// Common and component files (includes baseThemeFiles, i18nFiles, and i18nMinFiles)
// Common and component files (includes baseThemeFiles)
build.commonFiles.into( "development-bundle/" ).forEach( add );
build.componentFiles.into( "development-bundle/" ).forEach( add );

Expand All @@ -113,7 +113,11 @@ Packer.prototype = {
.rename( /^themes\/base\/images/, "themes/base/minified/images" )
.into( "development-bundle/" ).forEach( add );

// I18n (i18nFiles and i18nMinFiles have been included by build.componentFiles)
// I18n
build.i18nFiles.into( "development-bundle/" ).forEach( add );
build.i18nMinFiles
.rename( /^ui\/i18n/, "ui/minified/i18n" )
.into( "development-bundle/" ).forEach( add );
build.bundleI18n.into( "development-bundle/ui/i18n/" ).forEach( add );
build.bundleI18nMin.into( "development-bundle/ui/minified/i18n/" ).forEach( add );

Expand Down
117 changes: 31 additions & 86 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,41 @@
var Main,
_ = require( "underscore" ),
Config = require( "./lib/config" );
module.exports = {
/**
* The Builder class.
*/
Builder: require( "./lib/builder" ),

/**
* Main( options ) -- or require( "download.jqueryui.com" )( options )
* - options [ Object ]: key-value pairs detailed below.
*
* options
* - config [ Object ]: optional, if present used instead of the `config.json` file;
* - env [ String ]: optional, specify whether in development or production environment. Default: "development".
* - host [ String ]: optional, specify the host where download.jqueryui.com server is running. Default: "" (empty string).
*
* attributes
* - frontend [ Object ]: for more details see `frontend.js`.
*
*/
module.exports = function( options ) {
return new Main( options );
};
/**
* The JqueryUi class.
*/
JqueryUi: require( "./lib/jquery-ui" ),

Main = function( options ) {
options = _.extend( {}, Main.defaults, options );
if ( options.config && typeof options.config === "object" ) {
Config.get = function() {
return options.config;
};
}
this.frontend = new ( require( "./frontend" ) )( options );
};
/**
* The JqueryUi class.
*/
Packer: require( "./lib/packer" ),

Main.defaults = {
// Empty, check frontend.js's.
};
/**
* The Util object.
*/
util: require( "./lib/util" ),

Main.prototype = {
/**
* frontend( options )
* - options [ Object ]: see `frontend.js` for more details.
*
* Returns a frontend instance.
*/
frontend: function( options ) {
return new ( require( "./frontend" ) )( options );
},

/**
* Main#buildThemesBundle( callback )
* - callback( err, bundleFiles ): bundleFiles is an Array of { path:<path>, data:<data> }'s.
* themeGallery( jqueryUi )
* - jqueryUi [ instanceof JqueryUi ]: see `frontend.js` for more details.
*
* Generates the theme bundle with base and all themes from themegallery.
* Returns themeGallery using jqueryUi's version.
*/
buildThemesBundle: function( callback ) {
var allComponents, jqueryUi, success,
async = require( "async" ),
Builder = require( "./lib/builder" ),
Packer = require( "./lib/packer" ),
bundleFiles = [],
JqueryUi = require( "./lib/jquery-ui" ),
themeGallery = require( "./lib/themeroller.themegallery" )();

jqueryUi = JqueryUi.getStable();
allComponents = jqueryUi.components().map(function( component ) {
return component.name;
});

async.mapSeries( themeGallery, function( theme, callback ) {
var build = new Builder( jqueryUi, allComponents ),
packer = new Packer( build, theme, { skipDocs: true } ),
folderName = theme.folderName();
packer.pack(function( err, files ) {
if ( err ) {
return callback( err );
}
// Add theme files.
files
// Pick only theme files we need on the bundle.
.filter(function( file ) {
var themeCssOnlyRe = new RegExp( "development-bundle/themes/" + folderName + "/jquery.ui.theme.css" ),
themeDirRe = new RegExp( "css/" + folderName );
if ( themeCssOnlyRe.test( file.path ) || themeDirRe.test( file.path ) ) {
return true;
}
return false;
})
// Convert paths the way bundle needs and add it into bundleFiles.
.forEach(function( file ) {
// 1: Remove initial package name eg. "jquery-ui-1.10.0.custom".
// 2: Make jquery-ui-1.10.0.custom.css into jquery-ui.css, or jquery-ui-1.10.0.custom.min.css into jquery-ui.min.css
file.path = file.path
.split( "/" ).slice( 1 ).join( "/" ) /* 1 */
.replace( /development-bundle\/themes/, "css" )
.replace( /css/, "themes" )
.replace( /jquery-ui-.*?(\.min)*\.css/, "jquery-ui$1.css" ); /* 2 */
bundleFiles.push( file );
});

callback( null, files );
});
}, function( err ) {
callback( err, bundleFiles );
});
themeGallery: function( jqueryUi ) {
return require( "./lib/themeroller.themegallery" )( jqueryUi );
}
};