Event: Increase robustness of an inner native event in leverageNative
[jquery.git] / build / release / authors.js
blobbf72b8af76e657b6bf2bc0efabe684e6962b175c
1 "use strict";
3 const fs = require( "node:fs/promises" );
4 const util = require( "node:util" );
5 const exec = util.promisify( require( "node:child_process" ).exec );
6 const rnewline = /\r?\n/;
7 const rdate = /^\[(\d+)\] /;
9 const ignore = [
10         /dependabot\[bot\]/
13 function compareAuthors( a, b ) {
14         const aName = a.replace( rdate, "" ).replace( / <.*>/, "" );
15         const bName = b.replace( rdate, "" ).replace( / <.*>/, "" );
16         return aName === bName;
19 function uniq( arr ) {
20         const unique = [];
21         for ( const item of arr ) {
22                 if ( ignore.some( re => re.test( item ) ) ) {
23                         continue;
24                 }
25                 if ( item && !unique.find( ( e ) => compareAuthors( e, item ) ) ) {
26                         unique.push( item );
27                 }
28         }
29         return unique;
32 function cleanupSizzle() {
33         console.log( "Cleaning up..." );
34         return exec( "npx rimraf .sizzle" );
37 function cloneSizzle() {
38         console.log( "Cloning Sizzle..." );
39         return exec( "git clone https://github.com/jquery/sizzle .sizzle" );
42 async function getLastAuthor() {
43         const authorsTxt = await fs.readFile( "AUTHORS.txt", "utf8" );
44         return authorsTxt.trim().split( rnewline ).pop();
47 async function logAuthors( preCommand ) {
48         let command = "git log --pretty=format:\"[%at] %aN <%aE>\"";
49         if ( preCommand ) {
50                 command = `${ preCommand } && ${ command }`;
51         }
52         const { stdout } = await exec( command );
53         return uniq( stdout.trim().split( rnewline ).reverse() );
56 async function getSizzleAuthors() {
57         await cloneSizzle();
58         const authors = await logAuthors( "cd .sizzle" );
59         await cleanupSizzle();
60         return authors;
63 function sortAuthors( a, b ) {
64         const [ , aDate ] = rdate.exec( a );
65         const [ , bDate ] = rdate.exec( b );
66         return Number( aDate ) - Number( bDate );
69 function formatAuthor( author ) {
70         return author.replace( rdate, "" );
73 async function getAuthors() {
74         console.log( "Getting authors..." );
75         const authors = await logAuthors();
76         const sizzleAuthors = await getSizzleAuthors();
77         return uniq( authors.concat( sizzleAuthors ) ).sort( sortAuthors ).map( formatAuthor );
80 async function checkAuthors() {
81         const authors = await getAuthors();
82         const lastAuthor = await getLastAuthor();
84         if ( authors[ authors.length - 1 ] !== lastAuthor ) {
85                 console.log( "AUTHORS.txt: ", lastAuthor );
86                 console.log( "Last 20 in git: ", authors.slice( -20 ) );
87                 throw new Error( "Last author in AUTHORS.txt does not match last git author" );
88         }
89         console.log( "AUTHORS.txt is up to date" );
92 async function updateAuthors() {
93         const authors = await getAuthors();
95         const authorsTxt = "Authors ordered by first contribution.\n\n" + authors.join( "\n" ) + "\n";
96         await fs.writeFile( "AUTHORS.txt", authorsTxt );
98         console.log( "AUTHORS.txt updated" );
101 module.exports = {
102         checkAuthors,
103         getAuthors,
104         updateAuthors