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"),
|
2013-05-12 21:21:31 +00:00
|
|
|
path = require("path"),
|
2013-05-13 01:58:53 +00:00
|
|
|
archiver = require("archiver");
|
2012-08-09 19:22:15 +00:00
|
|
|
|
|
|
|
var releaseVersion,
|
|
|
|
nextVersion,
|
|
|
|
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
|
2013-05-09 00:00:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
jQueryFilesCDN = [],
|
|
|
|
|
|
|
|
googleFilesCDN = [
|
|
|
|
"jquery.js", "jquery.min.js", "jquery.min.map"
|
|
|
|
],
|
|
|
|
|
|
|
|
msFilesCDN = [
|
|
|
|
"jquery-VER.js", "jquery-VER.min.js", "jquery-VER.min.map"
|
|
|
|
];
|
|
|
|
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
steps(
|
|
|
|
initialize,
|
|
|
|
checkGitStatus,
|
|
|
|
tagReleaseVersion,
|
|
|
|
gruntBuild,
|
|
|
|
makeReleaseCopies,
|
|
|
|
setNextVersion,
|
2013-05-09 00:00:24 +00:00
|
|
|
copyTojQueryCDN,
|
|
|
|
buildGoogleCDN,
|
|
|
|
buildMicrosoftCDN,
|
2012-08-09 19:22:15 +00:00
|
|
|
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,
|
2013-04-09 12:07:21 +00:00
|
|
|
rsemver = /^(\d+)\.(\d+)\.(\d+)(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?$/,
|
|
|
|
version = ( process.argv[3] || "" ).toLowerCase().match( rsemver ) || {},
|
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 );
|
2013-04-09 12:07:21 +00:00
|
|
|
version = pkg.version.match( rsemver );
|
2013-10-07 22:24:02 +00:00
|
|
|
oldver = ( +version[1] ) * 10000 + ( +version[2] * 100 ) + ( +version[3] );
|
2012-08-30 21:07:03 +00:00
|
|
|
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
|
|
|
|
2013-04-09 12:07:21 +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 ) {
|
2013-10-07 22:24:02 +00:00
|
|
|
git( [ "status" ], function( error, stdout ) {
|
2012-12-16 22:13:17 +00:00
|
|
|
var onBranch = ((stdout||"").match( /On branch (\S+)/ ) || [])[1];
|
|
|
|
if ( onBranch !== branch ) {
|
2013-05-13 01:58:53 +00:00
|
|
|
dieIfReal( "Branches don't match: Wanted " + branch + ", got " + onBranch );
|
2012-12-16 22:13:17 +00:00
|
|
|
}
|
2012-08-09 19:22:15 +00:00
|
|
|
if ( /Changes to be committed/i.test( stdout ) ) {
|
2013-09-19 13:06:19 +00:00
|
|
|
dieIfReal( "Please commit changed files before attempting 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 ) ) {
|
2013-05-06 14:32:16 +00:00
|
|
|
dieIfReal( "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 ) {
|
2013-10-07 22:24:02 +00:00
|
|
|
exec( gruntCmd, [], function( error, stdout, stderr ) {
|
2012-12-16 22:13:17 +00:00
|
|
|
if ( error ) {
|
|
|
|
die( error + stderr );
|
|
|
|
}
|
|
|
|
console.log( stdout );
|
|
|
|
next();
|
2013-05-13 01:58:53 +00:00
|
|
|
}, false );
|
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 ) {
|
|
|
|
Object.keys( releaseFiles ).forEach(function( key ) {
|
2012-12-29 01:47:33 +00:00
|
|
|
var text,
|
|
|
|
builtFile = releaseFiles[ key ],
|
2013-05-24 16:37:32 +00:00
|
|
|
unpathedFile = key.replace( /VER/g, releaseVersion ),
|
|
|
|
releaseFile = "dist/" + unpathedFile;
|
2012-08-09 19:22:15 +00:00
|
|
|
|
|
|
|
// Beta releases don't update the jquery-latest etc. copies
|
2013-05-17 02:48:02 +00:00
|
|
|
if ( !isBeta || key.indexOf( "VER" ) >= 0 ) {
|
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":\["([^"]+)"\]/,
|
2013-05-24 16:37:32 +00:00
|
|
|
"\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js" ) +
|
|
|
|
"\",\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" );
|
2013-05-17 02:48:02 +00:00
|
|
|
fs.writeFileSync( releaseFile, text );
|
|
|
|
} else if ( /\.min\.js$/.test( releaseFile ) ) {
|
2013-11-09 22:55:32 +00:00
|
|
|
// Remove the source map comment; it causes way too many problems.
|
|
|
|
// Keep the map file in case DevTools allow manual association.
|
2013-05-17 02:48:02 +00:00
|
|
|
text = fs.readFileSync( builtFile, "utf8" )
|
2013-11-09 22:55:32 +00:00
|
|
|
.replace( /\/\/# sourceMappingURL=\S+/, "" );
|
2013-05-17 02:48:02 +00:00
|
|
|
fs.writeFileSync( releaseFile, text );
|
|
|
|
} else if ( builtFile !== releaseFile ) {
|
|
|
|
copy( builtFile, releaseFile );
|
2012-12-29 01:47:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:00:24 +00:00
|
|
|
jQueryFilesCDN.push( releaseFile );
|
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 );
|
2013-05-06 14:32:16 +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
|
|
|
|
2013-05-09 00:00:24 +00:00
|
|
|
function copyTojQueryCDN( next ) {
|
2012-08-09 19:22:15 +00:00
|
|
|
var cmds = [];
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2013-05-09 00:00:24 +00:00
|
|
|
jQueryFilesCDN.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
|
|
|
|
2013-05-09 00:00:24 +00:00
|
|
|
function buildGoogleCDN( next ) {
|
|
|
|
makeArchive( "googlecdn", googleFilesCDN, next );
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildMicrosoftCDN( next ) {
|
|
|
|
makeArchive( "mscdn", msFilesCDN, next );
|
|
|
|
}
|
|
|
|
|
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,
|
2013-10-07 22:24:02 +00:00
|
|
|
st = arguments;
|
2012-08-09 19:22:15 +00:00
|
|
|
(function next(){
|
2012-12-29 01:47:33 +00:00
|
|
|
process.nextTick(function(){
|
2013-10-07 22:24:02 +00:00
|
|
|
st[ cur++ ]( next );
|
2012-12-29 01:47:33 +00:00
|
|
|
});
|
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
|
|
|
|
2013-05-09 00:00:24 +00:00
|
|
|
function makeArchive( cdn, files, fn ) {
|
|
|
|
if ( isBeta ) {
|
|
|
|
console.log( "Skipping archive creation for " + cdn + "; " + releaseVersion + " is beta" );
|
|
|
|
process.nextTick( fn );
|
2013-05-12 20:50:54 +00:00
|
|
|
return;
|
2013-05-09 00:00:24 +00:00
|
|
|
}
|
2013-05-12 20:50:54 +00:00
|
|
|
|
|
|
|
console.log( "Creating production archive for " + cdn );
|
|
|
|
|
2013-05-13 01:58:53 +00:00
|
|
|
var archive = archiver( "zip" ),
|
|
|
|
md5file = "dist/" + cdn + "-md5.txt",
|
|
|
|
output = fs.createWriteStream( "dist/" + cdn + "-jquery-" + releaseVersion + ".zip" );
|
2013-05-12 21:21:31 +00:00
|
|
|
|
|
|
|
archive.on( "error", function( err ) {
|
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
|
|
|
|
output.on( "close", fn );
|
2013-05-13 01:58:53 +00:00
|
|
|
archive.pipe( output );
|
2013-05-12 21:21:31 +00:00
|
|
|
|
2013-05-09 00:00:24 +00:00
|
|
|
files = files.map(function( item ) {
|
|
|
|
return "dist/" + item.replace( /VER/g, releaseVersion );
|
|
|
|
});
|
2013-05-12 20:50:54 +00:00
|
|
|
|
2013-10-07 22:24:02 +00:00
|
|
|
exec( "md5sum", files, function( err, stdout ) {
|
2013-05-09 00:00:24 +00:00
|
|
|
fs.writeFileSync( md5file, stdout );
|
|
|
|
files.push( md5file );
|
2013-05-12 21:21:31 +00:00
|
|
|
|
|
|
|
files.forEach(function( file ) {
|
|
|
|
archive.append( fs.createReadStream( file ), { name: file } );
|
|
|
|
});
|
|
|
|
|
|
|
|
archive.finalize();
|
2013-05-09 00:00:24 +00:00
|
|
|
}, false );
|
|
|
|
}
|
|
|
|
|
2013-05-13 01:58:53 +00:00
|
|
|
function copy( oldFile, newFile, skip ) {
|
2012-08-09 19:22:15 +00:00
|
|
|
console.log( "Copying " + oldFile + " to " + newFile );
|
2013-05-13 01:58:53 +00:00
|
|
|
if ( !skip ) {
|
2012-08-09 19:22:15 +00:00
|
|
|
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(" ") );
|
2013-05-06 14:32:16 +00:00
|
|
|
child.execFile( cmd, args, { env: process.env },
|
2012-12-16 22:13:17 +00:00
|
|
|
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
|
|
|
|
2013-05-06 14:32:16 +00:00
|
|
|
function dieIfReal( msg ) {
|
|
|
|
if ( debug ) {
|
|
|
|
console.log ( "DIE: " + msg );
|
|
|
|
} else {
|
|
|
|
die( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
function exit() {
|
|
|
|
process.exit( 0 );
|
|
|
|
}
|