123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- #!/usr/bin/env node
- /*
- * jQuery Core Release Management
- */
- // Debugging variables
- var debug = false,
- skipRemote = false;
- var fs = require("fs"),
- child = require("child_process"),
- path = require("path"),
- which = require("which").sync;
- var releaseVersion,
- nextVersion,
- finalFiles,
- isBeta,
- pkg,
- branch,
- scpURL = "jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/",
- cdnURL = "http://code.origin.jquery.com/",
- repoURL = "git@github.com:dmethvin/jquery.git",
- //repoURL = "git@github.com:jquery/jquery.git",
- // Windows needs the .cmd version but will find the non-.cmd
- // On Windows, ensure the HOME environment variable is set
- gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt",
- devFile = "dist/jquery.js",
- minFile = "dist/jquery.min.js",
- releaseFiles = {
- "jquery-VER.js": devFile,
- "jquery-VER.min.js": minFile,
- "jquery.js": devFile,
- "jquery-latest.js": devFile,
- "jquery.min.js": minFile,
- "jquery-latest.min.js": minFile
- };
- steps(
- initialize,
- checkGitStatus,
- tagReleaseVersion,
- gruntBuild,
- makeReleaseCopies,
- setNextVersion,
- uploadToCDN,
- pushToGithub,
- exit
- );
- function initialize( next ) {
- if ( process.argv[2] === "-d" ) {
- process.argv.shift();
- debug = true;
- console.warn("=== DEBUG MODE ===" );
- }
- // First arg should be the version number being released
- var newver, oldver,
- rversion = /^(\d)\.(\d+)\.(\d)((?:a|b|rc)\d|pre)?$/,
- version = ( process.argv[3] || "" ).toLowerCase().match( rversion ) || {},
- major = version[1],
- minor = version[2],
- patch = version[3],
- xbeta = version[4];
- branch = process.argv[2];
- releaseVersion = process.argv[3];
- isBeta = !!xbeta;
- if ( !branch || !major || !minor || !patch ) {
- die( "Usage: " + process.argv[1] + " branch releaseVersion" );
- }
- if ( xbeta === "pre" ) {
- die( "Cannot release a 'pre' version!" );
- }
- if ( !(fs.existsSync || path.existsSync)( "package.json" ) ) {
- die( "No package.json in this directory" );
- }
- pkg = JSON.parse( fs.readFileSync( "package.json" ) );
- console.log( "Current version is " + pkg.version + "; generating release " + releaseVersion );
- version = pkg.version.match( rversion );
- oldver = ( +version[1] ) * 10000 + ( +version[2] * 100 ) + ( +version[3] )
- newver = ( +major ) * 10000 + ( +minor * 100 ) + ( +patch );
- if ( newver < oldver ) {
- die( "Next version is older than current version!" );
- }
- nextVersion = major + "." + minor + "." + ( isBeta ? patch : +patch + 1 ) + "pre";
- next();
- }
- function checkGitStatus( next ) {
- child.execFile( "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 );
- }
- if ( /Changes to be committed/i.test( stdout ) ) {
- die( "Please commit changed files before attemping to push a release." );
- }
- if ( /Changes not staged for commit/i.test( stdout ) ) {
- die( "Please stash files before attempting to push a release." );
- }
- next();
- });
- }
- function tagReleaseVersion( next ) {
- updatePackageVersion( releaseVersion );
- git( [ "commit", "-a", "-m", "Tagging the " + releaseVersion + " release." ], function(){
- git( [ "tag", releaseVersion ], next);
- });
- }
- 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;
- }
- });
- next();
- }
- function setNextVersion( next ) {
- updatePackageVersion( nextVersion );
- git( [ "commit", "-a", "-m", "Updating the source version to " + nextVersion ], next );
- }
- function uploadToCDN( next ) {
- var cmds = [];
- Object.keys( finalFiles ).forEach(function( name ) {
- cmds.push(function( x ){
- exec( "scp", [ name, scpURL ], x, skipRemote );
- });
- cmds.push(function( x ){
- exec( "curl", [ cdnURL + name + "?reload" ], x, skipRemote );
- });
- });
- cmds.push( next );
-
- steps.apply( this, cmds );
- }
- function pushToGithub( next ) {
- git( [ "push", "--tags", repoURL, branch ], next, skipRemote );
- }
- //==============================
- 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" ) );
- }
- }
- function git( args, fn, skip ) {
- exec( "git", args, fn, skip );
- }
- function exec( cmd, args, fn, skip ) {
- if ( debug || skip ) {
- console.log( "# " + cmd + " " + args.join(" ") );
- fn();
- } else {
- console.log( cmd + " " + args.join(" ") );
- child.execFile( cmd, args, { env: process.env },
- function( err, stdout, stderr ) {
- if ( err ) {
- die( stderr || stdout || err );
- }
- fn();
- }
- );
- }
- }
- function die( msg ) {
- console.error( "ERROR: " + msg );
- process.exit( 1 );
- }
- function exit() {
- process.exit( 0 );
- }
|