From 469fc1590c8acedd461466eb0e1d3afeadcc254b Mon Sep 17 00:00:00 2001 From: Rafael Xavier de Souza Date: Thu, 30 May 2013 08:51:27 -0300 Subject: [PATCH 1/3] Unmap i18n files from componentFiles attribute. Use i18nFiles instead --- lib/jquery-ui.files.1.10.0.js | 2 +- lib/jquery-ui.files.1.9.0.js | 2 +- lib/packer.js | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/jquery-ui.files.1.10.0.js b/lib/jquery-ui.files.1.10.0.js index 5b9a67d4..8ea76247 100644 --- a/lib/jquery-ui.files.1.10.0.js +++ b/lib/jquery-ui.files.1.10.0.js @@ -25,7 +25,7 @@ commonFiles = [ ]; componentFiles = [ "*jquery.json", - "ui/**", + "ui/*.js", "themes/base/jquery*" ]; testFiles = [ diff --git a/lib/jquery-ui.files.1.9.0.js b/lib/jquery-ui.files.1.9.0.js index 150a3f0e..5e3f2ce8 100644 --- a/lib/jquery-ui.files.1.9.0.js +++ b/lib/jquery-ui.files.1.9.0.js @@ -25,7 +25,7 @@ commonFiles = [ ]; componentFiles = [ "*jquery.json", - "ui/**", + "ui/*.js", "themes/base/jquery*" ]; testFiles = [ diff --git a/lib/packer.js b/lib/packer.js index 1c9744b7..7235c18d 100644 --- a/lib/packer.js +++ b/lib/packer.js @@ -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 ); @@ -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 ); From 8243d4a5d0051fbb74af3054700878c914941e42 Mon Sep 17 00:00:00 2001 From: Rafael Xavier de Souza Date: Thu, 30 May 2013 09:18:32 -0300 Subject: [PATCH 2/3] Remove jqueryui.path from config --- lib/jquery-ui.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jquery-ui.js b/lib/jquery-ui.js index 50079e21..7c7fd3c3 100644 --- a/lib/jquery-ui.js +++ b/lib/jquery-ui.js @@ -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." ); } From 0f510a9660897fe11600b64b1dd60344ede6da4b Mon Sep 17 00:00:00 2001 From: Rafael Xavier de Souza Date: Thu, 30 May 2013 10:01:38 -0300 Subject: [PATCH 3/3] Make DownloadBuilder a low level tool by exporting its main classes --- README.md | 2 +- frontend.js | 15 +++++++ lib/config.js | 3 -- main.js | 117 +++++++++++++------------------------------------- 4 files changed, 47 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index c0358990..0e0dc21d 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/frontend.js b/frontend.js index 3b13e8f8..0c8fc005 100644 --- a/frontend.js +++ b/frontend.js @@ -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 ); }; diff --git a/lib/config.js b/lib/config.js index 419f675b..2d340cff 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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" ); } diff --git a/main.js b/main.js index f616cc7c..fe993d70 100644 --- a/main.js +++ b/main.js @@ -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:, 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 ); } }; -