jquery/build/release/dist.js

127 lines
2.7 KiB
JavaScript
Raw Normal View History

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
2023-07-27 15:24:49 +00:00
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.
// package.json is a simplified version of the original.
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
2023-07-27 15:24:49 +00:00
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",
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
2023-07-27 15:24:49 +00:00
ignore: [ "package.json" ],
keywords: pkg.keywords
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
2023-07-27 15:24:49 +00:00
},
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();