diff options
Diffstat (limited to 'build/release/cdn.js')
-rw-r--r-- | build/release/cdn.js | 229 |
1 files changed, 131 insertions, 98 deletions
diff --git a/build/release/cdn.js b/build/release/cdn.js index 0cbea4a7a..a75ad7303 100644 --- a/build/release/cdn.js +++ b/build/release/cdn.js @@ -1,130 +1,163 @@ "use strict"; -var - fs = require( "fs" ), - shell = require( "shelljs" ), - path = require( "path" ), - os = require( "os" ), - - cdnFolder = "dist/cdn", - - releaseFiles = { - "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" - }, - - googleFilesCDN = [ - "jquery.js", "jquery.min.js", "jquery.min.map", - "jquery.slim.js", "jquery.slim.min.js", "jquery.slim.min.map" - ], - - msFilesCDN = [ - "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" - ]; +const fs = require( "fs" ); +const shell = require( "shelljs" ); +const path = require( "path" ); +const os = require( "os" ); + +const cdnFolderContainer = "dist/cdn"; +const cdnFolderVersioned = `${ cdnFolderContainer }/versioned`; +const cdnFolderUnversioned = `${ cdnFolderContainer }/unversioned`; + +const versionedReleaseFiles = { + "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", + "jquery-@VER.module.js": "dist-module/jquery.module.js", + "jquery-@VER.module.min.js": "dist-module/jquery.module.min.js", + "jquery-@VER.module.min.map": "dist-module/jquery.module.min.map", + "jquery-@VER.slim.module.js": "dist-module/jquery.slim.module.js", + "jquery-@VER.slim.module.min.js": "dist-module/jquery.slim.module.min.js", + "jquery-@VER.slim.module.min.map": "dist-module/jquery.slim.module.min.map" +}; + +const unversionedReleaseFiles = { + "jquery.js": "dist/jquery.js", + "jquery.min.js": "dist/jquery.min.js", + "jquery.min.map": "dist/jquery.min.map", + "jquery.slim.js": "dist/jquery.slim.js", + "jquery.slim.min.js": "dist/jquery.slim.min.js", + "jquery.slim.min.map": "dist/jquery.slim.min.map", + "jquery.module.js": "dist-module/jquery.module.js", + "jquery.module.min.js": "dist-module/jquery.module.min.js", + "jquery.module.min.map": "dist-module/jquery.module.min.map", + "jquery.slim.module.js": "dist-module/jquery.slim.module.js", + "jquery.slim.module.min.js": "dist-module/jquery.slim.module.min.js", + "jquery.slim.module.min.map": "dist-module/jquery.slim.module.min.map" +}; /** * Generates copies for the CDNs */ function makeReleaseCopies( Release ) { - shell.mkdir( "-p", cdnFolder ); - - Object.keys( releaseFiles ).forEach( function( key ) { - var text, - builtFile = releaseFiles[ key ], - unpathedFile = key.replace( /VER/g, Release.newVersion ), - releaseFile = cdnFolder + "/" + unpathedFile; - - if ( /\.map$/.test( releaseFile ) ) { - - // Map files need to reference the new uncompressed name; - // assume that all files reside in the same directory. - // "file":"jquery.min.js" ... "sources":["jquery.js"] - text = fs.readFileSync( builtFile, "utf8" ) - .replace( /"file":"([^"]+)"/, - "\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js\"" ) ) - .replace( /"sources":\["([^"]+)"\]/, - "\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" ); - fs.writeFileSync( releaseFile, text ); - } else if ( builtFile !== releaseFile ) { - shell.cp( "-f", builtFile, releaseFile ); - } + [ + { filesMap: versionedReleaseFiles, cdnFolder: cdnFolderVersioned }, + { filesMap: unversionedReleaseFiles, cdnFolder: cdnFolderUnversioned } + ].forEach( ( { filesMap, cdnFolder } ) => { + shell.mkdir( "-p", cdnFolder ); + + Object.keys( filesMap ).forEach( key => { + let text; + const builtFile = filesMap[ key ]; + const unpathedFile = key.replace( /@VER/g, Release.newVersion ); + const releaseFile = cdnFolder + "/" + unpathedFile; + + if ( /\.map$/.test( releaseFile ) ) { + + // Map files need to reference the new uncompressed name; + // assume that all files reside in the same directory. + // "file":"jquery.min.js" ... "sources":["jquery.js"] + text = fs.readFileSync( builtFile, "utf8" ) + .replace( /"file":"([^"]+)"/, + "\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js\"" ) ) + .replace( /"sources":\["([^"]+)"\]/, + "\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" ); + fs.writeFileSync( releaseFile, text ); + } else if ( builtFile !== releaseFile ) { + shell.cp( "-f", builtFile, releaseFile ); + } + } ); + } ); } -function makeArchives( Release, callback ) { +async function makeArchives( Release ) { Release.chdir( Release.dir.repo ); - function makeArchive( cdn, files, callback ) { - if ( Release.preRelease ) { - console.log( "Skipping archive creation for " + cdn + "; this is a beta release." ); - callback(); - return; - } + async function makeArchive( { cdn, filesMap, cdnFolder } ) { + return new Promise( ( resolve, reject ) => { + if ( Release.preRelease ) { + console.log( "Skipping archive creation for " + cdn + "; this is a beta release." ); + resolve(); + return; + } - console.log( "Creating production archive for " + cdn ); + console.log( "Creating production archive for " + cdn ); - var i, sum, result, - archiver = require( "archiver" )( "zip" ), - md5file = cdnFolder + "/" + cdn + "-md5.txt", - output = fs.createWriteStream( + let i, sum, result; + const archiver = require( "archiver" )( "zip" ); + const md5file = cdnFolder + "/" + cdn + "-md5.txt"; + const output = fs.createWriteStream( cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip" - ), - rmd5 = /[a-f0-9]{32}/, - rver = /VER/; + ); + const rmd5 = /[a-f0-9]{32}/; + const rver = /@VER/; - output.on( "close", callback ); + output.on( "close", resolve ); - output.on( "error", function( err ) { - throw err; - } ); + output.on( "error", err => { + reject( err ); + } ); - archiver.pipe( output ); + archiver.pipe( output ); - files = files.map( function( item ) { - return "dist" + ( rver.test( item ) ? "/cdn" : "" ) + "/" + - item.replace( rver, Release.newVersion ); - } ); + let finalFilesMap = Object.create( null ); + for ( const [ releaseFile, builtFile ] of Object.entries( filesMap ) ) { + finalFilesMap[ releaseFile.replace( rver, Release.newVersion ) ] = builtFile; + } - if ( os.platform() === "win32" ) { - sum = []; - for ( i = 0; i < files.length; i++ ) { - result = Release.exec( - "certutil -hashfile " + files[ i ] + " MD5", "Error retrieving md5sum" - ); - sum.push( rmd5.exec( result )[ 0 ] + " " + files[ i ] ); + const files = Object + .keys( filesMap ) + .map( item => `${ cdnFolder }/${ + item.replace( rver, Release.newVersion ) + }` ); + + if ( os.platform() === "win32" ) { + sum = []; + for ( i = 0; i < files.length; i++ ) { + result = Release.exec( + "certutil -hashfile " + files[ i ] + " MD5", "Error retrieving md5sum" + ); + sum.push( rmd5.exec( result )[ 0 ] + " " + files[ i ] ); + } + sum = sum.join( "\n" ); + } else { + sum = Release.exec( "md5 -r " + files.join( " " ), "Error retrieving md5sum" ); } - sum = sum.join( "\n" ); - } else { - sum = Release.exec( "md5 -r " + files.join( " " ), "Error retrieving md5sum" ); - } - fs.writeFileSync( md5file, sum ); - files.push( md5file ); - - files.forEach( function( file ) { - archiver.append( fs.createReadStream( file ), - { name: path.basename( file ) } ); - } ); + fs.writeFileSync( md5file, sum ); + files.push( md5file ); + + files.forEach( file => { + archiver.append( fs.createReadStream( file ), + { name: path.basename( file ) } ); + } ); - archiver.finalize(); + archiver.finalize(); + } ); } - function buildGoogleCDN( callback ) { - makeArchive( "googlecdn", googleFilesCDN, callback ); + async function buildGoogleCDN() { + await makeArchive( { + cdn: "googlecdn", + filesMap: unversionedReleaseFiles, + cdnFolder: cdnFolderUnversioned + } ); } - function buildMicrosoftCDN( callback ) { - makeArchive( "mscdn", msFilesCDN, callback ); + async function buildMicrosoftCDN() { + await makeArchive( { + cdn: "mscdn", + filesMap: versionedReleaseFiles, + cdnFolder: cdnFolderVersioned + } ); } - buildGoogleCDN( function() { - buildMicrosoftCDN( callback ); - } ); + await buildGoogleCDN(); + await buildMicrosoftCDN(); } module.exports = { |