1+ //@ts -check
12import { exec } from 'child_process' ;
23import { readFileSync , writeFileSync } from 'fs' ;
34import { createInterface } from 'readline' ;
@@ -15,15 +16,17 @@ let data = readFileSync(changelogPath, 'utf8');
1516
1617// Find the current version number
1718const match = / \[ u n r e l e a s e d \] : h t t p s : \/ \/ g i t h u b \. c o m \/ g i t k r a k e n \/ v s c o d e - g i t l e n s \/ c o m p a r e \/ v ( .+ ) \. \. \. H E A D / . exec ( data ) ;
18- const currentVersion = match ?. [ 1 ] ;
19+ let currentVersion = match ?. [ 1 ] ;
1920if ( currentVersion == null || versionRegex . test ( currentVersion ) === false ) {
2021 console . error ( 'Unable to find current version number.' ) ;
2122 currentVersion = '0.0.0' ;
2223}
2324
2425// Create readline interface for getting input from user
2526const rl = createInterface ( {
27+ // @ts -ignore
2628 input : process . stdin ,
29+ // @ts -ignore
2730 output : process . stdout ,
2831} ) ;
2932
@@ -50,10 +53,15 @@ rl.question(`Enter the new version number (format x.x.x, current is ${currentVer
5053 // Add the new version header below the ## [Unreleased] header
5154 data = data . replace ( '## [Unreleased]' , newVersionHeader ) ;
5255
53- const unreleasedLink = match [ 0 ] . replace ( / \/ c o m p a r e \/ v ( .+ ?) \. \. \. H E A D / , `/compare/v${ version } ...HEAD` ) ;
56+ if ( match == null ) {
57+ // Add the [unreleased]: line
58+ data += `\n[unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/v${ version } ...HEAD` ;
59+ } else {
60+ const unreleasedLink = match [ 0 ] . replace ( / \/ c o m p a r e \/ v ( .+ ?) \. \. \. H E A D / , `/compare/v${ version } ...HEAD` ) ;
5461
55- // Update the [unreleased]: line
56- data = data . replace ( match [ 0 ] , `${ unreleasedLink } \n${ newVersionLink } ` ) ;
62+ // Update the [unreleased]: line
63+ data = data . replace ( match [ 0 ] , `${ unreleasedLink } \n${ newVersionLink } ` ) ;
64+ }
5765
5866 // Writing the updated version data to CHANGELOG
5967 writeFileSync ( changelogPath , data ) ;
0 commit comments