3 module.exports = function( Release, files, complete ) {
5 const fs = require( "node:fs/promises" );
6 const shell = require( "shelljs" );
7 const inquirer = require( "inquirer" );
8 const pkg = require( `${ Release.dir.repo }/package.json` );
9 const distRemote = Release.remote
11 // For local and github dists
12 .replace( /jquery(\.git|$)/, "jquery-dist$1" );
14 // These files are included with the distribution
20 "dist/jquery.bundler-require-wrapper.js",
21 "dist/jquery.bundler-require-wrapper.slim.js",
22 "dist-module/package.json",
23 "dist-module/jquery.node-module-wrapper.js",
24 "dist-module/jquery.node-module-wrapper.slim.js"
28 * Clone the distribution repo
31 Release.chdir( Release.dir.base );
32 Release.dir.dist = `${ Release.dir.base }/dist`;
34 console.log( "Using distribution repo: ", distRemote );
35 Release.exec( `git clone ${ distRemote } ${ Release.dir.dist }`,
36 "Error cloning repo." );
38 // Distribution always works on main
39 Release.chdir( Release.dir.dist );
40 Release.exec( "git checkout main", "Error checking out branch." );
45 * Generate bower file for jquery-dist
47 function generateBower() {
48 return JSON.stringify( {
55 keywords: pkg.keywords
60 * Replace the version in the README
61 * @param {string} readme
62 * @param {string} blogPostLink
64 function editReadme( readme, blogPostLink ) {
66 .replace( /@VERSION/g, Release.newVersion )
67 .replace( /@BLOG_POST_LINK/g, blogPostLink );
71 * Copy necessary files over to the dist repo
73 async function copy() {
74 const readme = await fs.readFile(
75 `${ Release.dir.repo }/build/fixtures/README.md`, "utf8" );
76 const rmIgnore = [ ...files, "node_modules" ]
77 .map( file => `${ Release.dir.dist }/${ file }` );
79 shell.config.globOptions = {
83 const { blogPostLink } = await inquirer.prompt( [ {
86 message: "Enter URL of the blog post announcing the jQuery release...\n"
89 // Remove extraneous files before copy
90 shell.rm( "-rf", `${ Release.dir.dist }/**/*` );
93 shell.mkdir( "-p", `${ Release.dir.dist }/dist` );
94 shell.mkdir( "-p", `${ Release.dir.dist }/dist-module` );
95 files.forEach( function( file ) {
98 `${ Release.dir.repo }/${ file }`,
99 `${ Release.dir.dist }/${ file }`
104 extras.forEach( function( file ) {
107 `${ Release.dir.repo }/${ file }`,
108 `${ Release.dir.dist }/${ file }`
112 // Remove the wrapper & the ESLint config from the dist repo
113 shell.rm( "-f", `${ Release.dir.dist }/src/wrapper.js` );
114 shell.rm( "-f", `${ Release.dir.dist }/src/.eslintrc.json` );
116 // Write package.json
117 // Remove scripts and other superfluous properties,
118 // especially the prepare script, which fails on the dist repo
119 const packageJson = Object.assign( {}, pkg );
120 delete packageJson.scripts;
121 delete packageJson.devDependencies;
122 delete packageJson.dependencies;
123 delete packageJson.commitplease;
124 packageJson.version = Release.newVersion;
126 `${ Release.dir.dist }/package.json`,
127 JSON.stringify( packageJson, null, 2 )
130 // Write generated bower file
131 await fs.writeFile( `${ Release.dir.dist }/bower.json`, generateBower() );
133 await fs.writeFile( `${ Release.dir.dist }/README.md`,
134 editReadme( readme, blogPostLink ) );
136 console.log( "Files ready to add." );
140 * Add, commit, and tag the dist files
143 console.log( "Adding files to dist..." );
144 Release.exec( "git add -A", "Error adding files." );
146 `git commit -m "Release ${ Release.newVersion }"`,
147 "Error committing files."
151 console.log( "Tagging release on dist..." );
152 Release.exec( `git tag ${ Release.newVersion }`,
153 `Error tagging ${ Release.newVersion } on dist repo.` );
154 Release.tagTime = Release.exec( "git log -1 --format=\"%ad\"",
155 "Error getting tag timestamp." ).trim();
159 * Push files to dist repo
162 Release.chdir( Release.dir.dist );
164 console.log( "Pushing release to dist repo..." );
167 Release.isTest ? " --dry-run" : ""
168 } ${ distRemote } main --tags`,
169 "Error pushing main and tags to git repo."
172 // Set repo for npm publish
173 Release.dir.origRepo = Release.dir.repo;
174 Release.dir.repo = Release.dir.dist;
178 Release._section( "Copy files to distribution repo" ),
181 Release.confirmReview,
183 Release._section( "Add, commit, and tag files in distribution repo" ),
185 Release.confirmReview,
187 Release._section( "Pushing files to distribution repo" ),