2011-04-26 20:23:09 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
/*
|
2012-08-09 19:22:15 +00:00
|
|
|
* jQuery Core Release Management
|
2011-04-26 20:23:09 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
// Debugging variables
|
|
|
|
var debug = false,
|
2012-09-21 01:12:38 +00:00
|
|
|
skipRemote = false;
|
2012-08-09 19:22:15 +00:00
|
|
|
|
2011-04-26 20:23:09 +00:00
|
|
|
var fs = require("fs"),
|
|
|
|
child = require("child_process"),
|
2012-12-16 22:13:17 +00:00
|
|
|
path = require("path");
|
2012-08-09 19:22:15 +00:00
|
|
|
|
|
|
|
var releaseVersion,
|
|
|
|
nextVersion,
|
2012-12-29 01:47:33 +00:00
|
|
|
CDNFiles,
|
2012-08-09 19:22:15 +00:00
|
|
|
isBeta,
|
|
|
|
pkg,
|
2012-12-16 22:13:17 +00:00
|
|
|
branch,
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
scpURL = "jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/",
|
2011-04-26 20:23:09 +00:00
|
|
|
cdnURL = "http://code.origin.jquery.com/",
|
2012-12-16 23:55:42 +00:00
|
|
|
repoURL = "git@github.com:jquery/jquery.git",
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
// Windows needs the .cmd version but will find the non-.cmd
|
2012-08-30 21:07:03 +00:00
|
|
|
// On Windows, ensure the HOME environment variable is set
|
2012-08-09 19:22:15 +00:00
|
|
|
gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt",
|
|
|
|
|
|
|
|
devFile = "dist/jquery.js",
|
2011-04-26 20:23:09 +00:00
|
|
|
minFile = "dist/jquery.min.js",
|
2012-12-29 01:47:33 +00:00
|
|
|
mapFile = "dist/jquery.min.map",
|
2012-08-09 19:22:15 +00:00
|
|
|
|
|
|
|
releaseFiles = {
|
|
|
|
"jquery-VER.js": devFile,
|
|
|
|
"jquery-VER.min.js": minFile,
|
2013-01-15 04:11:33 +00:00
|
|
|
"jquery-VER.min.map": mapFile //,
|
|
|
|
// Disable these until 2.0 defeats 1.9 as the ONE TRUE JQUERY
|
|
|
|
// "jquery.js": devFile,
|
|
|
|
// "jquery.min.js": minFile,
|
|
|
|
// "jquery.min.map": mapFile,
|
|
|
|
// "jquery-latest.js": devFile,
|
|
|
|
// "jquery-latest.min.js": minFile,
|
|
|
|
// "jquery-latest.min.map": mapFile
|
2011-04-26 20:23:09 +00:00
|
|
|
};
|
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
steps(
|
|
|
|
initialize,
|
|
|
|
checkGitStatus,
|
|
|
|
tagReleaseVersion,
|
|
|
|
gruntBuild,
|
|
|
|
makeReleaseCopies,
|
|
|
|
setNextVersion,
|
|
|
|
uploadToCDN,
|
|
|
|
pushToGithub,
|
|
|
|
exit
|
|
|
|
);
|
|
|
|
|
|
|
|
function initialize( next ) {
|
2012-09-21 01:12:38 +00:00
|
|
|
|
|
|
|
if ( process.argv[2] === "-d" ) {
|
|
|
|
process.argv.shift();
|
|
|
|
debug = true;
|
|
|
|
console.warn("=== DEBUG MODE ===" );
|
|
|
|
}
|
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
// First arg should be the version number being released
|
|
|
|
var newver, oldver,
|
|
|
|
rversion = /^(\d)\.(\d+)\.(\d)((?:a|b|rc)\d|pre)?$/,
|
2012-12-16 22:13:17 +00:00
|
|
|
version = ( process.argv[3] || "" ).toLowerCase().match( rversion ) || {},
|
2012-08-09 19:22:15 +00:00
|
|
|
major = version[1],
|
|
|
|
minor = version[2],
|
|
|
|
patch = version[3],
|
|
|
|
xbeta = version[4];
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-12-16 22:13:17 +00:00
|
|
|
branch = process.argv[2];
|
|
|
|
releaseVersion = process.argv[3];
|
2012-08-09 19:22:15 +00:00
|
|
|
isBeta = !!xbeta;
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-12-16 22:13:17 +00:00
|
|
|
if ( !branch || !major || !minor || !patch ) {
|
|
|
|
die( "Usage: " + process.argv[1] + " branch releaseVersion" );
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
|
|
|
if ( xbeta === "pre" ) {
|
2012-08-30 21:07:03 +00:00
|
|
|
die( "Cannot release a 'pre' version!" );
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
|
|
|
if ( !(fs.existsSync || path.existsSync)( "package.json" ) ) {
|
|
|
|
die( "No package.json in this directory" );
|
|
|
|
}
|
|
|
|
pkg = JSON.parse( fs.readFileSync( "package.json" ) );
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
console.log( "Current version is " + pkg.version + "; generating release " + releaseVersion );
|
|
|
|
version = pkg.version.match( rversion );
|
2012-08-30 21:07:03 +00:00
|
|
|
oldver = ( +version[1] ) * 10000 + ( +version[2] * 100 ) + ( +version[3] )
|
|
|
|
newver = ( +major ) * 10000 + ( +minor * 100 ) + ( +patch );
|
2012-08-09 19:22:15 +00:00
|
|
|
if ( newver < oldver ) {
|
|
|
|
die( "Next version is older than current version!" );
|
|
|
|
}
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-08-30 21:07:03 +00:00
|
|
|
nextVersion = major + "." + minor + "." + ( isBeta ? patch : +patch + 1 ) + "pre";
|
2012-08-09 19:22:15 +00:00
|
|
|
next();
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function checkGitStatus( next ) {
|
2012-12-16 22:13:17 +00:00
|
|
|
git( [ "status" ], function( error, stdout, stderr ) {
|
|
|
|
var onBranch = ((stdout||"").match( /On branch (\S+)/ ) || [])[1];
|
|
|
|
if ( onBranch !== branch ) {
|
|
|
|
die( "Branches don't match: Wanted " + branch + ", got " + onBranch );
|
|
|
|
}
|
2012-08-09 19:22:15 +00:00
|
|
|
if ( /Changes to be committed/i.test( stdout ) ) {
|
|
|
|
die( "Please commit changed files before attemping to push a release." );
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
2012-08-09 19:22:15 +00:00
|
|
|
if ( /Changes not staged for commit/i.test( stdout ) ) {
|
|
|
|
die( "Please stash files before attempting to push a release." );
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
2012-08-09 19:22:15 +00:00
|
|
|
next();
|
2011-04-26 20:23:09 +00:00
|
|
|
});
|
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function tagReleaseVersion( next ) {
|
|
|
|
updatePackageVersion( releaseVersion );
|
2012-12-16 22:13:17 +00:00
|
|
|
git( [ "commit", "-a", "-m", "Tagging the " + releaseVersion + " release." ], function(){
|
|
|
|
git( [ "tag", releaseVersion ], next, debug);
|
|
|
|
}, debug);
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function gruntBuild( next ) {
|
2012-12-16 22:13:17 +00:00
|
|
|
exec( gruntCmd, [], function( error, stdout ) {
|
|
|
|
if ( error ) {
|
|
|
|
die( error + stderr );
|
|
|
|
}
|
|
|
|
console.log( stdout );
|
|
|
|
next();
|
|
|
|
}, debug);
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function makeReleaseCopies( next ) {
|
2012-12-29 01:47:33 +00:00
|
|
|
CDNFiles = {};
|
2012-08-09 19:22:15 +00:00
|
|
|
Object.keys( releaseFiles ).forEach(function( key ) {
|
2012-12-29 01:47:33 +00:00
|
|
|
var text,
|
|
|
|
builtFile = releaseFiles[ key ],
|
2012-08-09 19:22:15 +00:00
|
|
|
releaseFile = key.replace( /VER/g, releaseVersion );
|
|
|
|
|
|
|
|
// Beta releases don't update the jquery-latest etc. copies
|
|
|
|
if ( !isBeta || key !== releaseFile ) {
|
2012-12-29 01:47:33 +00:00
|
|
|
|
|
|
|
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\":\"" + releaseFile.replace( /\.min\.map/, ".min.js" ) +
|
|
|
|
"\",\"sources\":[\"" + releaseFile.replace( /\.min\.map/, ".js" ) + "\"]" );
|
|
|
|
console.log( "Modifying map " + builtFile + " to " + releaseFile );
|
|
|
|
if ( !debug ) {
|
|
|
|
fs.writeFileSync( releaseFile, text );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
copy( builtFile, releaseFile );
|
|
|
|
}
|
|
|
|
|
|
|
|
CDNFiles[ releaseFile ] = builtFile;
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
2011-04-26 20:23:09 +00:00
|
|
|
});
|
2012-08-09 19:22:15 +00:00
|
|
|
next();
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function setNextVersion( next ) {
|
|
|
|
updatePackageVersion( nextVersion );
|
2012-12-16 22:13:17 +00:00
|
|
|
git( [ "commit", "-a", "-m", "Updating the source version to " + nextVersion ], next, debug );
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function uploadToCDN( next ) {
|
|
|
|
var cmds = [];
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-12-29 01:47:33 +00:00
|
|
|
Object.keys( CDNFiles ).forEach(function( name ) {
|
2012-12-16 22:13:17 +00:00
|
|
|
cmds.push(function( nxt ){
|
|
|
|
exec( "scp", [ name, scpURL ], nxt, debug || skipRemote );
|
2012-08-09 19:22:15 +00:00
|
|
|
});
|
2012-12-16 22:13:17 +00:00
|
|
|
cmds.push(function( nxt ){
|
|
|
|
exec( "curl", [ cdnURL + name + "?reload" ], nxt, debug || skipRemote );
|
2012-08-09 19:22:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
cmds.push( next );
|
2013-03-13 01:06:25 +00:00
|
|
|
|
2012-08-30 21:07:03 +00:00
|
|
|
steps.apply( this, cmds );
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function pushToGithub( next ) {
|
2012-12-16 22:13:17 +00:00
|
|
|
git( [ "push", "--tags", repoURL, branch ], next, debug || skipRemote );
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
//==============================
|
|
|
|
|
|
|
|
function steps() {
|
|
|
|
var cur = 0,
|
|
|
|
steps = arguments;
|
|
|
|
(function next(){
|
2012-12-29 01:47:33 +00:00
|
|
|
process.nextTick(function(){
|
|
|
|
steps[ cur++ ]( next );
|
|
|
|
});
|
2012-08-09 19:22:15 +00:00
|
|
|
})();
|
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function updatePackageVersion( ver ) {
|
|
|
|
console.log( "Updating package.json version to " + ver );
|
|
|
|
pkg.version = ver;
|
|
|
|
if ( !debug ) {
|
|
|
|
fs.writeFileSync( "package.json", JSON.stringify( pkg, null, "\t" ) + "\n" );
|
|
|
|
}
|
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function copy( oldFile, newFile ) {
|
|
|
|
console.log( "Copying " + oldFile + " to " + newFile );
|
|
|
|
if ( !debug ) {
|
|
|
|
fs.writeFileSync( newFile, fs.readFileSync( oldFile, "utf8" ) );
|
|
|
|
}
|
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-12-16 22:13:17 +00:00
|
|
|
function git( args, fn, skip ) {
|
|
|
|
exec( "git", args, fn, skip );
|
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-12-16 22:13:17 +00:00
|
|
|
function exec( cmd, args, fn, skip ) {
|
|
|
|
if ( skip ) {
|
|
|
|
console.log( "# " + cmd + " " + args.join(" ") );
|
|
|
|
fn( "", "", "" );
|
2011-04-26 20:23:09 +00:00
|
|
|
} else {
|
2012-12-16 22:13:17 +00:00
|
|
|
console.log( cmd + " " + args.join(" ") );
|
|
|
|
child.execFile( cmd, args, { env: process.env },
|
|
|
|
function( err, stdout, stderr ) {
|
|
|
|
if ( err ) {
|
|
|
|
die( stderr || stdout || err );
|
|
|
|
}
|
|
|
|
fn.apply( this, arguments );
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
2012-12-16 22:13:17 +00:00
|
|
|
);
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function die( msg ) {
|
2012-08-30 21:07:03 +00:00
|
|
|
console.error( "ERROR: " + msg );
|
2011-04-26 20:23:09 +00:00
|
|
|
process.exit( 1 );
|
|
|
|
}
|
2012-12-29 01:47:33 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function exit() {
|
|
|
|
process.exit( 0 );
|
|
|
|
}
|