Build: Make it possible to change browserSets in the testswarm task
[jquery.git] / build / release.js
blobe7da799882ffd65ae3da8c63a28d00c5c98747fd
1 module.exports = function( Release ) {
3         var
4                 fs = require( "fs" ),
5                 shell = require( "shelljs" ),
7                 // Windows needs the .cmd version but will find the non-.cmd
8                 // On Windows, ensure the HOME environment variable is set
9                 gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt",
11                 devFile = "dist/jquery.js",
12                 minFile = "dist/jquery.min.js",
13                 mapFile = "dist/jquery.min.map",
15                 cdnFolder = "dist/cdn",
17                 releaseFiles = {
18                         "jquery-VER.js": devFile,
19                         "jquery-VER.min.js": minFile,
20                         "jquery-VER.min.map": mapFile //,
21 // Disable these until 2.0 defeats 1.9 as the ONE TRUE JQUERY
22                         // "jquery.js": devFile,
23                         // "jquery.min.js": minFile,
24                         // "jquery.min.map": mapFile,
25                         // "jquery-latest.js": devFile,
26                         // "jquery-latest.min.js": minFile,
27                         // "jquery-latest.min.map": mapFile
28                 },
30                 googleFilesCDN = [
31                         "jquery.js", "jquery.min.js", "jquery.min.map"
32                 ],
34                 msFilesCDN = [
35                         "jquery-VER.js", "jquery-VER.min.js", "jquery-VER.min.map"
36                 ],
38                 _complete = Release.complete;
40         /**
41          * Generates copies for the CDNs
42          */
43         function makeReleaseCopies() {
44                 shell.mkdir( "-p", cdnFolder );
46                 Object.keys( releaseFiles ).forEach(function( key ) {
47                         var text,
48                                 builtFile = releaseFiles[ key ],
49                                 unpathedFile = key.replace( /VER/g, Release.newVersion ),
50                                 releaseFile = cdnFolder + "/" + unpathedFile;
52                         // Beta releases don't update the jquery-latest etc. copies
53                         if ( !Release.preRelease || key.indexOf( "VER" ) >= 0 ) {
55                                 if ( /\.map$/.test( releaseFile ) ) {
56                                         // Map files need to reference the new uncompressed name;
57                                         // assume that all files reside in the same directory.
58                                         // "file":"jquery.min.js","sources":["jquery.js"]
59                                         text = fs.readFileSync( builtFile, "utf8" )
60                                                 .replace( /"file":"([^"]+)","sources":\["([^"]+)"\]/,
61                                                         "\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js" ) +
62                                                         "\",\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" );
63                                         fs.writeFileSync( releaseFile, text );
64                                 } else if ( /\.min\.js$/.test( releaseFile ) ) {
65                                         // Remove the source map comment; it causes way too many problems.
66                                         // Keep the map file in case DevTools allow manual association.
67                                         text = fs.readFileSync( builtFile, "utf8" )
68                                                 .replace( /\/\/# sourceMappingURL=\S+/, "" );
69                                         fs.writeFileSync( releaseFile, text );
70                                 } else if ( builtFile !== releaseFile ) {
71                                         shell.cp( "-f", builtFile, releaseFile );
72                                 }
73                         }
74                 });
75         }
77         function buildGoogleCDN() {
78                 makeArchive( "googlecdn", googleFilesCDN );
79         }
81         function buildMicrosoftCDN() {
82                 makeArchive( "mscdn", msFilesCDN );
83         }
85         function makeArchive( cdn, files ) {
86                 if ( Release.preRelease ) {
87                         console.log( "Skipping archive creation for " + cdn + "; this is a beta release." );
88                         return;
89                 }
91                 console.log( "Creating production archive for " + cdn );
93                 var archiver = require( "archiver" )( "zip" ),
94                         md5file = cdnFolder + "/" + cdn + "-md5.txt",
95                         output = fs.createWriteStream( cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip" );
97                 output.on( "error", function( err ) {
98                         throw err;
99                 });
101                 archiver.pipe( output );
103                 files = files.map(function( item ) {
104                         return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion );
105                 });
107                 shell.exec( "md5sum", files, function( code, stdout ) {
108                         fs.writeFileSync( md5file, stdout );
109                         files.push( md5file );
111                         files.forEach(function( file ) {
112                                 archiver.append( fs.createReadStream( file ), { name: file } );
113                         });
115                         archiver.finalize();
116                 });
117         }
119         Release.define({
120                 npmPublish: true,
121                 issueTracker: "trac",
122                 contributorReportId: 508,
123                 /**
124                  * Generates any release artifacts that should be included in the release.
125                  * The callback must be invoked with an array of files that should be
126                  * committed before creating the tag.
127                  * @param {Function} callback
128                  */
129                 generateArtifacts: function( callback ) {
130                         if ( Release.exec( gruntCmd ).code !== 0 ) {
131                                 Release.abort("Grunt command failed");
132                         }
133                         makeReleaseCopies();
134                         callback([ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ]);
135                 },
136                 /**
137                  * Release completion
138                  */
139                 complete: function() {
140                         // Build CDN archives async
141                         buildGoogleCDN();
142                         buildMicrosoftCDN();
143                         _complete();
144                 },
145                 /**
146                  * Our trac milestones are different than the new version
147                  * @example
148                  *
149                  * // For Release.newVersion equal to 2.1.0 or 1.11.0
150                  * Release._tracMilestone();
151                  * // => 1.11/2.1
152                  *
153                  * // For Release.newVersion equal to 2.1.1 or 1.11.1
154                  * Release._tracMilestone();
155                  * // => 1.11.1/2.1.1
156                  */
157                 tracMilestone: function() {
158                         var otherVersion,
159                                 m = Release.newVersion.split( "." ),
160                                 major = m[0] | 0,
161                                 minor = m[1] | 0,
162                                 patch = m[2] | 0 ? "." + m[2] : "",
163                                 version = major + "." + minor + patch;
164                         if ( major === 1) {
165                                 otherVersion = "2." + ( minor - 10 ) + patch;
166                                 return version + "/" + otherVersion;
167                         }
168                         otherVersion = "1." + ( minor + 10 ) + patch;
169                         return otherVersion + "/" + version;
170                 }
171         });