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