Skip to content

Commit 0f510a9

Browse files
committed
Make DownloadBuilder a low level tool by exporting its main classes
1 parent 8243d4a commit 0f510a9

File tree

4 files changed

+47
-90
lines changed

4 files changed

+47
-90
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ $ npm link download.jqueryui.com
8282

8383
Temporarily change its `grunt.js` to use localhost instead of http://download.jqueryui.com.
8484
```diff
85-
var downloadBuilder = require( "download.jqueryui.com" )({
85+
var frontend = require( "download.jqueryui.com" ).frontend({
8686
- host: "http://download.jqueryui.com"
8787
+ host: "http://localhost:8088",
8888
env: "production"

frontend.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,23 @@ var _ = require( "underscore" ),
99
var errorTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/500.html", "utf-8" ) ),
1010
rootTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/root.html", "utf-8" ) );
1111

12+
/**
13+
* Frontend( options )
14+
* - options [ Object ]: key-value pairs detailed below.
15+
*
16+
* options
17+
* - config [ Object ]: optional, if present used instead of the `config.json` file;
18+
* - env [ String ]: optional, specify whether in development or production environment. Default: "development".
19+
* - host [ String ]: optional, specify the host where download.jqueryui.com server is running. Default: "" (empty string).
20+
*
21+
*/
1222
var Frontend = function( options ) {
1323
options = _.extend( {}, Frontend.defaults, options );
24+
if ( options.config && typeof options.config === "object" ) {
25+
require( "./lib/config" ).get = function() {
26+
return options.config;
27+
};
28+
}
1429
this.download = new Download( options );
1530
this.themeroller = new ThemeRoller( options );
1631
};

lib/config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ Config = module.exports = function() {
3232
jqueryUi.push( config.jqueryUi.legacy );
3333
}
3434
config.jqueryUi = jqueryUi.map(function( entry ) {
35-
if ( entry.path && !entry.version ) {
36-
entry.version = "skip";
37-
}
3835
if ( typeof entry !== "object" || !entry.version ) {
3936
throw new Error( "Invalid jqueryUi entry " + JSON.stringify( entry ) + " in config.json" );
4037
}

main.js

Lines changed: 31 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,41 @@
1-
var Main,
2-
_ = require( "underscore" ),
3-
Config = require( "./lib/config" );
1+
module.exports = {
2+
/**
3+
* The Builder class.
4+
*/
5+
Builder: require( "./lib/builder" ),
46

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

22-
Main = function( options ) {
23-
options = _.extend( {}, Main.defaults, options );
24-
if ( options.config && typeof options.config === "object" ) {
25-
Config.get = function() {
26-
return options.config;
27-
};
28-
}
29-
this.frontend = new ( require( "./frontend" ) )( options );
30-
};
12+
/**
13+
* The JqueryUi class.
14+
*/
15+
Packer: require( "./lib/packer" ),
3116

32-
Main.defaults = {
33-
// Empty, check frontend.js's.
34-
};
17+
/**
18+
* The Util object.
19+
*/
20+
util: require( "./lib/util" ),
3521

36-
Main.prototype = {
22+
/**
23+
* frontend( options )
24+
* - options [ Object ]: see `frontend.js` for more details.
25+
*
26+
* Returns a frontend instance.
27+
*/
28+
frontend: function( options ) {
29+
return new ( require( "./frontend" ) )( options );
30+
},
3731

3832
/**
39-
* Main#buildThemesBundle( callback )
40-
* - callback( err, bundleFiles ): bundleFiles is an Array of { path:<path>, data:<data> }'s.
33+
* themeGallery( jqueryUi )
34+
* - jqueryUi [ instanceof JqueryUi ]: see `frontend.js` for more details.
4135
*
42-
* Generates the theme bundle with base and all themes from themegallery.
36+
* Returns themeGallery using jqueryUi's version.
4337
*/
44-
buildThemesBundle: function( callback ) {
45-
var allComponents, jqueryUi, success,
46-
async = require( "async" ),
47-
Builder = require( "./lib/builder" ),
48-
Packer = require( "./lib/packer" ),
49-
bundleFiles = [],
50-
JqueryUi = require( "./lib/jquery-ui" ),
51-
themeGallery = require( "./lib/themeroller.themegallery" )();
52-
53-
jqueryUi = JqueryUi.getStable();
54-
allComponents = jqueryUi.components().map(function( component ) {
55-
return component.name;
56-
});
57-
58-
async.mapSeries( themeGallery, function( theme, callback ) {
59-
var build = new Builder( jqueryUi, allComponents ),
60-
packer = new Packer( build, theme, { skipDocs: true } ),
61-
folderName = theme.folderName();
62-
packer.pack(function( err, files ) {
63-
if ( err ) {
64-
return callback( err );
65-
}
66-
// Add theme files.
67-
files
68-
// Pick only theme files we need on the bundle.
69-
.filter(function( file ) {
70-
var themeCssOnlyRe = new RegExp( "development-bundle/themes/" + folderName + "/jquery.ui.theme.css" ),
71-
themeDirRe = new RegExp( "css/" + folderName );
72-
if ( themeCssOnlyRe.test( file.path ) || themeDirRe.test( file.path ) ) {
73-
return true;
74-
}
75-
return false;
76-
})
77-
// Convert paths the way bundle needs and add it into bundleFiles.
78-
.forEach(function( file ) {
79-
// 1: Remove initial package name eg. "jquery-ui-1.10.0.custom".
80-
// 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
81-
file.path = file.path
82-
.split( "/" ).slice( 1 ).join( "/" ) /* 1 */
83-
.replace( /development-bundle\/themes/, "css" )
84-
.replace( /css/, "themes" )
85-
.replace( /jquery-ui-.*?(\.min)*\.css/, "jquery-ui$1.css" ); /* 2 */
86-
bundleFiles.push( file );
87-
});
88-
89-
callback( null, files );
90-
});
91-
}, function( err ) {
92-
callback( err, bundleFiles );
93-
});
38+
themeGallery: function( jqueryUi ) {
39+
return require( "./lib/themeroller.themegallery" )( jqueryUi );
9440
}
9541
};
96-

0 commit comments

Comments
 (0)