aboutsummaryrefslogtreecommitdiffstats
path: root/build/release/dist.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/dist.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/dist.js')
-rw-r--r--build/release/dist.js307
1 files changed, 121 insertions, 186 deletions
diff --git a/build/release/dist.js b/build/release/dist.js
index 78dc5064f..5f1545b71 100644
--- a/build/release/dist.js
+++ b/build/release/dist.js
@@ -1,190 +1,125 @@
-"use strict";
-
-module.exports = function( Release, files, complete ) {
-
- const fs = require( "node:fs/promises" );
- const shell = require( "shelljs" );
- const inquirer = require( "inquirer" );
- const pkg = require( `${ Release.dir.repo }/package.json` );
- const distRemote = Release.remote
-
- // For local and github dists
- .replace( /jquery(\.git|$)/, "jquery-dist$1" );
-
- // These files are included with the distribution
- const extras = [
- "src",
- "LICENSE.txt",
- "AUTHORS.txt",
- "dist/package.json",
- "dist/jquery.bundler-require-wrapper.js",
- "dist/jquery.bundler-require-wrapper.slim.js",
- "dist-module/package.json",
- "dist-module/jquery.node-module-wrapper.js",
- "dist-module/jquery.node-module-wrapper.slim.js"
- ];
-
- /**
- * Clone the distribution repo
- */
- function clone() {
- Release.chdir( Release.dir.base );
- Release.dir.dist = `${ Release.dir.base }/dist`;
-
- console.log( "Using distribution repo: ", distRemote );
- Release.exec( `git clone ${ distRemote } ${ Release.dir.dist }`,
- "Error cloning repo." );
-
- // Distribution always works on main
- Release.chdir( Release.dir.dist );
- Release.exec( "git checkout main", "Error checking out branch." );
- console.log();
- }
-
- /**
- * Generate bower file for jquery-dist
- */
- function generateBower() {
- return JSON.stringify( {
+import { readFile, writeFile } from "node:fs/promises";
+import util from "node:util";
+import { argv } from "node:process";
+import { exec as nodeExec } from "node:child_process";
+import { rimraf } from "rimraf";
+
+const pkg = JSON.parse( await readFile( "./package.json", "utf8" ) );
+
+const exec = util.promisify( nodeExec );
+
+const version = argv[ 2 ];
+const blogURL = argv[ 3 ];
+
+if ( !version ) {
+ throw new Error( "No version specified" );
+}
+
+if ( !blogURL || !blogURL.startsWith( "https://blog.jquery.com/" ) ) {
+ throw new Error( "Invalid blog post URL" );
+}
+
+// The dist repo is cloned during release
+const distRepoFolder = "tmp/release/dist";
+
+// Files to be included in the dist repo.
+// README.md and bower.json are generated.
+const files = [
+ "dist",
+ "dist-module",
+ "src",
+ "LICENSE.txt",
+ "AUTHORS.txt",
+ "changelog.md"
+];
+
+async function generateBower() {
+ return JSON.stringify(
+ {
name: pkg.name,
main: pkg.main,
license: "MIT",
- ignore: [
- "package.json"
- ],
+ ignore: [ "package.json" ],
keywords: pkg.keywords
- }, null, 2 );
- }
-
- /**
- * Replace the version in the README
- * @param {string} readme
- * @param {string} blogPostLink
- */
- function editReadme( readme, blogPostLink ) {
- return readme
- .replace( /@VERSION/g, Release.newVersion )
- .replace( /@BLOG_POST_LINK/g, blogPostLink );
- }
-
- /**
- * Copy necessary files over to the dist repo
- */
- async function copy() {
- const readme = await fs.readFile(
- `${ Release.dir.repo }/build/fixtures/README.md`, "utf8" );
- const rmIgnore = [ ...files, "node_modules" ]
- .map( file => `${ Release.dir.dist }/${ file }` );
-
- shell.config.globOptions = {
- ignore: rmIgnore
- };
-
- const { blogPostLink } = await inquirer.prompt( [ {
- type: "input",
- name: "blogPostLink",
- message: "Enter URL of the blog post announcing the jQuery release...\n"
- } ] );
-
- // Remove extraneous files before copy
- shell.rm( "-rf", `${ Release.dir.dist }/**/*` );
-
- // Copy dist files
- shell.mkdir( "-p", `${ Release.dir.dist }/dist` );
- shell.mkdir( "-p", `${ Release.dir.dist }/dist-module` );
- files.forEach( function( file ) {
- shell.cp(
- "-f",
- `${ Release.dir.repo }/${ file }`,
- `${ Release.dir.dist }/${ file }`
- );
- } );
-
- // Copy other files
- extras.forEach( function( file ) {
- shell.cp(
- "-rf",
- `${ Release.dir.repo }/${ file }`,
- `${ Release.dir.dist }/${ file }`
- );
- } );
-
- // Remove the wrapper & the ESLint config from the dist repo
- shell.rm( "-f", `${ Release.dir.dist }/src/wrapper.js` );
- shell.rm( "-f", `${ Release.dir.dist }/src/.eslintrc.json` );
-
- // Write package.json
- // Remove scripts and other superfluous properties,
- // especially the prepare script, which fails on the dist repo
- const packageJson = Object.assign( {}, pkg );
- delete packageJson.scripts;
- delete packageJson.devDependencies;
- delete packageJson.dependencies;
- delete packageJson.commitplease;
- packageJson.version = Release.newVersion;
- await fs.writeFile(
- `${ Release.dir.dist }/package.json`,
- JSON.stringify( packageJson, null, 2 )
- );
-
- // Write generated bower file
- await fs.writeFile( `${ Release.dir.dist }/bower.json`, generateBower() );
-
- await fs.writeFile( `${ Release.dir.dist }/README.md`,
- editReadme( readme, blogPostLink ) );
-
- console.log( "Files ready to add." );
- }
-
- /**
- * Add, commit, and tag the dist files
- */
- function commit() {
- console.log( "Adding files to dist..." );
- Release.exec( "git add -A", "Error adding files." );
- Release.exec(
- `git commit -m "Release ${ Release.newVersion }"`,
- "Error committing files."
- );
- console.log();
-
- console.log( "Tagging release on dist..." );
- Release.exec( `git tag ${ Release.newVersion }`,
- `Error tagging ${ Release.newVersion } on dist repo.` );
- Release.tagTime = Release.exec( "git log -1 --format=\"%ad\"",
- "Error getting tag timestamp." ).trim();
- }
-
- /**
- * Push files to dist repo
- */
- function push() {
- Release.chdir( Release.dir.dist );
-
- console.log( "Pushing release to dist repo..." );
- Release.exec(
- `git push ${
- Release.isTest ? " --dry-run" : ""
- } ${ distRemote } main --tags`,
- "Error pushing main and tags to git repo."
- );
-
- // Set repo for npm publish
- Release.dir.origRepo = Release.dir.repo;
- Release.dir.repo = Release.dir.dist;
- }
-
- Release.walk( [
- Release._section( "Copy files to distribution repo" ),
- clone,
- copy,
- Release.confirmReview,
-
- Release._section( "Add, commit, and tag files in distribution repo" ),
- commit,
- Release.confirmReview,
-
- Release._section( "Pushing files to distribution repo" ),
- push
- ], complete );
-};
+ },
+ null,
+ 2
+ );
+}
+
+async function generateReadme() {
+ const readme = await readFile(
+ "./build/fixtures/README.md",
+ "utf8"
+ );
+
+ return readme
+ .replace( /@VERSION/g, version )
+ .replace( /@BLOG_POST_LINK/g, blogURL );
+}
+
+/**
+ * Copy necessary files over to the dist repo
+ */
+async function copyFiles() {
+
+ // Remove any extraneous files before copy
+ await rimraf( [
+ `${ distRepoFolder }/dist`,
+ `${ distRepoFolder }/dist-module`,
+ `${ distRepoFolder }/src`
+ ] );
+
+ // Copy all files
+ await Promise.all(
+ files.map( function( path ) {
+ console.log( `Copying ${ path }...` );
+ return exec( `cp -rf ${ path } ${ distRepoFolder }/${ path }` );
+ } )
+ );
+
+ // Remove the wrapper from the dist repo
+ await rimraf( [
+ `${ distRepoFolder }/src/wrapper.js`
+ ] );
+
+ // Set the version in src/core.js
+ const core = await readFile( `${ distRepoFolder }/src/core.js`, "utf8" );
+ await writeFile(
+ `${ distRepoFolder }/src/core.js`,
+ core.replace( /@VERSION/g, version )
+ );
+
+ // Write generated README
+ console.log( "Generating README.md..." );
+ const readme = await generateReadme();
+ await writeFile( `${ distRepoFolder }/README.md`, readme );
+
+ // Write generated Bower file
+ console.log( "Generating bower.json..." );
+ const bower = await generateBower();
+ await writeFile( `${ distRepoFolder }/bower.json`, bower );
+
+ // Write simplified package.json
+ console.log( "Writing package.json..." );
+ await writeFile(
+ `${ distRepoFolder }/package.json`,
+ JSON.stringify(
+ {
+ ...pkg,
+ scripts: undefined,
+ dependencies: undefined,
+ devDependencies: undefined,
+ commitplease: undefined
+ },
+ null,
+ 2
+
+ // Add final newline
+ ) + "\n"
+ );
+
+ console.log( "Files copied to dist repo." );
+}
+
+copyFiles();