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-08-09 19:22:15 +00:00
|
|
|
path = require("path"),
|
|
|
|
which = require('which').sync;
|
|
|
|
|
|
|
|
var releaseVersion,
|
|
|
|
nextVersion,
|
|
|
|
finalFiles,
|
|
|
|
isBeta,
|
|
|
|
pkg,
|
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-08-09 19:22:15 +00:00
|
|
|
repoURL = "git://github.com/jquery/jquery.git",
|
|
|
|
branch = "master",
|
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-08-09 19:22:15 +00:00
|
|
|
|
|
|
|
releaseFiles = {
|
|
|
|
"jquery-VER.js": devFile,
|
|
|
|
"jquery-VER.min.js": minFile,
|
|
|
|
"jquery.js": devFile,
|
|
|
|
"jquery-latest.js": devFile,
|
2011-04-26 20:23:09 +00:00
|
|
|
"jquery.min.js": minFile,
|
|
|
|
"jquery-latest.min.js": minFile
|
|
|
|
};
|
|
|
|
|
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)?$/,
|
|
|
|
version = ( process.argv[2] || "" ).toLowerCase().match( rversion ) || {},
|
|
|
|
major = version[1],
|
|
|
|
minor = version[2],
|
|
|
|
patch = version[3],
|
|
|
|
xbeta = version[4];
|
2011-04-26 20:23:09 +00:00
|
|
|
|
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
releaseVersion = process.argv[2];
|
|
|
|
isBeta = !!xbeta;
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
if ( !major || !minor || !patch ) {
|
|
|
|
die( "Usage: " + process.argv[1] + " releaseVersion" );
|
|
|
|
}
|
|
|
|
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-08-09 19:22:15 +00:00
|
|
|
function checkGitStatus( next ) {
|
|
|
|
exec( "git status", function( error, stdout, stderr ) {
|
|
|
|
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-08-09 19:22:15 +00:00
|
|
|
function tagReleaseVersion( next ) {
|
|
|
|
updatePackageVersion( releaseVersion );
|
|
|
|
exec( 'git commit -a -m "Tagging the ' + releaseVersion + ' release."', function(){
|
|
|
|
exec( "git tag " + releaseVersion, next);
|
2011-04-26 20:23:09 +00:00
|
|
|
});
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
|
|
|
function gruntBuild( next ) {
|
|
|
|
exec( gruntCmd, next );
|
|
|
|
}
|
|
|
|
function makeReleaseCopies( next ) {
|
|
|
|
finalFiles = {};
|
|
|
|
Object.keys( releaseFiles ).forEach(function( key ) {
|
|
|
|
var builtFile = releaseFiles[ key ],
|
|
|
|
releaseFile = key.replace( /VER/g, releaseVersion );
|
|
|
|
|
|
|
|
// Beta releases don't update the jquery-latest etc. copies
|
|
|
|
if ( !isBeta || key !== releaseFile ) {
|
|
|
|
copy( builtFile, releaseFile );
|
|
|
|
finalFiles[ releaseFile ] = builtFile;
|
|
|
|
}
|
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-08-09 19:22:15 +00:00
|
|
|
function setNextVersion( next ) {
|
|
|
|
updatePackageVersion( nextVersion );
|
2012-08-09 20:25:57 +00:00
|
|
|
exec( 'git commit -a -m "Updating the source version to ' + nextVersion + '"', next );
|
2012-08-09 19:22:15 +00:00
|
|
|
}
|
|
|
|
function uploadToCDN( next ) {
|
|
|
|
var cmds = [];
|
2011-04-26 20:23:09 +00:00
|
|
|
|
2012-08-09 19:22:15 +00:00
|
|
|
Object.keys( finalFiles ).forEach(function( name ) {
|
|
|
|
cmds.push(function( x ){
|
2012-08-30 21:07:03 +00:00
|
|
|
exec( "scp " + name + " " + scpURL, x, skipRemote );
|
2012-08-09 19:22:15 +00:00
|
|
|
});
|
|
|
|
cmds.push(function( x ){
|
2012-08-30 21:07:03 +00:00
|
|
|
exec( "curl '" + cdnURL + name + "?reload'", x, skipRemote );
|
2012-08-09 19:22:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
cmds.push( next );
|
|
|
|
|
2012-08-30 21:07:03 +00:00
|
|
|
steps.apply( this, cmds );
|
2011-04-26 20:23:09 +00:00
|
|
|
}
|
2012-08-09 19:22:15 +00:00
|
|
|
function pushToGithub( next ) {
|
2012-08-30 21:07:03 +00:00
|
|
|
exec("git push --tags "+ repoURL + " " + branch, next, 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(){
|
|
|
|
var step = steps[ cur++ ];
|
|
|
|
step( next );
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function copy( oldFile, newFile ) {
|
|
|
|
console.log( "Copying " + oldFile + " to " + newFile );
|
|
|
|
if ( !debug ) {
|
|
|
|
fs.writeFileSync( newFile, fs.readFileSync( oldFile, "utf8" ) );
|
|
|
|
}
|
|
|
|
}
|
2012-08-30 21:07:03 +00:00
|
|
|
function exec( cmd, fn, skip ) {
|
|
|
|
if ( debug || skip ) {
|
|
|
|
console.log( "# " + cmd );
|
2011-04-26 20:23:09 +00:00
|
|
|
fn();
|
|
|
|
} else {
|
2012-08-30 21:07:03 +00:00
|
|
|
console.log( cmd );
|
2012-08-09 19:22:15 +00:00
|
|
|
child.exec( cmd, { env: process.env }, function( err, stdout, stderr ) {
|
|
|
|
if ( err ) {
|
|
|
|
die( stderr || stdout || err );
|
|
|
|
}
|
|
|
|
fn();
|
|
|
|
});
|
2011-04-26 20:23:09 +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-08-09 19:22:15 +00:00
|
|
|
function exit() {
|
|
|
|
process.exit( 0 );
|
|
|
|
}
|