2019-10-08 22:17:55 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-01-28 19:37:29 +00:00
|
|
|
var
|
|
|
|
fs = require( "fs" ),
|
|
|
|
shell = require( "shelljs" ),
|
2015-01-30 00:21:39 +00:00
|
|
|
path = require( "path" ),
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
|
|
cdnFolder = "dist/cdn",
|
|
|
|
|
|
|
|
releaseFiles = {
|
2015-11-12 18:18:59 +00:00
|
|
|
"jquery-VER.js": "dist/jquery.js",
|
|
|
|
"jquery-VER.min.js": "dist/jquery.min.js",
|
|
|
|
"jquery-VER.min.map": "dist/jquery.min.map",
|
|
|
|
"jquery-VER.slim.js": "dist/jquery.slim.js",
|
|
|
|
"jquery-VER.slim.min.js": "dist/jquery.slim.min.js",
|
|
|
|
"jquery-VER.slim.min.map": "dist/jquery.slim.min.map"
|
2015-01-28 19:37:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
googleFilesCDN = [
|
2015-11-12 18:18:59 +00:00
|
|
|
"jquery.js", "jquery.min.js", "jquery.min.map",
|
|
|
|
"jquery.slim.js", "jquery.slim.min.js", "jquery.slim.min.map"
|
2015-01-28 19:37:29 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
msFilesCDN = [
|
2015-11-12 18:18:59 +00:00
|
|
|
"jquery-VER.js", "jquery-VER.min.js", "jquery-VER.min.map",
|
|
|
|
"jquery-VER.slim.js", "jquery-VER.slim.min.js", "jquery-VER.slim.min.map"
|
2015-01-28 19:37:29 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates copies for the CDNs
|
|
|
|
*/
|
|
|
|
function makeReleaseCopies( Release ) {
|
|
|
|
shell.mkdir( "-p", cdnFolder );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
Object.keys( releaseFiles ).forEach( function( key ) {
|
2015-01-28 19:37:29 +00:00
|
|
|
var text,
|
|
|
|
builtFile = releaseFiles[ key ],
|
|
|
|
unpathedFile = key.replace( /VER/g, Release.newVersion ),
|
|
|
|
releaseFile = cdnFolder + "/" + unpathedFile;
|
|
|
|
|
|
|
|
if ( /\.map$/.test( releaseFile ) ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2015-01-28 19:37:29 +00:00
|
|
|
// Map files need to reference the new uncompressed name;
|
|
|
|
// assume that all files reside in the same directory.
|
2016-09-19 02:07:34 +00:00
|
|
|
// "file":"jquery.min.js" ... "sources":["jquery.js"]
|
2015-01-28 19:37:29 +00:00
|
|
|
text = fs.readFileSync( builtFile, "utf8" )
|
2016-09-19 02:07:34 +00:00
|
|
|
.replace( /"file":"([^"]+)"/,
|
|
|
|
"\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js\"" ) )
|
|
|
|
.replace( /"sources":\["([^"]+)"\]/,
|
|
|
|
"\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" );
|
2015-01-28 19:37:29 +00:00
|
|
|
fs.writeFileSync( releaseFile, text );
|
|
|
|
} else if ( builtFile !== releaseFile ) {
|
|
|
|
shell.cp( "-f", builtFile, releaseFile );
|
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2015-01-28 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 00:21:39 +00:00
|
|
|
function makeArchives( Release, callback ) {
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2015-01-30 00:21:39 +00:00
|
|
|
Release.chdir( Release.dir.repo );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2015-01-30 00:21:39 +00:00
|
|
|
function makeArchive( cdn, files, callback ) {
|
|
|
|
if ( Release.preRelease ) {
|
|
|
|
console.log( "Skipping archive creation for " + cdn + "; this is a beta release." );
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2015-01-30 00:21:39 +00:00
|
|
|
console.log( "Creating production archive for " + cdn );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2015-01-30 00:21:39 +00:00
|
|
|
var sum,
|
|
|
|
archiver = require( "archiver" )( "zip" ),
|
|
|
|
md5file = cdnFolder + "/" + cdn + "-md5.txt",
|
|
|
|
output = fs.createWriteStream(
|
|
|
|
cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip"
|
|
|
|
),
|
|
|
|
rver = /VER/;
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2015-01-30 00:21:39 +00:00
|
|
|
output.on( "close", callback );
|
|
|
|
|
|
|
|
output.on( "error", function( err ) {
|
|
|
|
throw err;
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2015-01-30 00:21:39 +00:00
|
|
|
|
|
|
|
archiver.pipe( output );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
files = files.map( function( item ) {
|
2015-01-30 00:21:39 +00:00
|
|
|
return "dist" + ( rver.test( item ) ? "/cdn" : "" ) + "/" +
|
|
|
|
item.replace( rver, Release.newVersion );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2017-03-16 18:59:57 +00:00
|
|
|
sum = Release.exec( "md5 -r " + files.join( " " ), "Error retrieving md5sum" );
|
2015-01-30 00:21:39 +00:00
|
|
|
fs.writeFileSync( md5file, sum );
|
2015-01-28 19:37:29 +00:00
|
|
|
files.push( md5file );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
files.forEach( function( file ) {
|
2015-01-30 00:21:39 +00:00
|
|
|
archiver.append( fs.createReadStream( file ),
|
|
|
|
{ name: path.basename( file ) } );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
|
|
archiver.finalize();
|
2015-01-30 00:21:39 +00:00
|
|
|
}
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2015-01-30 00:21:39 +00:00
|
|
|
function buildGoogleCDN( callback ) {
|
|
|
|
makeArchive( "googlecdn", googleFilesCDN, callback );
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildMicrosoftCDN( callback ) {
|
|
|
|
makeArchive( "mscdn", msFilesCDN, callback );
|
|
|
|
}
|
2015-01-28 19:37:29 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
buildGoogleCDN( function() {
|
2015-01-30 00:21:39 +00:00
|
|
|
buildMicrosoftCDN( callback );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2015-01-28 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
makeReleaseCopies: makeReleaseCopies,
|
2015-01-30 00:21:39 +00:00
|
|
|
makeArchives: makeArchives
|
2015-01-28 19:37:29 +00:00
|
|
|
};
|