]> source.dussan.org Git - jquery.git/commitdiff
Release: fix CDN archive creation
authorTimmy Willison <timmywillisn@gmail.com>
Fri, 30 Jan 2015 00:21:39 +0000 (16:21 -0800)
committerTimmy Willison <timmywillisn@gmail.com>
Fri, 30 Jan 2015 02:23:52 +0000 (18:23 -0800)
Fixes gh-1940

build/release.js
build/release/cdn.js

index b5eaf4df52673267528c5a64b88aaaba6a1c07ac..c394eac32e1307c091fac92d75f28b299774129c 100644 (file)
@@ -58,13 +58,15 @@ module.exports = function( Release ) {
                 * @param {Function} callback
                 */
                dist: function( callback ) {
-                       dist( Release, callback );
+                       cdn.makeArchives( Release, function() {
+                               dist( Release, callback );
+                       });
                }
        });
 };
 
 module.exports.dependencies = [
-       "archiver@0.5.2",
+       "archiver@0.14.2",
        "shelljs@0.2.6",
        "npm@2.3.0"
 ];
index 81dac2baca4dd1fc5bfea753339329a093ed3922..215241f407796607ce2ffb429d03ff6483f67364 100644 (file)
@@ -1,6 +1,7 @@
 var
        fs = require( "fs" ),
        shell = require( "shelljs" ),
+       path = require( "path" ),
 
        cdnFolder = "dist/cdn",
 
@@ -20,18 +21,22 @@ var
 
        msFilesCDN = [
                "jquery-compat-VER.js", "jquery-compat-VER.min.js", "jquery-compat-VER.min.map"
-       ];
+       ],
+
+       rver = /VER/,
+       rcompat = /\-compat\./g;
 
 /**
  * Generates copies for the CDNs
  */
 function makeReleaseCopies( Release ) {
+       var version = Release.newVersion.replace( "-compat", "" );
        shell.mkdir( "-p", cdnFolder );
 
        Object.keys( releaseFiles ).forEach(function( key ) {
                var text,
                        builtFile = releaseFiles[ key ],
-                       unpathedFile = key.replace( /VER/g, Release.newVersion ),
+                       unpathedFile = key.replace( /VER/g, version ),
                        releaseFile = cdnFolder + "/" + unpathedFile;
 
                if ( /\.map$/.test( releaseFile ) ) {
@@ -55,52 +60,72 @@ function makeReleaseCopies( Release ) {
        });
 }
 
-function makeArchive( Release, cdn, files ) {
-       if ( Release.preRelease ) {
-               console.log( "Skipping archive creation for " + cdn + "; this is a beta release." );
-               return;
-       }
+function makeArchives( Release, callback ) {
 
-       console.log( "Creating production archive for " + cdn );
+       Release.chdir( Release.dir.repo );
 
-       var archiver = require( "archiver" )( "zip" ),
-               md5file = cdnFolder + "/" + cdn + "-md5.txt",
-               output = fs.createWriteStream(
-                       cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip"
-               );
+       var version = Release.newVersion.replace( "-compat", "" );
 
-       output.on( "error", function( err ) {
-               throw err;
-       });
+       function makeArchive( cdn, files, callback ) {
+               if ( Release.preRelease ) {
+                       console.log( "Skipping archive creation for " + cdn + "; this is a beta release." );
+                       callback();
+                       return;
+               }
 
-       archiver.pipe( output );
+               console.log( "Creating production archive for " + cdn );
 
-       files = files.map(function( item ) {
-               return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion );
-       });
+               var sum,
+                       archiver = require( "archiver" )( "zip" ),
+                       md5file = cdnFolder + "/" + cdn + "-md5.txt",
+                       output = fs.createWriteStream(
+                               cdnFolder + "/" + cdn + "-jquery-compat-" + version + ".zip"
+                       );
+
+               output.on( "close", callback );
+
+               output.on( "error", function( err ) {
+                       throw err;
+               });
+
+               archiver.pipe( output );
 
-       shell.exec( "md5sum", files, function( code, stdout ) {
-               fs.writeFileSync( md5file, stdout );
+               files = files.map(function( item ) {
+                       return "dist" + ( rver.test( item ) ? "/cdn" : "" ) + "/" +
+                               item.replace( rver, version );
+               });
+
+               sum = Release.exec(
+                       // Read jQuery files
+                       "md5sum " + files.join( " " ).replace( rcompat, "." ),
+                       "Error retrieving md5sum"
+               );
+               fs.writeFileSync( "./" + md5file, sum );
                files.push( md5file );
 
                files.forEach(function( file ) {
-                       archiver.append( fs.createReadStream( file ), { name: file } );
+                       // For Google, read jquery.js, write jquery-compat.js
+                       archiver.append( fs.createReadStream( file.replace( rcompat, "." ) ),
+                               { name: path.basename( file ) } );
                });
 
                archiver.finalize();
-       });
-}
+       }
 
-function buildGoogleCDN( Release ) {
-       makeArchive( Release, "googlecdn", googleFilesCDN );
-}
+       function buildGoogleCDN( callback ) {
+               makeArchive( "googlecdn", googleFilesCDN, callback );
+       }
 
-function buildMicrosoftCDN( Release ) {
-       makeArchive( Release, "mscdn", msFilesCDN );
+       function buildMicrosoftCDN( callback ) {
+               makeArchive( "mscdn", msFilesCDN, callback );
+       }
+
+       buildGoogleCDN(function() {
+               buildMicrosoftCDN( callback );
+       });
 }
 
 module.exports = {
        makeReleaseCopies: makeReleaseCopies,
-       buildGoogleCDN: buildGoogleCDN,
-       buildMicrosoftCDN: buildMicrosoftCDN
+       makeArchives: makeArchives
 };