|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +var async = require( "async" ); |
| 4 | +var extend = require( "util" )._extend; |
| 5 | +var banner = require( "./banner" ); |
| 6 | +var sqwish = require( "sqwish" ); |
| 7 | +var Package1_12 = require( "./package-1-12" ); |
| 8 | +var path = require( "path" ); |
| 9 | +var ThemeGallery = require( "./themeroller-themegallery" ); |
| 10 | + |
| 11 | +function stripBanner( data ) { |
| 12 | + if ( data instanceof Buffer ) { |
| 13 | + data = data.toString( "utf8" ); |
| 14 | + } |
| 15 | + return data.replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" ); |
| 16 | +} |
| 17 | + |
| 18 | +function Package( files, runtime ) { |
| 19 | + this.themeGallery = ThemeGallery( runtime.jqueryUi ); |
| 20 | + if ( !runtime.themeVars ) { |
| 21 | + runtime.themeVars = this.themeGallery[ 0 ].vars; |
| 22 | + } |
| 23 | + Package1_12.apply( this, arguments ); |
| 24 | +} |
| 25 | + |
| 26 | +extend( Package.prototype, { |
| 27 | + "AUTHORS.txt": Package1_12.prototype[ "AUTHORS.txt" ], |
| 28 | + "LICENSE.txt": Package1_12.prototype[ "LICENSE.txt" ], |
| 29 | + "images": Package1_12.prototype.images, |
| 30 | + "jquery-ui.css": Package1_12.prototype[ "jquery-ui.css" ], |
| 31 | + "jquery-ui.structure.css": Package1_12.prototype[ "jquery-ui.structure.css" ], |
| 32 | + "jquery-ui.theme.css": Package1_12.prototype[ "jquery-ui.theme.css" ], |
| 33 | + "jquery-ui.min.css": Package1_12.prototype[ "jquery-ui.min.css" ], |
| 34 | + "jquery-ui.structure.min.css": Package1_12.prototype[ "jquery-ui.structure.min.css" ], |
| 35 | + "jquery-ui.theme.min.css": Package1_12.prototype[ "jquery-ui.theme.min.css" ], |
| 36 | + |
| 37 | + "themes": function( callback ) { |
| 38 | + var files = {}; |
| 39 | + var structureCssFileNames = this.structureCssFileNames; |
| 40 | + var themeCssFileNames = this.themeCssFileNames; |
| 41 | + var pkgJson = this.pkgJson; |
| 42 | + var themeGallery = this.themeGallery; |
| 43 | + this.structureCss.promise.then( function( structureCss ) { |
| 44 | + async.mapSeries( themeGallery, function( theme, callback ) { |
| 45 | + var themeCss = theme.css(); |
| 46 | + |
| 47 | + files[ path.join( theme.folderName(), "theme.css" ) ] = themeCss; |
| 48 | + |
| 49 | + var _banner = banner( pkgJson, structureCssFileNames.concat( themeCssFileNames ), { |
| 50 | + customThemeUrl: theme.url() |
| 51 | + } ); |
| 52 | + var _minBanner = banner( pkgJson, structureCssFileNames.concat( themeCssFileNames ), { |
| 53 | + minify: true, |
| 54 | + customThemeUrl: theme.url() |
| 55 | + } ); |
| 56 | + var allCss = structureCss + stripBanner( themeCss ); |
| 57 | + |
| 58 | + // Bundle CSS (and minified) |
| 59 | + files[ path.join( theme.folderName(), "jquery-ui.css" ) ] = _banner + allCss; |
| 60 | + files[ path.join( theme.folderName(), "jquery-ui.min.css" ) ] = _minBanner + sqwish.minify( allCss ); |
| 61 | + |
| 62 | + // Custom theme image files |
| 63 | + theme.generateImages( function( error, imageFiles ) { |
| 64 | + if ( error ) { |
| 65 | + return callback( error, null ); |
| 66 | + } |
| 67 | + imageFiles.forEach( function( imageFile ) { |
| 68 | + files[ path.join( theme.folderName(), "images", imageFile.path ) ] = imageFile.data; |
| 69 | + } ); |
| 70 | + callback(); |
| 71 | + } ); |
| 72 | + }, function( error ) { |
| 73 | + if ( error ) { |
| 74 | + console.log( "mapSeries( themeGallery ) failed", error ); |
| 75 | + return callback( error ); |
| 76 | + } |
| 77 | + callback( null, files ); |
| 78 | + } ); |
| 79 | + } ); |
| 80 | + } |
| 81 | +} ); |
| 82 | + |
| 83 | +module.exports = Package; |
0 commit comments