11import { createWriteStream } from 'fs'
2- import dependencies from '../dependencies.json' with { type : 'json' }
2+ import { readFile } from 'fs/promises'
3+ import { join } from 'path'
34import { execFile } from 'child_process'
45import { promisify } from 'util'
56
67const execFileAsync = promisify ( execFile )
78
8- const { stdout } = await execFileAsync ( 'git' , [ 'show' , 'HEAD:dependencies.json' ] )
9+ const { stdout } = await execFileAsync ( 'git' , [
10+ 'show' ,
11+ 'HEAD~50:dependencies.json' ,
12+ ] )
913const previousDependencies = JSON . parse ( stdout )
10- const currentDependencies = dependencies
14+ const currentDependencies = JSON . parse (
15+ await readFile ( join ( import . meta. dirname , '..' , 'dependencies.json' ) , 'utf8' )
16+ )
1117
1218const listFormatter = new Intl . ListFormat ( 'en' )
1319
14- const findG4WVersion = ( deps ) => {
20+ const findG4WVersion = deps => {
1521 const url = deps . git . packages . find ( x => x . platform === 'windows' ) ?. url
1622
1723 if ( url ) {
@@ -24,37 +30,49 @@ const findG4WVersion = (deps) => {
2430}
2531
2632const updates = {
27- "Git" : currentDependencies . git . version !== previousDependencies . git . version ? {
28- from : previousDependencies . git . version ,
29- to : currentDependencies . git . version
30- } : undefined ,
31- "G4W" : findG4WVersion ( currentDependencies ) !== findG4WVersion ( previousDependencies ) ? {
32- from : findG4WVersion ( previousDependencies ) ,
33- to : findG4WVersion ( currentDependencies )
34- } : undefined ,
35- "LFS" : currentDependencies [ 'git-lfs' ] . version !== previousDependencies [ 'git-lfs' ] . version ? {
36- from : previousDependencies [ 'git-lfs' ] . version ,
37- to : currentDependencies [ 'git-lfs' ] . version
38- } : undefined ,
39- "GCM" : currentDependencies [ 'git-credential-manager' ] . version !== previousDependencies [ 'git-credential-manager' ] . version ? {
40- from : previousDependencies [ 'git-credential-manager' ] . version ,
41- to : currentDependencies [ 'git-credential-manager' ] . version
42- } : undefined ,
33+ Git :
34+ currentDependencies . git . version !== previousDependencies . git . version
35+ ? {
36+ from : previousDependencies . git . version ,
37+ to : currentDependencies . git . version ,
38+ }
39+ : undefined ,
40+ G4W :
41+ findG4WVersion ( currentDependencies ) !== findG4WVersion ( previousDependencies )
42+ ? {
43+ from : findG4WVersion ( previousDependencies ) ,
44+ to : findG4WVersion ( currentDependencies ) ,
45+ }
46+ : undefined ,
47+ LFS :
48+ currentDependencies [ 'git-lfs' ] . version !==
49+ previousDependencies [ 'git-lfs' ] . version
50+ ? {
51+ from : previousDependencies [ 'git-lfs' ] . version ,
52+ to : currentDependencies [ 'git-lfs' ] . version ,
53+ }
54+ : undefined ,
55+ GCM :
56+ currentDependencies [ 'git-credential-manager' ] . version !==
57+ previousDependencies [ 'git-credential-manager' ] . version
58+ ? {
59+ from : previousDependencies [ 'git-credential-manager' ] . version ,
60+ to : currentDependencies [ 'git-credential-manager' ] . version ,
61+ }
62+ : undefined ,
4363}
4464
45- const updatedComponents = Array . from ( Object . entries ( updates ) . filter ( ( [ _ , v ] ) => v !== undefined ) . map ( ( [ k ] ) => k ) )
65+ const updatedComponents = Array . from (
66+ Object . entries ( updates ) . filter ( ( [ _ , v ] ) => v !== undefined )
67+ )
4668
4769if ( updatedComponents . length === 0 ) {
4870 console . log ( 'title=Update dependencies' )
4971} else {
50- console . log ( `title=Update ${ listFormatter . format ( updatedComponents ) } ` )
51- }
52-
53- if ( updatedComponents . length === 0 ) {
54- console . log ( 'commit-message=Update dependencies' )
55- } else {
56- const parts = Object . entries ( updates ) . filter ( ( [ _ , v ] ) => v !== undefined ) . map ( ( [ k , v ] ) => `${ k } to ${ v . to } ` )
57- console . log ( `commit-message=Update ${ listFormatter . format ( parts ) } ` )
72+ const parts = Object . entries ( updates )
73+ . filter ( ( [ _ , v ] ) => v !== undefined )
74+ . map ( ( [ k , v ] ) => `${ k } to ${ v . to } ` )
75+ console . log ( `title=Update ${ listFormatter . format ( parts ) } ` )
5876}
5977
6078const bodyStream = createWriteStream ( 'pr-body.md' , 'utf8' )
6785wl ( `` )
6886
6987if ( updates . Git ) {
70- wl ( `- Updated Git from ${ updates . Git . from } to ${ updates . Git . to } ` )
88+ wl ( `- Updated Git from ${ updates . Git . from } to ${ updates . Git . to } ` )
7189}
7290
7391if ( updates . G4W ) {
74- wl ( `- Updated G4W from ${ updates . G4W . from } to ${ updates . G4W . to } ` )
92+ wl ( `- Updated G4W from ${ updates . G4W . from } to ${ updates . G4W . to } ` )
7593}
7694
7795if ( updates . LFS ) {
78- wl ( `- Updated Git LFS from ${ updates . LFS . from } to ${ updates . LFS . to } ` )
96+ wl ( `- Updated Git LFS from ${ updates . LFS . from } to ${ updates . LFS . to } ` )
7997}
8098
8199if ( updates . GCM ) {
0 commit comments