3 * jQuery Release Management
6 var fs = require("fs"),
7 child = require("child_process"),
10 var scpURL = "jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/",
11 cdnURL = "http://code.origin.jquery.com/",
13 version = /^[\d.]+(?:(?:a|b|rc)\d+|pre)?$/,
14 versionFile = "version.txt",
16 file = "dist/jquery.js",
17 minFile = "dist/jquery.min.js",
20 "jquery-VER.js": file,
21 "jquery-VER.min.js": minFile
26 "jquery-latest.js": file,
27 "jquery.min.js": minFile,
28 "jquery-latest.min.js": minFile
31 exec( "git pull && git status", function( error, stdout, stderr ) {
32 if ( /Changes to be committed/i.test( stdout ) ) {
33 exit( "Please commit changed files before attemping to push a release." );
35 } else if ( /Changes not staged for commit/i.test( stdout ) ) {
36 exit( "Please stash files before attempting to push a release." );
43 function setVersion() {
44 var oldVersion = fs.readFileSync( versionFile, "utf8" );
46 prompt( "New Version (was " + oldVersion + "): ", function( data ) {
47 if ( data && version.test( data ) ) {
48 fs.writeFileSync( versionFile, data );
50 exec( "git commit -a -m 'Tagging the " + data + " release.' && git push && " +
51 "git tag " + data + " && git push origin " + data, function() {
56 console.error( "Malformed version number, please try again." );
62 function make( newVersion ) {
63 exec( "make clean && make", function( error, stdout, stderr ) {
64 // TODO: Verify JSLint
66 Object.keys( files ).forEach(function( oldName ) {
67 var value = files[ oldName ], name = oldName.replace( /VER/g, newVersion );
71 delete files[ oldName ];
72 files[ name ] = value;
75 exec( "scp " + Object.keys( files ).join( " " ) + " " + scpURL, function() {
76 setNextVersion( newVersion );
81 function setNextVersion( newVersion ) {
84 if ( /(?:a|b|rc)\d+$/.test( newVersion ) ) {
85 newVersion = newVersion.replace( /(?:a|b|rc)\d+$/, "pre" );
87 } else if ( /^\d+\.\d+\.?(\d*)$/.test( newVersion ) ) {
88 newVersion = newVersion.replace( /^(\d+\.\d+\.?)(\d*)$/, function( all, pre, num ) {
89 return pre + (pre.charAt( pre.length - 1 ) !== "." ? "." : "") + (num ? parseFloat( num ) + 1 : 1) + "pre";
95 prompt( "Next Version [" + newVersion + "]: ", function( data ) {
100 if ( version.test( data ) ) {
101 fs.writeFileSync( versionFile, data );
103 exec( "git commit -a -m 'Updating the source version to " + data + "' && git push", function() {
105 makeFinal( newVersion );
110 console.error( "Malformed version number, please try again." );
111 setNextVersion( newVersion );
116 function makeFinal( newVersion ) {
117 var all = Object.keys( finalFiles );
119 // Copy all the files
120 all.forEach(function( name ) {
121 copy( finalFiles[ name ], name );
124 // Upload files to CDN
125 exec( "scp " + all.join( " " ) + " " + scpURL, function() {
126 exec( "curl '" + cdnURL + "{" + all.join( "," ) + "}?reload'", function() {
127 console.log( "Done." );
132 function copy( oldFile, newFile ) {
134 console.log( "Copying " + oldFile + " to " + newFile );
137 fs.writeFileSync( newFile, fs.readFileSync( oldFile, "utf8" ) );
141 function prompt( msg, callback ) {
142 process.stdout.write( msg );
144 process.stdin.resume();
145 process.stdin.setEncoding( "utf8" );
147 process.stdin.once( "data", function( chunk ) {
148 process.stdin.pause();
149 callback( chunk.replace( /\n*$/g, "" ) );
153 function exec( cmd, fn ) {
159 child.exec( cmd, fn );
163 function exit( msg ) {
165 console.error( "\nError: " + msg );