3 module.exports = function( Release, files, complete ) {
5 const fs = require( "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-module/package.json",
21 "dist-module/jquery.node-module-wrapper.js",
22 "dist-module/jquery.node-module-wrapper.slim.js"
26 * Clone the distribution repo
29 Release.chdir( Release.dir.base );
30 Release.dir.dist = `${ Release.dir.base }/dist`;
32 console.log( "Using distribution repo: ", distRemote );
33 Release.exec( `git clone ${ distRemote } ${ Release.dir.dist }`,
34 "Error cloning repo." );
36 // Distribution always works on main
37 Release.chdir( Release.dir.dist );
38 Release.exec( "git checkout main", "Error checking out branch." );
43 * Generate bower file for jquery-dist
45 function generateBower() {
46 return JSON.stringify( {
53 keywords: pkg.keywords
58 * Replace the version in the README
59 * @param {string} readme
60 * @param {string} blogPostLink
62 function editReadme( readme, blogPostLink ) {
64 .replace( /@VERSION/g, Release.newVersion )
65 .replace( /@BLOG_POST_LINK/g, blogPostLink );
69 * Copy necessary files over to the dist repo
71 async function copy() {
72 const readme = await fs.readFile(
73 `${ Release.dir.repo }/build/fixtures/README.md`, "utf8" );
74 const rmIgnore = [ ...files, "node_modules" ]
75 .map( file => `${ Release.dir.dist }/${ file }` );
77 shell.config.globOptions = {
81 const { blogPostLink } = await inquirer.prompt( [ {
84 message: "Enter URL of the blog post announcing the jQuery release...\n"
87 // Remove extraneous files before copy
88 shell.rm( "-rf", `${ Release.dir.dist }/**/*` );
91 shell.mkdir( "-p", `${ Release.dir.dist }/dist` );
92 shell.mkdir( "-p", `${ Release.dir.dist }/dist-module` );
93 files.forEach( function( file ) {
96 `${ Release.dir.repo }/${ file }`,
97 `${ Release.dir.dist }/${ file }`
102 extras.forEach( function( file ) {
105 `${ Release.dir.repo }/${ file }`,
106 `${ Release.dir.dist }/${ file }`
110 // Remove the wrapper & the ESLint config from the dist repo
111 shell.rm( "-f", `${ Release.dir.dist }/src/wrapper.js` );
112 shell.rm( "-f", `${ Release.dir.dist }/src/.eslintrc.json` );
114 // Write package.json
115 // Remove scripts and other superfluous properties,
116 // especially the prepare script, which fails on the dist repo
117 const packageJson = Object.assign( {}, pkg );
118 delete packageJson.scripts;
119 delete packageJson.devDependencies;
120 delete packageJson.dependencies;
121 delete packageJson.commitplease;
123 `${ Release.dir.dist }/package.json`,
124 JSON.stringify( packageJson, null, 2 )
127 // Write generated bower file
128 await fs.writeFile( `${ Release.dir.dist }/bower.json`, generateBower() );
130 await fs.writeFile( `${ Release.dir.dist }/README.md`,
131 editReadme( readme, blogPostLink ) );
133 console.log( "Files ready to add." );
137 * Add, commit, and tag the dist files
140 console.log( "Adding files to dist..." );
141 Release.exec( "git add -A", "Error adding files." );
143 `git commit -m "Release ${ Release.newVersion }"`,
144 "Error committing files."
148 console.log( "Tagging release on dist..." );
149 Release.exec( `git tag ${ Release.newVersion }`,
150 `Error tagging ${ Release.newVersion } on dist repo.` );
151 Release.tagTime = Release.exec( "git log -1 --format=\"%ad\"",
152 "Error getting tag timestamp." ).trim();
156 * Push files to dist repo
159 Release.chdir( Release.dir.dist );
161 console.log( "Pushing release to dist repo..." );
164 Release.isTest ? " --dry-run" : ""
165 } ${ distRemote } main --tags`,
166 "Error pushing main and tags to git repo."
169 // Set repo for npm publish
170 Release.dir.origRepo = Release.dir.repo;
171 Release.dir.repo = Release.dir.dist;
175 Release._section( "Copy files to distribution repo" ),
178 Release.confirmReview,
180 Release._section( "Add, commit, and tag files in distribution repo" ),
182 Release.confirmReview,
184 Release._section( "Pushing files to distribution repo" ),