2012-07-20 00:49:07 +00:00
|
|
|
#!/usr/bin/env node
|
2013-04-08 19:02:54 +00:00
|
|
|
/* global cat:true, cd:true, echo:true, exec:true, exit:true */
|
2012-07-20 00:49:07 +00:00
|
|
|
|
2012-12-13 16:35:41 +00:00
|
|
|
// Usage:
|
|
|
|
// stable release: node release.js
|
|
|
|
// pre-release: node release.js --pre-release {version}
|
|
|
|
|
2012-10-22 21:41:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
2012-12-13 16:35:41 +00:00
|
|
|
var baseDir, repoDir, prevVersion, newVersion, nextVersion, tagTime, preRelease,
|
2012-07-20 00:49:07 +00:00
|
|
|
fs = require( "fs" ),
|
|
|
|
rnewline = /\r?\n/,
|
|
|
|
repo = "git@github.com:jquery/jquery-ui.git",
|
|
|
|
branch = "master";
|
|
|
|
|
|
|
|
walk([
|
|
|
|
bootstrap,
|
|
|
|
|
|
|
|
section( "setting up repo" ),
|
|
|
|
cloneRepo,
|
|
|
|
checkState,
|
|
|
|
|
|
|
|
section( "calculating versions" ),
|
|
|
|
getVersions,
|
|
|
|
confirm,
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
section( "building release" ),
|
|
|
|
buildRelease,
|
|
|
|
|
|
|
|
section( "pushing tag" ),
|
|
|
|
confirmReview,
|
2012-07-20 00:49:07 +00:00
|
|
|
pushRelease,
|
|
|
|
|
|
|
|
section( "updating branch version" ),
|
|
|
|
updateBranchVersion,
|
2012-07-23 19:39:12 +00:00
|
|
|
|
|
|
|
section( "pushing " + branch ),
|
|
|
|
confirmReview,
|
2012-07-20 00:49:07 +00:00
|
|
|
pushBranch,
|
|
|
|
|
|
|
|
section( "generating changelog" ),
|
|
|
|
generateChangelog,
|
|
|
|
|
|
|
|
section( "gathering contributors" ),
|
|
|
|
gatherContributors,
|
|
|
|
|
|
|
|
section( "updating trac" ),
|
|
|
|
updateTrac,
|
2012-07-23 19:39:12 +00:00
|
|
|
confirm
|
2012-07-20 00:49:07 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function cloneRepo() {
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Cloning " + repo.cyan + "..." );
|
2012-07-20 00:49:07 +00:00
|
|
|
git( "clone " + repo + " " + repoDir, "Error cloning repo." );
|
|
|
|
cd( repoDir );
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Checking out " + branch.cyan + " branch..." );
|
2012-07-20 00:49:07 +00:00
|
|
|
git( "checkout " + branch, "Error checking out branch." );
|
2012-07-23 19:39:12 +00:00
|
|
|
echo();
|
2012-07-20 00:49:07 +00:00
|
|
|
|
|
|
|
echo( "Installing dependencies..." );
|
|
|
|
if ( exec( "npm install" ).code !== 0 ) {
|
|
|
|
abort( "Error installing dependencies." );
|
|
|
|
}
|
2012-12-13 16:35:41 +00:00
|
|
|
// We need download.jqueryui.com in order to generate themes.
|
|
|
|
// We only generate themes for stable releases.
|
|
|
|
if ( !preRelease ) {
|
|
|
|
if ( exec( "npm install download.jqueryui.com" ).code !== 0 ) {
|
|
|
|
abort( "Error installing dependencies." );
|
|
|
|
}
|
2012-09-29 20:33:30 +00:00
|
|
|
}
|
2012-07-23 19:39:12 +00:00
|
|
|
echo();
|
2012-07-20 00:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkState() {
|
|
|
|
echo( "Checking AUTHORS.txt..." );
|
|
|
|
var result, lastActualAuthor,
|
|
|
|
lastListedAuthor = cat( "AUTHORS.txt" ).trim().split( rnewline ).pop();
|
|
|
|
|
|
|
|
result = exec( "grunt authors", { silent: true });
|
|
|
|
if ( result.code !== 0 ) {
|
|
|
|
abort( "Error getting list of authors." );
|
|
|
|
}
|
|
|
|
lastActualAuthor = result.output.split( rnewline ).splice( -4, 1 )[ 0 ];
|
|
|
|
|
|
|
|
if ( lastListedAuthor !== lastActualAuthor ) {
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Last listed author is " + lastListedAuthor.red + "." );
|
|
|
|
echo( "Last actual author is " + lastActualAuthor.green + "." );
|
2012-07-20 00:49:07 +00:00
|
|
|
abort( "Please update AUTHORS.txt." );
|
|
|
|
}
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Last listed author (" + lastListedAuthor.cyan + ") is correct." );
|
2012-07-20 00:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getVersions() {
|
|
|
|
// prevVersion, newVersion, nextVersion are defined in the parent scope
|
|
|
|
var parts, major, minor, patch,
|
|
|
|
currentVersion = readPackage().version;
|
|
|
|
|
|
|
|
echo( "Validating current version..." );
|
|
|
|
if ( currentVersion.substr( -3, 3 ) !== "pre" ) {
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "The current version is " + currentVersion.red + "." );
|
2012-07-20 00:49:07 +00:00
|
|
|
abort( "The version must be a pre version." );
|
|
|
|
}
|
|
|
|
|
2012-12-13 16:35:41 +00:00
|
|
|
if ( preRelease ) {
|
|
|
|
newVersion = preRelease;
|
|
|
|
// Note: prevVersion is not currently used for pre-releases. The TODO
|
|
|
|
// below about 1.10.0 applies here as well.
|
|
|
|
prevVersion = nextVersion = currentVersion;
|
|
|
|
} else {
|
|
|
|
newVersion = currentVersion.substr( 0, currentVersion.length - 3 );
|
|
|
|
parts = newVersion.split( "." );
|
|
|
|
major = parseInt( parts[ 0 ], 10 );
|
|
|
|
minor = parseInt( parts[ 1 ], 10 );
|
|
|
|
patch = parseInt( parts[ 2 ], 10 );
|
|
|
|
|
|
|
|
// TODO: handle 1.10.0
|
|
|
|
// Also see comment above about pre-releases
|
2013-01-16 18:59:27 +00:00
|
|
|
if ( patch === 0 ) {
|
2012-12-13 16:35:41 +00:00
|
|
|
abort( "This script is not smart enough to handle the 1.10.0 release." );
|
|
|
|
}
|
|
|
|
|
|
|
|
prevVersion = patch === 0 ?
|
|
|
|
[ major, minor - 1, 0 ].join( "." ) :
|
|
|
|
[ major, minor, patch - 1 ].join( "." );
|
|
|
|
nextVersion = [ major, minor, patch + 1 ].join( "." ) + "pre";
|
2012-07-20 00:49:07 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "We are going from " + prevVersion.cyan + " to " + newVersion.cyan + "." );
|
|
|
|
echo( "After the release, the version will be " + nextVersion.cyan + "." );
|
2012-07-20 00:49:07 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
function buildRelease() {
|
2012-12-13 16:35:41 +00:00
|
|
|
var pkg,
|
|
|
|
releaseTask = preRelease ? "release" : "release_cdn";
|
2012-07-20 00:49:07 +00:00
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Creating " + "release".cyan + " branch..." );
|
2012-07-20 00:49:07 +00:00
|
|
|
git( "checkout -b release", "Error creating release branch." );
|
2012-07-23 19:39:12 +00:00
|
|
|
echo();
|
2012-07-20 00:49:07 +00:00
|
|
|
|
|
|
|
echo( "Updating package.json..." );
|
|
|
|
pkg = readPackage();
|
|
|
|
pkg.version = newVersion;
|
2012-08-23 14:27:12 +00:00
|
|
|
pkg.author.url = pkg.author.url.replace( "master", newVersion );
|
2012-07-20 00:49:07 +00:00
|
|
|
pkg.licenses.forEach(function( license ) {
|
|
|
|
license.url = license.url.replace( "master", newVersion );
|
|
|
|
});
|
|
|
|
writePackage( pkg );
|
|
|
|
|
|
|
|
echo( "Generating manifest files..." );
|
|
|
|
if ( exec( "grunt manifest" ).code !== 0 ) {
|
|
|
|
abort( "Error generating manifest files." );
|
|
|
|
}
|
2012-07-23 19:39:12 +00:00
|
|
|
echo();
|
|
|
|
|
|
|
|
echo( "Building release..." );
|
2012-12-13 16:35:41 +00:00
|
|
|
if ( exec( "grunt " + releaseTask ).code !== 0 ) {
|
2012-07-23 19:39:12 +00:00
|
|
|
abort( "Error building release." );
|
|
|
|
}
|
|
|
|
echo();
|
|
|
|
|
2012-07-20 00:49:07 +00:00
|
|
|
echo( "Committing release artifacts..." );
|
|
|
|
git( "add *.jquery.json", "Error adding manifest files to git." );
|
|
|
|
git( "commit -am 'Tagging the " + newVersion + " release.'",
|
|
|
|
"Error committing release changes." );
|
2012-07-23 19:39:12 +00:00
|
|
|
echo();
|
2012-07-20 00:49:07 +00:00
|
|
|
|
|
|
|
echo( "Tagging release..." );
|
|
|
|
git( "tag " + newVersion, "Error tagging " + newVersion + "." );
|
|
|
|
tagTime = git( "log -1 --format='%ad'", "Error getting tag timestamp." ).trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
function pushRelease() {
|
|
|
|
echo( "Pushing release to GitHub..." );
|
|
|
|
git( "push --tags", "Error pushing tags to GitHub." );
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateBranchVersion() {
|
2012-12-13 16:35:41 +00:00
|
|
|
// Pre-releases don't change the master version
|
|
|
|
if ( preRelease ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:49:07 +00:00
|
|
|
var pkg;
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Checking out " + branch.cyan + " branch..." );
|
2012-07-20 00:49:07 +00:00
|
|
|
git( "checkout " + branch, "Error checking out " + branch + " branch." );
|
|
|
|
|
|
|
|
echo( "Updating package.json..." );
|
|
|
|
pkg = readPackage();
|
|
|
|
pkg.version = nextVersion;
|
|
|
|
writePackage( pkg );
|
|
|
|
|
|
|
|
echo( "Committing version update..." );
|
|
|
|
git( "commit -am 'Updating the " + branch + " version to " + nextVersion + ".'",
|
|
|
|
"Error committing package.json." );
|
|
|
|
}
|
|
|
|
|
|
|
|
function pushBranch() {
|
2012-12-13 16:35:41 +00:00
|
|
|
// Pre-releases don't change the master version
|
|
|
|
if ( preRelease ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Pushing " + branch.cyan + " to GitHub..." );
|
2012-07-20 00:49:07 +00:00
|
|
|
git( "push", "Error pushing to GitHub." );
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateChangelog() {
|
2012-12-13 16:35:41 +00:00
|
|
|
if ( preRelease ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:49:07 +00:00
|
|
|
var commits,
|
|
|
|
changelogPath = baseDir + "/changelog",
|
|
|
|
changelog = cat( "build/release/changelog-shell" ) + "\n",
|
2012-09-21 00:21:32 +00:00
|
|
|
fullFormat = "* %s (TICKETREF, [%h](http://github.com/jquery/jquery-ui/commit/%H))";
|
|
|
|
|
2012-09-21 00:36:39 +00:00
|
|
|
changelog = changelog.replace( "{title}", "jQuery UI " + newVersion + " Changelog" );
|
2012-07-20 00:49:07 +00:00
|
|
|
|
|
|
|
echo ( "Adding commits..." );
|
|
|
|
commits = gitLog( fullFormat );
|
|
|
|
|
|
|
|
echo( "Adding links to tickets..." );
|
|
|
|
changelog += commits
|
|
|
|
// Add ticket references
|
|
|
|
.map(function( commit ) {
|
|
|
|
var tickets = [];
|
|
|
|
commit.replace( /Fixe[sd] #(\d+)/g, function( match, ticket ) {
|
|
|
|
tickets.push( ticket );
|
|
|
|
});
|
|
|
|
return tickets.length ?
|
|
|
|
commit.replace( "TICKETREF", tickets.map(function( ticket ) {
|
2012-09-21 00:21:32 +00:00
|
|
|
return "[#" + ticket + "](http://bugs.jqueryui.com/ticket/" + ticket + ")";
|
2012-07-20 00:49:07 +00:00
|
|
|
}).join( ", " ) ) :
|
|
|
|
// Leave TICKETREF token in place so it's easy to find commits without tickets
|
|
|
|
commit;
|
|
|
|
})
|
|
|
|
// Sort commits so that they're grouped by component
|
|
|
|
.sort()
|
|
|
|
.join( "\n" ) + "\n";
|
|
|
|
|
|
|
|
echo( "Adding Trac tickets..." );
|
|
|
|
changelog += trac( "/query?milestone=" + newVersion + "&resolution=fixed" +
|
|
|
|
"&col=id&col=component&col=summary&order=component" ) + "\n";
|
|
|
|
|
|
|
|
fs.writeFileSync( changelogPath, changelog );
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Stored changelog in " + changelogPath.cyan + "." );
|
2012-07-20 00:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function gatherContributors() {
|
2012-12-13 16:35:41 +00:00
|
|
|
if ( preRelease ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:49:07 +00:00
|
|
|
var contributors,
|
|
|
|
contributorsPath = baseDir + "/contributors";
|
|
|
|
|
|
|
|
echo( "Adding committers and authors..." );
|
|
|
|
contributors = gitLog( "%aN%n%cN" );
|
|
|
|
|
|
|
|
echo( "Adding reporters and commenters from Trac..." );
|
|
|
|
contributors = contributors.concat(
|
|
|
|
trac( "/report/22?V=" + newVersion + "&max=-1" )
|
|
|
|
.split( rnewline )
|
2012-07-23 19:39:12 +00:00
|
|
|
// Remove header and trailing newline
|
2012-07-20 00:49:07 +00:00
|
|
|
.slice( 1, -1 ) );
|
|
|
|
|
|
|
|
echo( "Sorting contributors..." );
|
|
|
|
contributors = unique( contributors ).sort(function( a, b ) {
|
|
|
|
return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
echo ( "Adding people thanked in commits..." );
|
|
|
|
contributors = contributors.concat(
|
|
|
|
gitLog( "%b%n%s" ).filter(function( line ) {
|
2012-10-04 01:23:20 +00:00
|
|
|
return (/thank/i).test( line );
|
2012-07-20 00:49:07 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
fs.writeFileSync( contributorsPath, contributors.join( "\n" ) );
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Stored contributors in " + contributorsPath.cyan + "." );
|
2012-07-20 00:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateTrac() {
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( newVersion.cyan + " was tagged at " + tagTime.cyan + "." );
|
2012-12-13 16:35:41 +00:00
|
|
|
if ( !preRelease ) {
|
|
|
|
echo( "Close the " + newVersion.cyan + " Milestone." );
|
|
|
|
}
|
2012-11-25 22:32:24 +00:00
|
|
|
echo( "Create the " + newVersion.cyan + " Version." );
|
|
|
|
echo( "When Trac asks for date and time, match the above. Should only change minutes and seconds." );
|
2012-07-20 00:49:07 +00:00
|
|
|
echo( "Create a Milestone for the next minor release." );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===== HELPER FUNCTIONS ======================================================
|
|
|
|
|
|
|
|
function git( command, errorMessage ) {
|
|
|
|
var result = exec( "git " + command );
|
|
|
|
if ( result.code !== 0 ) {
|
|
|
|
abort( errorMessage );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.output;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gitLog( format ) {
|
|
|
|
var result = exec( "git log " + prevVersion + ".." + newVersion + " " +
|
|
|
|
"--format='" + format + "'",
|
|
|
|
{ silent: true });
|
|
|
|
|
|
|
|
if ( result.code !== 0 ) {
|
|
|
|
abort( "Error getting git log." );
|
|
|
|
}
|
|
|
|
|
|
|
|
result = result.output.split( rnewline );
|
|
|
|
if ( result[ result.length - 1 ] === "" ) {
|
|
|
|
result.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function trac( path ) {
|
|
|
|
var result = exec( "curl -s 'http://bugs.jqueryui.com" + path + "&format=tab'",
|
|
|
|
{ silent: true });
|
|
|
|
|
|
|
|
if ( result.code !== 0 ) {
|
|
|
|
abort( "Error getting Trac data." );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.output;
|
|
|
|
}
|
|
|
|
|
|
|
|
function unique( arr ) {
|
|
|
|
var obj = {};
|
|
|
|
arr.forEach(function( item ) {
|
|
|
|
obj[ item ] = 1;
|
|
|
|
});
|
|
|
|
return Object.keys( obj );
|
|
|
|
}
|
|
|
|
|
|
|
|
function readPackage() {
|
|
|
|
return JSON.parse( fs.readFileSync( repoDir + "/package.json" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function writePackage( pkg ) {
|
|
|
|
fs.writeFileSync( repoDir + "/package.json",
|
|
|
|
JSON.stringify( pkg, null, "\t" ) + "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
function bootstrap( fn ) {
|
2012-12-13 16:35:41 +00:00
|
|
|
console.log( "Determining release type..." );
|
|
|
|
preRelease = process.argv.indexOf( "--pre-release" );
|
|
|
|
if ( preRelease !== -1 ) {
|
|
|
|
preRelease = process.argv[ preRelease + 1 ];
|
|
|
|
console.log( "pre-release" );
|
|
|
|
} else {
|
|
|
|
preRelease = null;
|
|
|
|
console.log( "stable release" );
|
|
|
|
}
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
console.log( "Determining directories..." );
|
|
|
|
baseDir = process.cwd() + "/__release";
|
|
|
|
repoDir = baseDir + "/repo";
|
|
|
|
|
2013-01-09 01:20:03 +00:00
|
|
|
if ( fs.existsSync( baseDir ) ) {
|
2012-07-23 19:39:12 +00:00
|
|
|
console.log( "The directory '" + baseDir + "' already exists." );
|
|
|
|
console.log( "Aborting." );
|
|
|
|
process.exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log( "Creating directory..." );
|
|
|
|
fs.mkdirSync( baseDir );
|
|
|
|
|
|
|
|
console.log( "Installing dependencies..." );
|
2012-11-25 22:32:24 +00:00
|
|
|
require( "child_process" ).exec( "npm install shelljs colors", function( error ) {
|
2012-07-20 00:49:07 +00:00
|
|
|
if ( error ) {
|
|
|
|
console.log( error );
|
|
|
|
return process.exit( 1 );
|
|
|
|
}
|
|
|
|
|
2012-10-04 20:48:42 +00:00
|
|
|
require( "shelljs/global" );
|
|
|
|
require( "colors" );
|
2012-07-20 00:49:07 +00:00
|
|
|
|
|
|
|
fn();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function section( name ) {
|
|
|
|
return function() {
|
|
|
|
echo();
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "##" );
|
|
|
|
echo( "## " + name.toUpperCase().magenta );
|
|
|
|
echo( "##" );
|
2012-07-20 00:49:07 +00:00
|
|
|
echo();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function prompt( fn ) {
|
|
|
|
process.stdin.once( "data", function( chunk ) {
|
|
|
|
process.stdin.pause();
|
|
|
|
fn( chunk.toString().trim() );
|
|
|
|
});
|
|
|
|
process.stdin.resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirm( fn ) {
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( "Press enter to continue, or ctrl+c to cancel.".yellow );
|
2012-07-20 00:49:07 +00:00
|
|
|
prompt( fn );
|
|
|
|
}
|
|
|
|
|
2012-07-23 19:39:12 +00:00
|
|
|
function confirmReview( fn ) {
|
|
|
|
echo( "Please review the output and generated files as a sanity check.".yellow );
|
|
|
|
confirm( fn );
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:49:07 +00:00
|
|
|
function abort( msg ) {
|
2012-07-23 19:39:12 +00:00
|
|
|
echo( msg.red );
|
|
|
|
echo( "Aborting.".red );
|
2012-07-20 00:49:07 +00:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function walk( methods ) {
|
|
|
|
var method = methods.shift();
|
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
function next() {
|
2012-07-20 00:49:07 +00:00
|
|
|
if ( methods.length ) {
|
|
|
|
walk( methods );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !method.length ) {
|
|
|
|
method();
|
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
method( next );
|
|
|
|
}
|
|
|
|
}
|