aboutsummaryrefslogtreecommitdiffstats
path: root/build/release
diff options
context:
space:
mode:
authorTimmy Willison <timmywil@users.noreply.github.com>2024-01-22 21:08:16 -0500
committerGitHub <noreply@github.com>2024-01-22 21:08:16 -0500
commitaf79c99939628255f46f30bced000eba9aa6711f (patch)
tree36ef0140b1d5f2c27fe784906d049527123b316a /build/release
parent88690ebfc8b5ef8b1e444326c664b590ecc0b888 (diff)
downloadjquery-af79c99939628255f46f30bced000eba9aa6711f.tar.gz
jquery-af79c99939628255f46f30bced000eba9aa6711f.zip
Build: migrate grunt authors to a custom script
- the new script pulls all authors from the Sizzle repo - added temporary grunt task for releases Close gh-5395
Diffstat (limited to 'build/release')
-rw-r--r--build/release/authors.js105
1 files changed, 105 insertions, 0 deletions
diff --git a/build/release/authors.js b/build/release/authors.js
new file mode 100644
index 000000000..9ecd9f642
--- /dev/null
+++ b/build/release/authors.js
@@ -0,0 +1,105 @@
+"use strict";
+
+const fs = require( "node:fs" );
+const util = require( "node:util" );
+const exec = util.promisify( require( "node:child_process" ).exec );
+const rnewline = /\r?\n/;
+const rdate = /^\[(\d+)\] /;
+
+const ignore = [
+ /dependabot\[bot\]/
+];
+
+function compareAuthors( a, b ) {
+ const aName = a.replace( rdate, "" ).replace( / <.*>/, "" );
+ const bName = b.replace( rdate, "" ).replace( / <.*>/, "" );
+ return aName === bName;
+}
+
+function uniq( arr ) {
+ const unique = [];
+ for ( const item of arr ) {
+ if ( ignore.some( re => re.test( item ) ) ) {
+ continue;
+ }
+ if ( item && !unique.find( ( e ) => compareAuthors( e, item ) ) ) {
+ unique.push( item );
+ }
+ }
+ return unique;
+}
+
+function cleanupSizzle() {
+ console.log( "Cleaning up..." );
+ return exec( "npx rimraf .sizzle" );
+}
+
+function cloneSizzle() {
+ console.log( "Cloning Sizzle..." );
+ return exec( "git clone https://github.com/jquery/sizzle .sizzle" );
+}
+
+async function getLastAuthor() {
+ const authorsTxt = await fs.promises.readFile( "AUTHORS.txt", "utf8" );
+ return authorsTxt.trim().split( rnewline ).pop();
+}
+
+async function logAuthors( preCommand ) {
+ let command = "git log --pretty=format:\"[%at] %aN <%aE>\"";
+ if ( preCommand ) {
+ command = `${ preCommand } && ${ command }`;
+ }
+ const { stdout } = await exec( command );
+ return uniq( stdout.trim().split( rnewline ).reverse() );
+}
+
+async function getSizzleAuthors() {
+ await cloneSizzle();
+ const authors = await logAuthors( "cd .sizzle" );
+ await cleanupSizzle();
+ return authors;
+}
+
+function sortAuthors( a, b ) {
+ const [ , aDate ] = rdate.exec( a );
+ const [ , bDate ] = rdate.exec( b );
+ return Number( aDate ) - Number( bDate );
+}
+
+function formatAuthor( author ) {
+ return author.replace( rdate, "" );
+}
+
+async function getAuthors() {
+ console.log( "Getting authors..." );
+ const authors = await logAuthors();
+ const sizzleAuthors = await getSizzleAuthors();
+ return uniq( authors.concat( sizzleAuthors ) ).sort( sortAuthors ).map( formatAuthor );
+}
+
+async function checkAuthors() {
+ const authors = await getAuthors();
+ const lastAuthor = await getLastAuthor();
+
+ if ( authors[ authors.length - 1 ] !== lastAuthor ) {
+ console.log( "AUTHORS.txt: ", lastAuthor );
+ console.log( "Last 20 in git: ", authors.slice( -20 ) );
+ throw new Error( "Last author in AUTHORS.txt does not match last git author" );
+ }
+ console.log( "AUTHORS.txt is up to date" );
+}
+
+async function updateAuthors() {
+ const authors = await getAuthors();
+
+ const authorsTxt = "Authors ordered by first contribution.\n\n" + authors.join( "\n" ) + "\n";
+ await fs.promises.writeFile( "AUTHORS.txt", authorsTxt );
+
+ console.log( "AUTHORS.txt updated" );
+}
+
+module.exports = {
+ checkAuthors,
+ getAuthors,
+ updateAuthors
+};