diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2015-01-28 11:37:29 -0800 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2015-01-29 12:03:40 -0800 |
commit | 26eca143c2dd857b9e3d1c446a467fed16e903d2 (patch) | |
tree | 49b5cfb4478a5678375fb29acad66551d0b119aa /build/release | |
parent | 087d280ad1160de53a45ea96184911194f7b46e0 (diff) | |
download | jquery-26eca143c2dd857b9e3d1c446a467fed16e903d2.tar.gz jquery-26eca143c2dd857b9e3d1c446a467fed16e903d2.zip |
Release: Distribute files to distribution repo
Fixes gh-1869
Fixes gh-1673
Fixes gh-2045
Diffstat (limited to 'build/release')
-rw-r--r-- | build/release/cdn.js | 106 | ||||
-rw-r--r-- | build/release/dist.js | 113 | ||||
-rw-r--r-- | build/release/ensure-sizzle.js | 50 | ||||
-rw-r--r-- | build/release/release-notes.js | 56 |
4 files changed, 325 insertions, 0 deletions
diff --git a/build/release/cdn.js b/build/release/cdn.js new file mode 100644 index 000000000..ebca6bad6 --- /dev/null +++ b/build/release/cdn.js @@ -0,0 +1,106 @@ +var + fs = require( "fs" ), + shell = require( "shelljs" ), + + cdnFolder = "dist/cdn", + + devFile = "dist/jquery.js", + minFile = "dist/jquery.min.js", + mapFile = "dist/jquery.min.map", + + releaseFiles = { + "jquery-VER.js": devFile, + "jquery-VER.min.js": minFile, + "jquery-VER.min.map": mapFile + }, + + googleFilesCDN = [ + "jquery.js", "jquery.min.js", "jquery.min.map" + ], + + msFilesCDN = [ + "jquery-VER.js", "jquery-VER.min.js", "jquery-VER.min.map" + ]; + +/** + * Generates copies for the CDNs + */ +function makeReleaseCopies( Release ) { + shell.mkdir( "-p", cdnFolder ); + + Object.keys( releaseFiles ).forEach(function( key ) { + var text, + builtFile = releaseFiles[ key ], + unpathedFile = key.replace( /VER/g, Release.newVersion ), + releaseFile = cdnFolder + "/" + unpathedFile; + + if ( /\.map$/.test( releaseFile ) ) { + // Map files need to reference the new uncompressed name; + // assume that all files reside in the same directory. + // "file":"jquery.min.js","sources":["jquery.js"] + text = fs.readFileSync( builtFile, "utf8" ) + .replace( /"file":"([^"]+)","sources":\["([^"]+)"\]/, + "\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js" ) + + "\",\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" ); + fs.writeFileSync( releaseFile, text ); + } else if ( /\.min\.js$/.test( releaseFile ) ) { + // Remove the source map comment; it causes way too many problems. + // Keep the map file in case DevTools allow manual association. + text = fs.readFileSync( builtFile, "utf8" ) + .replace( /\/\/# sourceMappingURL=\S+/, "" ); + fs.writeFileSync( releaseFile, text ); + } else if ( builtFile !== releaseFile ) { + shell.cp( "-f", builtFile, releaseFile ); + } + }); +} + +function makeArchive( Release, cdn, files ) { + if ( Release.preRelease ) { + console.log( "Skipping archive creation for " + cdn + "; this is a beta release." ); + return; + } + + console.log( "Creating production archive for " + cdn ); + + var archiver = require( "archiver" )( "zip" ), + md5file = cdnFolder + "/" + cdn + "-md5.txt", + output = fs.createWriteStream( + cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip" + ); + + output.on( "error", function( err ) { + throw err; + }); + + archiver.pipe( output ); + + files = files.map(function( item ) { + return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion ); + }); + + shell.exec( "md5sum", files, function( code, stdout ) { + fs.writeFileSync( md5file, stdout ); + files.push( md5file ); + + files.forEach(function( file ) { + archiver.append( fs.createReadStream( file ), { name: file } ); + }); + + archiver.finalize(); + }); +} + +function buildGoogleCDN( Release ) { + makeArchive( Release, "googlecdn", googleFilesCDN ); +} + +function buildMicrosoftCDN( Release ) { + makeArchive( Release, "mscdn", msFilesCDN ); +} + +module.exports = { + makeReleaseCopies: makeReleaseCopies, + buildGoogleCDN: buildGoogleCDN, + buildMicrosoftCDN: buildMicrosoftCDN +}; diff --git a/build/release/dist.js b/build/release/dist.js new file mode 100644 index 000000000..1ebeee0b9 --- /dev/null +++ b/build/release/dist.js @@ -0,0 +1,113 @@ +module.exports = function( Release, complete ) { + + var + fs = require( "fs" ), + shell = require( "shelljs" ), + pkg = require( Release.dir.repo + "/package.json" ), + // These files are included with the distrubtion + files = [ + "src", + "LICENSE.txt", + "AUTHORS.txt", + "package.json" + ]; + + /** + * Clone the distribution repo + */ + function clone() { + var distRemote = Release.remote.replace( "jquery", "jquery-dist" ); + + Release.chdir( Release.dir.base ); + Release.dir.dist = Release.dir.base + "/dist"; + + console.log( "Using distribution repo: ", distRemote ); + Release.exec( "git clone " + distRemote + " " + Release.dir.dist, + "Error cloning repo." ); + + // Distribution always works on master + Release.chdir( Release.dir.dist ); + Release.exec( "git checkout master", "Error checking out branch." ); + console.log(); + } + + /** + * Generate bower file for jquery-dist + */ + function generateBower() { + return JSON.stringify({ + name: pkg.name, + version: pkg.version, + main: pkg.main, + license: "MIT", + ignore: [ + "package.json" + ], + keywords: pkg.keywords + }, null, 2); + } + + /** + * Copy necessary files over to the dist repo + */ + function copy() { + + // Copy dist files + var distFolder = Release.dir.dist + "/dist"; + shell.mkdir( "-p", distFolder ); + [ + "dist/jquery.js", + "dist/jquery.min.js", + "dist/jquery.min.map" + ].forEach(function( file ) { + shell.cp( Release.dir.repo + "/" + file, distFolder ); + }); + + // Copy other files + files.forEach(function( file ) { + shell.cp( "-r", Release.dir.repo + "/" + file, Release.dir.dist ); + }); + + // Write generated bower file + fs.writeFileSync( Release.dir.dist + "/bower.json", generateBower() ); + + console.log( "Adding files to dist..." ); + Release.exec( "git add .", "Error adding files." ); + Release.exec( + "git commit -m 'Release " + Release.newVersion + "'", + "Error commiting files." + ); + console.log(); + + console.log( "Tagging release on dist..." ); + Release.exec( "git tag " + Release.newVersion, + "Error tagging " + Release.newVersion + " on dist repo." ); + Release.tagTime = Release.exec( "git log -1 --format='%ad'", + "Error getting tag timestamp." ).trim(); + } + + /** + * Push files to dist repo + */ + function push() { + Release.chdir( Release.dir.dist ); + + console.log( "Pushing release to dist repo..." ); + Release.exec( "git push origin master --tags", + "Error pushing master and tags to git repo." ); + + // Set repo for npm publish + Release.dir.origRepo = Release.dir.repo; + Release.dir.repo = Release.dir.dist; + } + + Release.walk([ + Release._section( "Copy files to distribution repo" ), + clone, + copy, + Release.confirmReview, + + Release._section( "Pushing files to distribution repo" ), + push + ], complete); +}; diff --git a/build/release/ensure-sizzle.js b/build/release/ensure-sizzle.js new file mode 100644 index 000000000..c3e4ed159 --- /dev/null +++ b/build/release/ensure-sizzle.js @@ -0,0 +1,50 @@ +var fs = require( "fs" ), + npm = require( "npm" ), + sizzleLoc = __dirname + "/../../external/sizzle/dist/sizzle.js", + rversion = /Engine v(\d+\.\d+\.\d+(?:-[-\.\d\w]+)?)/; + +/** + * Retrieve the latest tag of Sizzle from npm + * @param {Function(string)} callback + */ +function getLatestSizzle( callback ) { + npm.load(function( err, npm ) { + if ( err ) { + throw err; + } + npm.commands.info( [ "sizzle", "version" ], function( err, info ) { + if ( err ) { + throw err; + } + callback( Object.keys( info )[ 0 ] ); + }); + }); +} + +/** + * Ensure the /src folder has the latest tag of Sizzle + * @param {Object} Release + * @param {Function} callback + */ +function ensureSizzle( Release, callback ) { + console.log(); + console.log( "Checking Sizzle version..." ); + getLatestSizzle(function( latest ) { + var match = rversion.exec( fs.readFileSync( sizzleLoc, "utf8" ) ), + version = match ? match[ 1 ] : "Not Found"; + + if ( version !== latest ) { + // colors is inherited from jquery-release + console.log( + "The Sizzle version in the src folder (" + version.red + + ") is not the latest tag (" + latest.green + ")." + ); + Release.confirm( callback ); + } else { + console.log( "Sizzle is latest (" + latest.green + ")" ); + callback(); + } + }); +} + +module.exports = ensureSizzle; diff --git a/build/release/release-notes.js b/build/release/release-notes.js new file mode 100644 index 000000000..00cdc8659 --- /dev/null +++ b/build/release/release-notes.js @@ -0,0 +1,56 @@ +#!/usr/bin/env node +/* + * jQuery Release Note Generator + */ + +var http = require("http"), + extract = /<a href="\/ticket\/(\d+)" title="View ticket">(.*?)<[^"]+"component">\s*(\S+)/g, + version = process.argv[2]; + +if ( !/^\d+\.\d+/.test( version ) ) { + console.error( "Invalid version number: " + version ); + process.exit( 1 ); +} + +http.request({ + host: "bugs.jquery.com", + port: 80, + method: "GET", + path: "/query?status=closed&resolution=fixed&max=400&" + + "component=!web&order=component&milestone=" + version +}, function( res ) { + var data = []; + + res.on( "data", function( chunk ) { + data.push( chunk ); + }); + + res.on( "end", function() { + var match, cur, cat, + file = data.join(""); + + while ( (match = extract.exec( file )) ) { + if ( "#" + match[1] !== match[2] ) { + cat = match[3]; + + if ( !cur || cur !== cat ) { + if ( cur ) { + console.log("</ul>"); + } + cur = cat; + console.log( "<h3>" + cat.charAt(0).toUpperCase() + cat.slice(1) + "</h3>" ); + console.log("<ul>"); + } + + console.log( + " <li><a href=\"http://bugs.jquery.com/ticket/" + match[1] + "\">#" + + match[1] + ": " + match[2] + "</a></li>" + ); + } + } + if ( cur ) { + console.log("</ul>"); + } + + }); +}).end(); |