Permalink
Browse files

Packer: Support building 1.12.0 package

- Handle CSS dependencies from JS comments (based on jQuery Mobile);
- Use node-packager, builder-amd, builder-jquery-css, and
  jquery-ui-themeroller to build UI 1.12.0 download package;
- Cache support;

Fixes #178
Fixes #255
Ref jquery/jquery-ui#1440
  • Loading branch information...
1 parent b2fc4a7 commit eda7d35b545950e14c5cb9073b9c98df460ee201 @rxaviers rxaviers committed Apr 17, 2014
Showing with 627 additions and 215 deletions.
  1. +1 −1 Gruntfile.js
  2. +69 −33 download.js
  3. +11 −42 lib/jquery-ui-files-1-12.js
  4. +320 −0 lib/package-1-12.js
  5. +0 −133 lib/packer-1-12-0.js
  6. +0 −1 lib/packer.js
  7. +4 −2 lib/util.js
  8. +6 −1 package.json
  9. +14 −0 server.js
  10. +1 −1 test/{jquery-ui.js → jquery-ui-1-11.js}
  11. +200 −0 test/package-1-12.0.js
  12. +1 −1 test/packer-1-11-1.js
View
@@ -394,7 +394,7 @@ function buildPackages( folder, callback ) {
return callback();
}
stream = fs.createWriteStream( filename );
- packer.zipTo( stream, function( error, result ) {
+ packer.zipTo( stream, function( error ) {
if ( error ) {
return callback( error );
}
View
@@ -1,17 +1,21 @@
-var downloadLogger, jqueryUis,
+var cache, downloadLogger, jqueryUis,
_ = require( "underscore" ),
- Builder = require( "./lib/builder" ),
+ Cache = require( "./lib/cache" ),
fs = require( "fs" ),
Handlebars = require( "handlebars" ),
JqueryUi = require( "./lib/jquery-ui" ),
logger = require( "simple-log" ).init( "download.jqueryui.com" ),
- Packer = require( "./lib/packer" ),
+ Packager = require( "node-packager" ),
querystring = require( "querystring" ),
semver = require( "semver" ),
themeGallery = require( "./lib/themeroller-themegallery" )(),
ThemeRoller = require( "./lib/themeroller" ),
+ ToBeDeprecatedBuilder = require( "./lib/builder" ),
+ ToBeDeprecatedPacker = require( "./lib/packer" ),
winston = require( "winston" );
+cache = new Cache( "Built Packages Cache" );
+
downloadLogger = new winston.Logger({
transports: [
new winston.transports.File({
@@ -91,7 +95,7 @@ Frontend.prototype = {
create: function( fields, response, callback ) {
try {
- var builder, components, jqueryUi, packer, start, theme,
+ var builder, components, files, jqueryUi, Package, packer, start, theme,
themeVars = null;
if ( fields.theme !== "none" ) {
themeVars = querystring.parse( fields.theme );
@@ -101,37 +105,69 @@ Frontend.prototype = {
themeVars.folderName = fields[ "theme-folder-name" ] || themeVars.folderName;
themeVars.scope = fields.scope || themeVars.scope;
}
- theme = new ThemeRoller({
- vars: themeVars,
- version: fields.version
- });
components = Object.keys( _.omit( fields, "scope", "theme", "theme-folder-name", "version" ) );
- start = new Date();
jqueryUi = JqueryUi.find( fields.version );
- builder = new Builder( jqueryUi, components, {
- scope: fields.scope
- });
- packer = new Packer( builder, theme, {
- scope: fields.scope
- });
- response.setHeader( "Content-Type", "application/zip" );
- response.setHeader( "Content-Disposition", "attachment; filename=" + packer.filename() );
- packer.zipTo( response, function( err, written, elapsedTime ) {
- if ( err ) {
- return callback( err );
- }
- // Log statistics
- downloadLogger.info(
- JSON.stringify({
- build_size: written,
- build_time: new Date() - start,
- components: builder.components,
- theme_name: theme.name,
- version: jqueryUi.pkg.version
- })
- );
- return callback();
- });
+
+ // The old way to generate a package (to be deprecated when jQuery UI support baseline is UI 1.12).
+ if ( semver.lt( jqueryUi.pkg.version, "1.12.0-a" ) ) {
+ start = new Date();
+ theme = new ThemeRoller({
+ vars: themeVars,
+ version: fields.version
+ });
+ builder = new ToBeDeprecatedBuilder( jqueryUi, components, {
+ scope: fields.scope
+ });
+ packer = new ToBeDeprecatedPacker( builder, theme, {
+ scope: fields.scope
+ });
+ response.setHeader( "Content-Type", "application/zip" );
+ response.setHeader( "Content-Disposition", "attachment; filename=" + packer.filename() );
+ packer.zipTo( response, function( err, written ) {
+ if ( err ) {
+ return callback( err );
+ }
+ // Log statistics
+ downloadLogger.info(
+ JSON.stringify({
+ build_size: written,
+ build_time: new Date() - start,
+ components: components,
+ theme_name: theme && theme.name || "n/a",
+ version: jqueryUi.pkg.version
+ })
+ );
+ return callback();
+ });
+
+ // The new way to generate a package.
+ } else {
+ Package = require( "./lib/package-1-12" );
+ packager = new Packager( jqueryUi.files().cache, Package, {
+ components: components,
+ themeVars: themeVars,
+ scope: fields.scope
+ }, { cache: cache } );
+ response.setHeader( "Content-Type", "application/zip" );
+ response.setHeader( "Content-Disposition", "attachment; filename=" + packager.pkg.zipFilename );
+ packager.toZip( response, {
+ basedir: packager.pkg.zipBasedir
+ }, function( error ) {
+ if ( error ) {
+ return callback( error );
+ }
+ // Log statistics
+ downloadLogger.info(
+ JSON.stringify({
+ build_size: packager.stats.toZip.size,
+ build_time: packager.stats.build.time + packager.stats.toZip.time,
+ components: components,
+ version: jqueryUi.pkg.version
+ })
+ );
+ return callback();
+ });
+ }
} catch( err ) {
return callback( err );
}
@@ -1,61 +1,30 @@
-var commonFiles, componentFiles, flatten, glob, isDirectory, noDirectory, optional, testFiles,
- Docs = require( "./docs" ),
+var glob, noDirectory,
Files = require( "./files" ),
util = require( "./util" );
-flatten = util.flatten;
glob = util.glob;
-isDirectory = util.isDirectory;
noDirectory = util.noDirectory;
-optional = util.optional;
-
-commonFiles = [
- "AUTHORS.txt",
- "Gruntfile.js",
- "MIT-LICENSE.txt",
- "package.json",
- "README.md",
- "external/*",
- "demos/demos.css",
- "demos/images/*",
- "themes/base/all.css",
- "themes/base/base.css",
- "themes/base/theme.css",
- "themes/base/images/*"
-];
-componentFiles = [
- "ui/*.js",
- "themes/base/*"
-];
-testFiles = [
- "tests/**",
- "ui/.jshintrc"
-];
/**
* JqueryUiFiles 1.12.0
*/
function JqueryUiFiles_1_12_0( jqueryUi ) {
- var readFile, stripJqueryUiPath,
- path = require( "path" );
+ var files, readFile, stripJqueryUiPath;
readFile = this.readFile;
stripJqueryUiPath = this.stripJqueryUiPath;
- this.commonFiles = commonFiles.map(function( path ) {
- return glob( jqueryUi.path + path ).filter( noDirectory ).map( stripJqueryUiPath ).map( readFile );
- }).reduce( flatten, Files() );
-
- this.componentFiles = componentFiles.map(function( path ) {
- return glob( jqueryUi.path + path ).filter( noDirectory ).map( stripJqueryUiPath ).map( readFile );
- }).reduce( flatten, Files() );
-
- this.i18nFiles = Files( glob( jqueryUi.path + "ui/i18n/*" ).map( stripJqueryUiPath ).map( readFile ) );
+ glob( jqueryUi.path + "!(node_modules|build)" ).filter( noDirectory ).map( stripJqueryUiPath ).map( readFile );
+ glob( jqueryUi.path + "!(node_modules|build)/**" ).filter( noDirectory ).map( stripJqueryUiPath ).map( readFile );
- this.jqueryCore = Files( glob( jqueryUi.path + "external/jquery/jquery.js" ).map( stripJqueryUiPath ).map( readFile ) );
+ this.componentFiles = Files( glob( jqueryUi.path + "ui/*.js" ).map( stripJqueryUiPath ).map( readFile ) );
- // Auxiliary variables
- this.baseThemeCss = this.get( "themes/base/theme.css" );
+ // Convert {path:<path>, data:<data>} into {path: <data>}.
+ files = this.cache;
+ this.cache = Object.keys( files ).reduce(function( _files, filepath ) {
+ _files[ filepath ] = files[ filepath ].data;
+ return _files;
+ }, {} );
}
module.exports = JqueryUiFiles_1_12_0;
Oops, something went wrong.

0 comments on commit eda7d35

Please sign in to comment.