aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2011-04-26 16:23:09 -0400
committerJohn Resig <jeresig@gmail.com>2011-04-26 16:23:09 -0400
commita8988e3cd13d1ffab4291ec9fcbd2f88b8e424a2 (patch)
tree2e5386e6331f3fa356120dc36cae91db0a6d4f36 /build
parentfd11df1ec477690e7b50c532d04d1781dac91284 (diff)
downloadjquery-a8988e3cd13d1ffab4291ec9fcbd2f88b8e424a2.tar.gz
jquery-a8988e3cd13d1ffab4291ec9fcbd2f88b8e424a2.zip
Adding a Node-based release management script for pushing new releases to the CDN.
Diffstat (limited to 'build')
-rw-r--r--build/release.js169
1 files changed, 169 insertions, 0 deletions
diff --git a/build/release.js b/build/release.js
new file mode 100644
index 000000000..09f917b48
--- /dev/null
+++ b/build/release.js
@@ -0,0 +1,169 @@
+#!/usr/bin/env node
+/*
+ * jQuery Release Management
+ */
+
+var fs = require("fs"),
+ child = require("child_process"),
+ debug = false;
+
+var scpURL = "jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/",
+ cdnURL = "http://code.origin.jquery.com/",
+
+ version = /^[\d.]+(?:(?:a|b|rc)\d+|pre)?$/,
+ versionFile = "version.txt",
+
+ file = "dist/jquery.js",
+ minFile = "dist/jquery.min.js",
+
+ files = {
+ "jquery-VER.js": file,
+ "jquery-VER.min.js": minFile
+ },
+
+ finalFiles = {
+ "jquery.js": file,
+ "jquery-latest.js": file,
+ "jquery.min.js": minFile,
+ "jquery-latest.min.js": minFile
+ };
+
+exec( "git pull && git status", function( error, stdout, stderr ) {
+ if ( /Changes to be committed/i.test( stdout ) ) {
+ exit( "Please commit changed files before attemping to push a release." );
+
+ } else if ( /Changes not staged for commit/i.test( stdout ) ) {
+ exit( "Please stash files before attempting to push a release." );
+
+ } else {
+ setVersion();
+ }
+});
+
+function setVersion() {
+ var oldVersion = fs.readFileSync( versionFile, "utf8" );
+
+ prompt( "New Version (was " + oldVersion + "): ", function( data ) {
+ if ( data && version.test( data ) ) {
+ fs.writeFileSync( versionFile, data );
+
+ exec( "git commit -a -m 'Tagging the " + data + " release.' && git push && " +
+ "git tag " + data + " && git push origin " + data, function() {
+ make( data );
+ });
+
+ } else {
+ console.error( "Malformed version number, please try again." );
+ setVersion();
+ }
+ });
+}
+
+function make( newVersion ) {
+ exec( "make clean && make", function( error, stdout, stderr ) {
+ // TODO: Verify JSLint
+
+ Object.keys( files ).forEach(function( oldName ) {
+ var value = files[ oldName ], name = oldName.replace( /VER/g, newVersion );
+
+ copy( value, name );
+
+ delete files[ oldName ];
+ files[ name ] = value;
+ });
+
+ exec( "scp " + Object.keys( files ).join( " " ) + " " + scpURL, function() {
+ setNextVersion( newVersion );
+ });
+ });
+}
+
+function setNextVersion( newVersion ) {
+ var isFinal = false;
+
+ if ( /(?:a|b|rc)\d+$/.test( newVersion ) ) {
+ newVersion = newVersion.replace( /(?:a|b|rc)\d+$/, "pre" );
+
+ } else if ( /^\d+\.\d+\.?(\d*)$/.test( newVersion ) ) {
+ newVersion = newVersion.replace( /^(\d+\.\d+\.?)(\d*)$/, function( all, pre, num ) {
+ return pre + (num ? parseFloat( num ) + 1 : 1) + "pre";
+ });
+
+ isFinal = true;
+ }
+
+ prompt( "Next Version [" + newVersion + "]: ", function( data ) {
+ if ( !data ) {
+ data = newVersion;
+ }
+
+ if ( version.test( data ) ) {
+ fs.writeFileSync( versionFile, data );
+
+ exec( "git commit -a -m 'Updating the source version to " + data + "' && git push", function() {
+ if ( isFinal ) {
+ makeFinal( newVersion );
+ }
+ });
+
+ } else {
+ console.error( "Malformed version number, please try again." );
+ setNextVersion( newVersion );
+ }
+ });
+}
+
+function makeFinal( newVersion ) {
+ var all = Object.keys( finalFiles );
+
+ // Copy all the files
+ all.forEach(function( name ) {
+ copy( finalFiles[ name ], name );
+ });
+
+ // Upload files to CDN
+ exec( "scp " + all.join( " " ) + " " + scpURL, function() {
+ exec( "curl '" + cdnURL + "{" + all.join( "," ) + "}?reload'", function() {
+ console.log( "Done." );
+ });
+ });
+}
+
+function copy( oldFile, newFile ) {
+ if ( debug ) {
+ console.log( "Copying " + oldFile + " to " + newFile );
+
+ } else {
+ fs.writeFileSync( newFile, fs.readFileSync( oldFile, "utf8" ) );
+ }
+}
+
+function prompt( msg, callback ) {
+ process.stdout.write( msg );
+
+ process.stdin.resume();
+ process.stdin.setEncoding( "utf8" );
+
+ process.stdin.once( "data", function( chunk ) {
+ process.stdin.pause();
+ callback( chunk.replace( /\n*$/g, "" ) );
+ });
+}
+
+function exec( cmd, fn ) {
+ if ( debug ) {
+ console.log( cmd );
+ fn();
+
+ } else {
+ child.exec( cmd, fn );
+ }
+}
+
+function exit( msg ) {
+ if ( msg ) {
+ console.error( "\nError: " + msg );
+ }
+
+ process.exit( 1 );
+}