11
11
*
12
12
* To avoid making an extra config value for the extension that one has to manage say in a Settings file or internal data, the approach is rather to use the existing commit template pattern in Git.
13
13
*/
14
- import * as fs from 'fs' ;
15
- import * as path from ' path' ;
14
+ import * as fs from "fs" ;
15
+ import * as path from " path" ;
16
16
import { getWorkspaceFolder } from "../workspace" ;
17
17
import { execute } from "./cli" ;
18
18
19
- const CONFIG_SUBCOMMAND = "config"
20
- const COMMIT_TEMPLATE_IDENTIFIER = ' commit.template'
19
+ const CONFIG_SUBCOMMAND = "config" ;
20
+ const COMMIT_TEMPLATE_IDENTIFIER = " commit.template" ;
21
21
22
22
/**
23
23
* Get a value from the Git config.
24
24
*
25
25
* The CLI will assume local (project) project by default.
26
26
*/
27
27
export async function _getConfigValue ( options : string [ ] ) {
28
- const workspace = getWorkspaceFolder ( )
28
+ const workspace = getWorkspaceFolder ( ) ;
29
29
const { stdout, stderr } = await execute (
30
30
workspace ,
31
31
CONFIG_SUBCOMMAND ,
@@ -36,7 +36,7 @@ export async function _getConfigValue(options: string[]) {
36
36
console . debug ( `stderr for 'git ${ CONFIG_SUBCOMMAND } ' command:` , stderr ) ;
37
37
}
38
38
39
- return stdout
39
+ return stdout ;
40
40
}
41
41
42
42
/**
@@ -46,10 +46,10 @@ export async function _getConfigValue(options: string[]) {
46
46
*/
47
47
async function _getCommitTemplatePath ( ) {
48
48
try {
49
- const options = [ COMMIT_TEMPLATE_IDENTIFIER ]
50
- return await _getConfigValue ( options )
49
+ const options = [ COMMIT_TEMPLATE_IDENTIFIER ] ;
50
+ return await _getConfigValue ( options ) ;
51
51
} catch ( _e ) {
52
- return null
52
+ return null ;
53
53
}
54
54
}
55
55
@@ -59,26 +59,26 @@ async function _getCommitTemplatePath() {
59
59
* NB. Use current workspace as the base path.
60
60
*/
61
61
function _readFile ( filePath : string ) {
62
- const workspace = getWorkspaceFolder ( )
63
- const p = path . join ( workspace , filePath )
62
+ const workspace = getWorkspaceFolder ( ) ;
63
+ const p = path . join ( workspace , filePath ) ;
64
64
65
- let value
65
+ let value ;
66
66
67
67
try {
68
- value = fs . readFileSync ( p , "utf-8" )
68
+ value = fs . readFileSync ( p , "utf-8" ) ;
69
69
} catch ( err ) {
70
- console . error ( `Could not find template file: ${ p } . ${ err . toString ( ) } ` )
70
+ console . error ( `Could not find template file: ${ p } . ${ err . toString ( ) } ` ) ;
71
71
72
- return null
72
+ return null ;
73
73
}
74
74
75
75
if ( ! value ) {
76
- return null
76
+ return null ;
77
77
}
78
78
79
- console . debug ( `Read ${ p } and found: ${ value } ` )
79
+ console . debug ( `Read ${ p } and found: ${ value } ` ) ;
80
80
81
- return value
81
+ return value ;
82
82
}
83
83
84
84
/**
@@ -87,12 +87,12 @@ function _readFile(filePath: string) {
87
87
* Return null if file is not configured or file is missing, without aborting.
88
88
*/
89
89
export async function getCommitTemplateValue ( ) {
90
- const filePath = await _getCommitTemplatePath ( )
90
+ const filePath = await _getCommitTemplatePath ( ) ;
91
91
92
92
if ( ! filePath ) {
93
- console . error ( `Could not read missing file: ${ filePath } ` )
94
- return null
93
+ console . error ( `Could not read missing file: ${ filePath } ` ) ;
94
+ return null ;
95
95
}
96
96
97
- return _readFile ( filePath )
97
+ return _readFile ( filePath ) ;
98
98
}
0 commit comments