| 1 |
"use strict"; |
| 2 |
|
| 3 |
module.exports = function( Release ) { |
| 4 |
|
| 5 |
var crypto = require( "crypto" ); |
| 6 |
var shell = require( "shelljs" ), |
| 7 |
path = require( "path" ), |
| 8 |
fs = require( "fs" ); |
| 9 |
|
| 10 |
function replaceAtVersion() { |
| 11 |
console.log( "Replacing @VERSION..." ); |
| 12 |
var matches = []; |
| 13 |
|
| 14 |
function recurse( folder ) { |
| 15 |
fs.readdirSync( folder ).forEach( function( fileName ) { |
| 16 |
var content, |
| 17 |
fullPath = folder + "/" + fileName; |
| 18 |
if ( fs.statSync( fullPath ).isDirectory() ) { |
| 19 |
recurse( fullPath ); |
| 20 |
return; |
| 21 |
} |
| 22 |
content = fs.readFileSync( fullPath, { |
| 23 |
encoding: "utf-8" |
| 24 |
} ); |
| 25 |
if ( !/@VERSION/.test( content ) ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
matches.push( fullPath ); |
| 29 |
fs.writeFileSync( fullPath, content.replace( /@VERSION/g, Release.newVersion ) ); |
| 30 |
} ); |
| 31 |
} |
| 32 |
|
| 33 |
[ "ui", "themes" ].forEach( recurse ); |
| 34 |
|
| 35 |
console.log( "Replaced @VERSION in " + matches.length + " files." ); |
| 36 |
|
| 37 |
return matches; |
| 38 |
} |
| 39 |
|
| 40 |
function removeExternals( packager ) { |
| 41 |
Object.keys( packager.builtFiles ).forEach( function( filepath ) { |
| 42 |
if ( /^external\//.test( filepath ) ) { |
| 43 |
delete packager.builtFiles[ filepath ]; |
| 44 |
} |
| 45 |
} ); |
| 46 |
} |
| 47 |
|
| 48 |
function addManifest( packager ) { |
| 49 |
var output = packager.builtFiles; |
| 50 |
output.MANIFEST = Object.keys( output ).sort( function( a, b ) { |
| 51 |
return a.localeCompare( b ); |
| 52 |
} ).map( function( filepath ) { |
| 53 |
var md5 = crypto.createHash( "md5" ); |
| 54 |
md5.update( output[ filepath ] ); |
| 55 |
return filepath + " " + md5.digest( "hex" ); |
| 56 |
} ).join( "\n" ); |
| 57 |
} |
| 58 |
|
| 59 |
function buildCDNPackage( callback ) { |
| 60 |
console.log( "Building CDN package" ); |
| 61 |
var JqueryUi = require( "download.jqueryui.com/lib/jquery-ui" ); |
| 62 |
var PackageWithoutThemes = require( "download.jqueryui.com/lib/package" ); |
| 63 |
var PackageOfThemes = require( "download.jqueryui.com/lib/package-themes" ); |
| 64 |
var Packager = require( "node-packager" ); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
function Package() { |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
PackageOfThemes.apply( this, arguments ); |
| 73 |
} |
| 74 |
|
| 75 |
Object.assign( Package.prototype, PackageWithoutThemes.prototype, PackageOfThemes.prototype ); |
| 76 |
|
| 77 |
var jqueryUi = new JqueryUi( path.resolve( "." ) ); |
| 78 |
var target = fs.createWriteStream( "../" + jqueryUi.pkg.name + "-" + jqueryUi.pkg.version + |
| 79 |
"-cdn.zip" ); |
| 80 |
var packager = new Packager( jqueryUi.files().cache, Package, { |
| 81 |
components: jqueryUi.components().map( function( component ) { |
| 82 |
return component.name; |
| 83 |
} ), |
| 84 |
jqueryUi: jqueryUi, |
| 85 |
themeVars: null |
| 86 |
} ); |
| 87 |
packager.ready |
| 88 |
.then( function() { |
| 89 |
removeExternals( packager ); |
| 90 |
addManifest( packager ); |
| 91 |
packager.toZip( target, { |
| 92 |
basedir: "" |
| 93 |
}, function( error ) { |
| 94 |
if ( error ) { |
| 95 |
Release.abort( "Failed to zip the CDN package", error ); |
| 96 |
} |
| 97 |
callback(); |
| 98 |
} ); |
| 99 |
} ) |
| 100 |
.catch( function( error ) { |
| 101 |
Release.abort( "Failed to create the CDN package", error ); |
| 102 |
} ); |
| 103 |
} |
| 104 |
|
| 105 |
Release.define( { |
| 106 |
npmPublish: true, |
| 107 |
issueTracker: "github", |
| 108 |
changelogShell: function() { |
| 109 |
var monthNames = [ "January", "February", "March", "April", "May", "June", "July", |
| 110 |
"August", "September", "October", "November", "December" ], |
| 111 |
now = new Date(); |
| 112 |
return "<script>{\n\t\"title\": \"jQuery UI " + Release.newVersion + " Changelog\"\n" + |
| 113 |
"}</script>\n\nReleased on " + monthNames[ now.getMonth() ] + " " + now.getDate() + |
| 114 |
", " + now.getFullYear() + "\n\n"; |
| 115 |
}, |
| 116 |
generateArtifacts: function( fn ) { |
| 117 |
var files = replaceAtVersion(); |
| 118 |
|
| 119 |
buildCDNPackage( function copyCdnFiles() { |
| 120 |
var zipFile = shell.ls( "../jquery*-cdn.zip" )[ 0 ], |
| 121 |
tmpFolder = "../tmp-zip-output", |
| 122 |
unzipCommand = "unzip -o " + zipFile + " -d " + tmpFolder; |
| 123 |
|
| 124 |
console.log( "Unzipping for dist/cdn copies" ); |
| 125 |
shell.mkdir( "-p", tmpFolder ); |
| 126 |
Release.exec( { |
| 127 |
command: unzipCommand, |
| 128 |
silent: true |
| 129 |
}, "Failed to unzip cdn files" ); |
| 130 |
|
| 131 |
shell.mkdir( "-p", "dist/cdn" ); |
| 132 |
shell.cp( tmpFolder + "/jquery-ui*.js", "dist/cdn" ); |
| 133 |
shell.cp( "-r", tmpFolder + "/themes", "dist/cdn" ); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
shell.cp( "dist/cdn/jquery-ui.js", "dist" ); |
| 138 |
shell.cp( "dist/cdn/jquery-ui.min.js", "dist" ); |
| 139 |
shell.cp( "-r", "dist/cdn/themes", "dist" ); |
| 140 |
|
| 141 |
Release.exec( "git add --force dist/jquery-ui.js", |
| 142 |
"Error adding dist/jquery-ui.js." ); |
| 143 |
Release.exec( "git add --force dist/jquery-ui.min.js", |
| 144 |
"Error adding dist/jquery-ui.min.js." ); |
| 145 |
Release.exec( "git add --force dist/themes", |
| 146 |
"Error adding dist/themes." ); |
| 147 |
|
| 148 |
fn( files ); |
| 149 |
} ); |
| 150 |
} |
| 151 |
} ); |
| 152 |
|
| 153 |
}; |
| 154 |
|
| 155 |
module.exports.dependencies = [ |
| 156 |
"[email protected]", |
| 157 |
"[email protected]", |
| 158 |
"[email protected]" |
| 159 |
]; |