-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change main DownloadBuilder, from Frontend to Main
Previously, main was `frontend.js`, now it is `main.js`. Frontend can now be accessed by `download.frontend`, where `download = require( "download.jqueryui.com" )()`; The new API: Main( options ) -- or require( "download.jqueryui.com" )( options ) - options [ Object ]: key-value pairs detailed below. options - host [ String ]: optional, specify the host where download.jqueryui.com server is running. Default: "" (empty string). - config [ Object ]: optional, if present used instead of the `config.json` file; attributes - frontend [ Object ]: for more details see `frontend.js`. Main#buildThemesBundle( callback ), generates the theme bundle with base and all themes from themegallery. - callback( err, bundleFiles ): bundleFiles is an Array of { path:<path>, data:<data> }'s. On the config, a prepared path can be specified for stable or legacy by using the `path` attribute, instead of passing the version plus letting `grunt prepare` prepare it. Eg. download = require( "download.jqueryui.com" )({ config: { "jqueryUi": { "stable": { "path": "my/stable/path" } } } }); The above prevents jQuery UI of some workarounds on its grunt `release_themes` task.
- Loading branch information
Showing
6 changed files
with
163 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,58 @@ | ||
var config, jqueryUi, | ||
var Config, jqueryUi, | ||
fs = require( "fs" ), | ||
path = require( "path" ); | ||
|
||
module.exports = config = JSON.parse( fs.readFileSync( path.join( __dirname, "../config.json" ) ) ); | ||
Config = module.exports = function() { | ||
var config = Config.get(); | ||
|
||
// Validate jqueryUi, eg: | ||
// "jqueryUi": { | ||
// "stable": { // required | ||
// "version": "1.10.0" | ||
// "dependsOn": "jQuery 1.7+" | ||
// }, | ||
// "legacy": { // optional | ||
// "version": "1.9.1" | ||
// "dependsOn": "jQuery 1.6+" | ||
// } | ||
// } | ||
if ( config.jqueryUi == null ) { | ||
throw new Error( "Missing jqueryUi branch/tag in config.json" ); | ||
} | ||
if ( typeof config.jqueryUi !== "object" ) { | ||
throw new Error( "Invalid jqueryUi branch/tag in config.json" ); | ||
} | ||
if ( config.jqueryUi.stable == null ) { | ||
throw new Error( "Missing \"stable\" jqueryUi branch/tag in config.json" ); | ||
} | ||
// Normalizing jqueryUi object into an Array | ||
jqueryUi = [ config.jqueryUi.stable ]; | ||
jqueryUi[ 0 ].stable = true; | ||
if ( config.jqueryUi.legacy ) { | ||
jqueryUi.push( config.jqueryUi.legacy ); | ||
} | ||
config.jqueryUi = jqueryUi.map(function( entry ) { | ||
if ( typeof entry !== "object" || !entry.version ) { | ||
throw new Error( "Invalid jqueryUi entry " + JSON.stringify( entry ) + " in config.json" ); | ||
// Validate jqueryUi, eg: | ||
// "jqueryUi": { | ||
// "stable": { // required | ||
// "version": "1.10.0" | ||
// "dependsOn": "jQuery 1.7+" | ||
// }, | ||
// "legacy": { // optional | ||
// "version": "1.9.1" | ||
// "dependsOn": "jQuery 1.6+" | ||
// } | ||
// } | ||
if ( config.jqueryUi == null ) { | ||
throw new Error( "Missing jqueryUi branch/tag in config.json" ); | ||
} | ||
entry.ref = entry.version; | ||
return entry; | ||
}); | ||
if ( typeof config.jqueryUi !== "object" ) { | ||
throw new Error( "Invalid jqueryUi branch/tag in config.json" ); | ||
} | ||
if ( config.jqueryUi.stable == null ) { | ||
throw new Error( "Missing \"stable\" jqueryUi branch/tag in config.json" ); | ||
} | ||
// Normalizing jqueryUi object into an Array | ||
jqueryUi = [ config.jqueryUi.stable ]; | ||
jqueryUi[ 0 ].stable = true; | ||
if ( config.jqueryUi.legacy ) { | ||
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" ); | ||
} | ||
entry.ref = entry.version; | ||
return entry; | ||
}); | ||
|
||
// Validate jquery | ||
if ( config.jquery == null ) { | ||
throw new Error( "Missing jquery version in config.json" ); | ||
} | ||
if ( typeof config.jquery !== "string" ) { | ||
throw new Error( "Invalid jquery version in config.json" ); | ||
} | ||
|
||
return config; | ||
}; | ||
|
||
// Validate jquery | ||
if ( config.jquery == null ) { | ||
throw new Error( "Missing jquery version in config.json" ); | ||
} | ||
if ( typeof config.jquery !== "string" ) { | ||
throw new Error( "Invalid jquery version in config.json" ); | ||
} | ||
Config.get = function() { | ||
return JSON.parse( fs.readFileSync( path.join( __dirname, "../config.json" ) ) ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var Main, | ||
Config = require( "./lib/config" ); | ||
|
||
/** | ||
* Main( options ) -- or require( "download.jqueryui.com" )( options ) | ||
* - options [ Object ]: key-value pairs detailed below. | ||
* | ||
* options | ||
* - host [ String ]: optional, specify the host where download.jqueryui.com server is running. Default: "" (empty string). | ||
* - config [ Object ]: optional, if present used instead of the `config.json` file; | ||
* | ||
* attributes | ||
* - frontend [ Object ]: for more details see `frontend.js`. | ||
* | ||
*/ | ||
module.exports = function( options ) { | ||
return new Main( options ); | ||
}; | ||
|
||
Main = function( options ) { | ||
options = options || {}; | ||
if ( options.config && typeof options.config === "object" ) { | ||
Config.get = function() { | ||
return options.config; | ||
}; | ||
} | ||
this.frontend = new ( require( "./frontend" ) )( options.host ); | ||
}; | ||
|
||
Main.prototype = { | ||
|
||
/** | ||
* Main#buildThemesBundle( callback ) | ||
* - callback( err, bundleFiles ): bundleFiles is an Array of { path:<path>, data:<data> }'s. | ||
* | ||
* Generates the theme bundle with base and all themes from themegallery. | ||
*/ | ||
buildThemesBundle: function( callback ) { | ||
var allComponents, release, success, | ||
async = require( "async" ), | ||
Builder = require( "./lib/builder" ), | ||
bundleFiles = [], | ||
Release = require( "./lib/release" ), | ||
themeGallery = require( "./lib/themeroller.themegallery" ); | ||
|
||
release = Release.getStable(); | ||
allComponents = release.components().map(function( component ) { | ||
return component.name; | ||
}); | ||
|
||
async.mapSeries( themeGallery, function( theme, callback ) { | ||
var builder = new Builder( release, allComponents, theme ), | ||
folderName = theme.folderName(); | ||
builder.build(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, builds ) { | ||
if ( !err ) { | ||
// Add base. | ||
builds[0] | ||
// Pick only the base files we need on the bundle. | ||
.filter(function( file ) { | ||
return (/development-bundle\/themes\/base/).test( file.path ); | ||
}) | ||
// 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". | ||
file.path = file.path | ||
.split( "/" ).slice( 1 ).join( "/" ) /* 1 */ | ||
.replace( /development-bundle\/themes/, "themes" ); | ||
bundleFiles.push( file ); | ||
}); | ||
} | ||
callback( err, bundleFiles ); | ||
}); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters