Update Sizzle
[jquery.git] / build / release.js
blob7a42f998b499d7908adcfd7c28e691f32b80a588
1 #!/usr/bin/env node
2 /*
3  * jQuery Release Management
4  */
6 var fs = require("fs"),
7         child = require("child_process"),
8         debug = false;
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",
15         
16         file = "dist/jquery.js",
17         minFile = "dist/jquery.min.js",
18         
19         files = {
20                 "jquery-VER.js": file,
21                 "jquery-VER.min.js": minFile
22         },
23         
24         finalFiles = {
25                 "jquery.js": file,
26                 "jquery-latest.js": file,
27                 "jquery.min.js": minFile,
28                 "jquery-latest.min.js": minFile
29         };
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." );
38         } else {
39                 setVersion();
40         }
41 });
43 function setVersion() {
44         var oldVersion = fs.readFileSync( versionFile, "utf8" );
45         
46         prompt( "New Version (was " + oldVersion + "): ", function( data ) {
47                 if ( data && version.test( data ) ) {
48                         fs.writeFileSync( versionFile, data );
49                         
50                         exec( "git commit -a -m 'Tagging the " + data + " release.' && git push && " +
51                                 "git tag " + data + " && git push origin " + data, function() {
52                                         make( data );
53                         });
54                         
55                 } else {
56                         console.error( "Malformed version number, please try again." );
57                         setVersion();
58                 }
59         });
62 function make( newVersion ) {
63         exec( "make clean && make", function( error, stdout, stderr ) {
64                 // TODO: Verify JSLint
65                 
66                 Object.keys( files ).forEach(function( oldName ) {
67                         var value = files[ oldName ], name = oldName.replace( /VER/g, newVersion );
69                         copy( value, name );
71                         delete files[ oldName ];
72                         files[ name ] = value;
73                 });
75                 exec( "scp " + Object.keys( files ).join( " " ) + " " + scpURL, function() {
76                         setNextVersion( newVersion );
77                 });
78         });
81 function setNextVersion( newVersion ) {
82         var isFinal = false;
83         
84         if ( /(?:a|b|rc)\d+$/.test( newVersion ) ) {
85                 newVersion = newVersion.replace( /(?:a|b|rc)\d+$/, "pre" );
86                 
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";
90                 });
91                 
92                 isFinal = true;
93         }
94         
95         prompt( "Next Version [" + newVersion + "]: ", function( data ) {
96                 if ( !data ) {
97                         data = newVersion;
98                 }
99                 
100                 if ( version.test( data ) ) {
101                         fs.writeFileSync( versionFile, data );
102                         
103                         exec( "git commit -a -m 'Updating the source version to " + data + "' && git push", function() {
104                                 if ( isFinal ) {
105                                         makeFinal( newVersion );
106                                 }
107                         });
108                         
109                 } else {
110                         console.error( "Malformed version number, please try again." );
111                         setNextVersion( newVersion );
112                 }
113         });
116 function makeFinal( newVersion ) {
117         var all = Object.keys( finalFiles );
118         
119         // Copy all the files
120         all.forEach(function( name ) {
121                 copy( finalFiles[ name ], name );
122         });
123         
124         // Upload files to CDN
125         exec( "scp " + all.join( " " ) + " " + scpURL, function() {
126                 exec( "curl '" + cdnURL + "{" + all.join( "," ) + "}?reload'", function() {
127                         console.log( "Done." );
128                 });
129         });
132 function copy( oldFile, newFile ) {
133         if ( debug ) {
134                 console.log( "Copying " + oldFile + " to " + newFile );
136         } else {
137                 fs.writeFileSync( newFile, fs.readFileSync( oldFile, "utf8" ) );
138         }
141 function prompt( msg, callback ) {
142         process.stdout.write( msg );
143         
144         process.stdin.resume();
145         process.stdin.setEncoding( "utf8" );
146         
147         process.stdin.once( "data", function( chunk ) {
148                 process.stdin.pause();
149                 callback( chunk.replace( /\n*$/g, "" ) );
150         });
153 function exec( cmd, fn ) {
154         if ( debug ) {
155                 console.log( cmd );
156                 fn();
158         } else {
159                 child.exec( cmd, fn );
160         }
163 function exit( msg ) {
164         if ( msg ) {
165                 console.error( "\nError: " + msg );
166         }
168         process.exit( 1 );