1- 'use script' ;
1+ import fs from 'node:fs' ;
2+ import path from 'node:path' ;
23
3- const fs = require ( 'fs' ) ;
4- const path = require ( 'path' ) ;
5-
6- const simpleGit = require ( 'simple-git' ) ;
4+ import simpleGit from 'simple-git' ;
75
86const maxCommitsInChangelog = 400 ;
97
@@ -23,7 +21,6 @@ const formatDateString = (dateString) => {
2321 */
2422class Formatter {
2523 static logCommit ( previousCommit , commit , gitdiff ) {
26-
2724 // Don't log commits that don't change the protocol.
2825 if ( ! gitdiff || ! gitdiff . length ) return ;
2926
@@ -34,11 +31,15 @@ class Formatter {
3431
3532 const adjustedDiff = [
3633 `@@ ${ filename } :${ lineNo . groups . lineno } @@ ${ hunkHeaderContext } ` ,
37- ...gitdiffLines . slice ( 5 )
34+ ...gitdiffLines . slice ( 5 ) ,
3835 ] . join ( '\n' ) ;
3936
4037 // simple-git adds this "(HEAD, origin/master)" string to the first commit's message...
41- const commitMessage = commit . message . replace ( / \( H E A D .* / , '' ) . replace ( ' (master)' , '' ) . replace ( ' (main)' , '' ) . trim ( ) ;
38+ const commitMessage = commit . message
39+ . replace ( / \( H E A D .* / , '' )
40+ . replace ( ' (master)' , '' )
41+ . replace ( ' (main)' , '' )
42+ . trim ( ) ;
4243 const commitDateStr = formatDateString ( commit . date ) ;
4344 results += `\n\n## ${ commitMessage } — _${ commitDateStr } _\n` ;
4445 const hashCompareStr = `${ previousCommit . hash . slice ( 0 , 7 ) } ...${ commit . hash . slice ( 0 , 7 ) } ` ;
@@ -50,7 +51,6 @@ ${adjustedDiff.trim()}
5051 }
5152}
5253
53-
5454const blacklistedCommits = [
5555 'b97e97f476c04b6b91e17dbd83ccd4543c3229fd' , // use private bot email
5656 '366374904f0cfd931263af8e171015859c5d6339' , // use private bot email
@@ -68,7 +68,7 @@ const blacklistedCommits = [
6868 */
6969class CommitCrawler {
7070 constructor ( ) {
71- this . remote = path . join ( __dirname , '../' ) ; // local clone
71+ this . remote = path . join ( __dirname , '../' ) ; // local clone
7272 this . path = path . join ( __dirname , './stubprotocolrepo' ) ;
7373
7474 if ( ! fs . existsSync ( this . path ) ) {
@@ -89,7 +89,9 @@ class CommitCrawler {
8989 await wait ( ) ;
9090 const commitlog = await git . log ( ) ;
9191 // Remove any commits we don't want to deal with.
92- this . commitlogs = commitlog . all . filter ( commit => ! blacklistedCommits . includes ( commit . hash ) ) ;
92+ this . commitlogs = commitlog . all . filter (
93+ ( commit ) => ! blacklistedCommits . includes ( commit . hash ) ,
94+ ) ;
9395
9496 const max = Math . min ( this . commitlogs . length , maxCommitsInChangelog ) ;
9597
@@ -111,19 +113,22 @@ class CommitCrawler {
111113
112114 const gitdiff = await this . git . diff ( [ previousCommit . hash , commit . hash , './pdl' ] ) ;
113115 // log status
114- console . log ( i , new Array ( 4 - i . toString ( ) . split ( '' ) . length ) . fill ( ' ' ) . join ( '' ) , commit . hash , gitdiff . length . toLocaleString ( ) . padStart ( 8 ) ) ;
116+ console . log (
117+ i ,
118+ new Array ( 4 - i . toString ( ) . split ( '' ) . length ) . fill ( ' ' ) . join ( '' ) ,
119+ commit . hash ,
120+ gitdiff . length . toLocaleString ( ) . padStart ( 8 ) ,
121+ ) ;
115122 Formatter . logCommit ( previousCommit , commit , gitdiff ) ;
116123 }
117124 }
118125}
119126
120- ( async function ( ) {
121- try {
122- const crawler = new CommitCrawler ( ) ;
123- await crawler . crawl ( ) ;
124- fs . writeFileSync ( path . join ( __dirname , '../changelog.md' ) , results ) ;
125- console . log ( 'changelog.md updated' ) ;
126- } catch ( e ) {
127- console . error ( 'changelog.md update FAILED' , e ) ;
128- }
129- } ) ( ) ;
127+ try {
128+ const crawler = new CommitCrawler ( ) ;
129+ await crawler . crawl ( ) ;
130+ fs . writeFileSync ( path . join ( __dirname , '../changelog.md' ) , results ) ;
131+ console . log ( 'changelog.md updated' ) ;
132+ } catch ( e ) {
133+ console . error ( 'changelog.md update FAILED' , e ) ;
134+ }
0 commit comments