1
+ //@ts -check
1
2
import { exec } from 'child_process' ;
2
3
import { readFileSync , writeFileSync } from 'fs' ;
3
4
import { createInterface } from 'readline' ;
@@ -15,15 +16,17 @@ let data = readFileSync(changelogPath, 'utf8');
15
16
16
17
// Find the current version number
17
18
const 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 ] ;
19
20
if ( currentVersion == null || versionRegex . test ( currentVersion ) === false ) {
20
21
console . error ( 'Unable to find current version number.' ) ;
21
22
currentVersion = '0.0.0' ;
22
23
}
23
24
24
25
// Create readline interface for getting input from user
25
26
const rl = createInterface ( {
27
+ // @ts -ignore
26
28
input : process . stdin ,
29
+ // @ts -ignore
27
30
output : process . stdout ,
28
31
} ) ;
29
32
@@ -50,10 +53,15 @@ rl.question(`Enter the new version number (format x.x.x, current is ${currentVer
50
53
// Add the new version header below the ## [Unreleased] header
51
54
data = data . replace ( '## [Unreleased]' , newVersionHeader ) ;
52
55
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` ) ;
54
61
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
+ }
57
65
58
66
// Writing the updated version data to CHANGELOG
59
67
writeFileSync ( changelogPath , data ) ;
0 commit comments