Build: update grunt-jscs-checker and pass with the new rules
[jquery.git] / build / release.js
blob2aa785eca6bfad8108421bcb61fa68a53b793392
1 module.exports = function( Release ) {
3         var
4                 fs = require( "fs" ),
5                 shell = require( "shelljs" ),
6                 ensureSizzle = require( "./ensure-sizzle" ),
8                 devFile = "dist/jquery.js",
9                 minFile = "dist/jquery.min.js",
10                 mapFile = "dist/jquery.min.map",
12                 cdnFolder = "dist/cdn",
14                 releaseFiles = {
15                         "jquery-VER.js": devFile,
16                         "jquery-VER.min.js": minFile,
17                         "jquery-VER.min.map": mapFile,
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(
92                                 cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip"
93                         );
95                 output.on( "error", function( err ) {
96                         throw err;
97                 });
99                 archiver.pipe( output );
101                 files = files.map(function( item ) {
102                         return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion );
103                 });
105                 shell.exec( "md5sum", files, function( code, stdout ) {
106                         fs.writeFileSync( md5file, stdout );
107                         files.push( md5file );
109                         files.forEach(function( file ) {
110                                 archiver.append( fs.createReadStream( file ), { name: file } );
111                         });
113                         archiver.finalize();
114                 });
115         }
117         Release.define({
118                 npmPublish: true,
119                 npmTags: function() {
120                         return [ "1.x" ];
121                 },
122                 issueTracker: "trac",
123                 contributorReportId: 508,
124                 /**
125                  * Ensure the repo is in a proper state before release
126                  * @param {Function} callback
127                  */
128                 checkRepoState: function( callback ) {
129                         ensureSizzle( Release, callback );
130                 },
131                 /**
132                  * Generates any release artifacts that should be included in the release.
133                  * The callback must be invoked with an array of files that should be
134                  * committed before creating the tag.
135                  * @param {Function} callback
136                  */
137                 generateArtifacts: function( callback ) {
138                         Release.exec( "grunt", "Grunt command failed" );
139                         makeReleaseCopies();
140                         callback([ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ]);
141                 },
142                 /**
143                  * Release completion
144                  */
145                 complete: function() {
146                         // Build CDN archives async
147                         buildGoogleCDN();
148                         buildMicrosoftCDN();
149                         _complete();
150                 },
151                 /**
152                  * Our trac milestones are different than the new version
153                  * @example
154                  *
155                  * // For Release.newVersion equal to 2.1.0 or 1.11.0
156                  * Release._tracMilestone();
157                  * // => 1.11/2.1
158                  *
159                  * // For Release.newVersion equal to 2.1.1 or 1.11.1
160                  * Release._tracMilestone();
161                  * // => 1.11.1/2.1.1
162                  */
163                 tracMilestone: function() {
164                         var otherVersion,
165                                 m = Release.newVersion.split( "." ),
166                                 major = m[0] | 0,
167                                 minor = m[1] | 0,
168                                 patch = m[2] | 0 ? "." + m[2] : "",
169                                 version = major + "." + minor + patch;
170                         if ( major === 1) {
171                                 otherVersion = "2." + ( minor - 10 ) + patch;
172                                 return version + "/" + otherVersion;
173                         }
174                         otherVersion = "1." + ( minor + 10 ) + patch;
175                         return otherVersion + "/" + version;
176                 }
177         });
180 module.exports.dependencies = [
181         "archiver@0.5.2",
182         "shelljs@0.2.6"