aboutsummaryrefslogtreecommitdiffstats
path: root/build/release/cdn.js
diff options
context:
space:
mode:
authorTimmy Willison <timmywil@users.noreply.github.com>2023-07-27 11:24:49 -0400
committerTimmy Willison <timmywil@users.noreply.github.com>2024-07-11 10:00:56 -0400
commit2646a8b07fcc2cf7cf384724f622eb0c27f9166c (patch)
tree3367ad18d492486a692bb4a7a23b216ba155451f /build/release/cdn.js
parent3a98ef91dfa0b4897df7562f40bfd1715f5fc30e (diff)
downloadjquery-2646a8b07fcc2cf7cf384724f622eb0c27f9166c.tar.gz
jquery-2646a8b07fcc2cf7cf384724f622eb0c27f9166c.zip
Release: migrate release process to release-it
*Authors* - Checking and updating authors has been migrated to a custom script in the repo *Changelog* - changelogplease is no longer maintained - generate changelog in markdown for GitHub releases - generate changelog in HTML for blog posts - generate contributors list in HTML for blog posts *dist* - clone dist repo, copy files, and commit/push - commit tag with dist files on main branch; remove dist files from main branch after release *cdn* - clone cdn repo, copy files, and commit/push - create versioned and unversioned copies in cdn/ - generate md5 sums and archives for Google and MSFT *build* - implement reproducible builds and verify release builds * uses the last modified date for the latest commit * See https://reproducible-builds.org/ - the verify workflow also ensures all files were properly published to the CDN and npm *docs* - the new release workflow is documented at build/release/README.md *misc* - now that we don't need the jquery-release script and now that we no longer need to build on Node 10, we can use ESM in all files in the build folder - move dist wrappers to "wrappers" folders for easy removal of all built files - limit certain workflows to the main repo (not forks) - version in package.json has been set to beta.1 so that the next release will be beta.2 - release-it added the `preReleaseBase` option and we now always set it to `1` in the npm script. This is a noop for stable releases. Fixes jquery/jquery-release#114 Closes gh-5512
Diffstat (limited to 'build/release/cdn.js')
-rw-r--r--build/release/cdn.js283
1 files changed, 119 insertions, 164 deletions
diff --git a/build/release/cdn.js b/build/release/cdn.js
index 610299661..7d9492623 100644
--- a/build/release/cdn.js
+++ b/build/release/cdn.js
@@ -1,175 +1,130 @@
-"use strict";
-
-const fs = require( "node:fs" );
-const shell = require( "shelljs" );
-const path = require( "node:path" );
-const os = require( "node: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 ) {
- [
- { 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 );
- }
- } );
- } );
+import { mkdir, readFile, writeFile } from "node:fs/promises";
+import path from "node:path";
+import { argv } from "node:process";
+import util from "node:util";
+import { exec as nodeExec } from "node:child_process";
+import { rimraf } from "rimraf";
+import archive from "./archive.js";
+
+const exec = util.promisify( nodeExec );
+
+const version = argv[ 2 ];
+
+if ( !version ) {
+ throw new Error( "No version specified" );
}
-async function makeArchives( Release ) {
- Release.chdir( Release.dir.repo );
-
- 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 );
-
- 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"
- );
- const rmd5 = /[a-f0-9]{32}/;
- const rver = /@VER/;
+const archivesFolder = "tmp/archives";
+const versionedFolder = `${ archivesFolder }/versioned`;
+const unversionedFolder = `${ archivesFolder }/unversioned`;
- output.on( "close", resolve );
+// The cdn repo is cloned during release
+const cdnRepoFolder = "tmp/release/cdn";
- output.on( "error", ( err ) => {
- reject( err );
- } );
+// .min.js and .min.map files are expected
+// in the same directory as the uncompressed files.
+const sources = [
+ "dist/jquery.js",
+ "dist/jquery.slim.js",
+ "dist-module/jquery.module.js",
+ "dist-module/jquery.slim.module.js"
+];
- archiver.pipe( output );
+const rminmap = /\.min\.map$/;
+const rjs = /\.js$/;
- let finalFilesMap = Object.create( null );
- for ( const [ releaseFile, builtFile ] of Object.entries( filesMap ) ) {
- finalFilesMap[ releaseFile.replace( rver, Release.newVersion ) ] =
- builtFile;
- }
+function clean() {
+ console.log( "Cleaning any existing archives..." );
+ return rimraf( archivesFolder );
+}
+
+// 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"]
+// This is only necessary for the versioned files.
+async function convertMapToVersioned( file, folder ) {
+ const mapFile = file.replace( /\.js$/, ".min.map" );
+ const filename = path
+ .basename( mapFile )
+ .replace( "jquery", "jquery-" + version );
+
+ const contents = JSON.parse( await readFile( mapFile, "utf8" ) );
+
+ return writeFile(
+ path.join( folder, filename ),
+ JSON.stringify( {
+ ...contents,
+ file: filename.replace( rminmap, ".min.js" ),
+ sources: [ filename.replace( rminmap, ".js" ) ]
+ } )
+ );
+}
+
+async function makeUnversionedCopies() {
+ await mkdir( unversionedFolder, { recursive: true } );
+
+ return Promise.all(
+ sources.map( async( file ) => {
+ const filename = path.basename( file );
+ const minFilename = filename.replace( rjs, ".min.js" );
+ const mapFilename = filename.replace( rjs, ".min.map" );
+
+ await exec( `cp -f ${ file } ${ unversionedFolder }/${ filename }` );
+ await exec(
+ `cp -f ${ file.replace(
+ rjs,
+ ".min.js"
+ ) } ${ unversionedFolder }/${ minFilename }`
+ );
+ await exec(
+ `cp -f ${ file.replace(
+ rjs,
+ ".min.map"
+ ) } ${ unversionedFolder }/${ mapFilename }`
+ );
+ } )
+ );
+}
- const files = Object.keys( filesMap ).map(
- ( item ) => `${ cdnFolder }/${ item.replace( rver, Release.newVersion ) }`
+async function makeVersionedCopies() {
+ await mkdir( versionedFolder, { recursive: true } );
+
+ return Promise.all(
+ sources.map( async( file ) => {
+ const filename = path
+ .basename( file )
+ .replace( "jquery", "jquery-" + version );
+ const minFilename = filename.replace( rjs, ".min.js" );
+
+ await exec( `cp -f ${ file } ${ versionedFolder }/${ filename }` );
+ await exec(
+ `cp -f ${ file.replace(
+ rjs,
+ ".min.js"
+ ) } ${ versionedFolder }/${ minFilename }`
);
+ await convertMapToVersioned( file, versionedFolder );
+ } )
+ );
+}
+
+async function copyToRepo( folder ) {
+ return exec( `cp -f ${ folder }/* ${ cdnRepoFolder }/cdn/` );
+}
+
+async function cdn() {
+ await clean();
+
+ await Promise.all( [ makeUnversionedCopies(), makeVersionedCopies() ] );
+
+ await copyToRepo( versionedFolder );
+
+ await Promise.all( [
+ archive( { cdn: "googlecdn", folder: unversionedFolder, version } ),
+ archive( { cdn: "mscdn", folder: versionedFolder, version } )
+ ] );
- 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"
- );
- }
- fs.writeFileSync( md5file, sum );
- files.push( md5file );
-
- files.forEach( ( file ) => {
- archiver.append( fs.createReadStream( file ), {
- name: path.basename( file )
- } );
- } );
-
- archiver.finalize();
- } );
- }
-
- async function buildGoogleCDN() {
- await makeArchive( {
- cdn: "googlecdn",
- filesMap: unversionedReleaseFiles,
- cdnFolder: cdnFolderUnversioned
- } );
- }
-
- async function buildMicrosoftCDN() {
- await makeArchive( {
- cdn: "mscdn",
- filesMap: versionedReleaseFiles,
- cdnFolder: cdnFolderVersioned
- } );
- }
-
- await buildGoogleCDN();
- await buildMicrosoftCDN();
+ console.log( "Files ready for CDNs." );
}
-module.exports = {
- makeReleaseCopies: makeReleaseCopies,
- makeArchives: makeArchives
-};
+cdn();