1
- //@ts -check
2
- const { execCommand } = require ( '../utils/exec' ) ;
1
+ import { execCommand } from './exec' ;
3
2
4
- /**
5
- * @typedef {{
6
- * status: 'tracked' | 'staged' | 'untracked'
7
- * path: string
8
- * }} File
9
- * @returns {Promise<Array<File>> }
10
- */
11
- async function gitStatus ( ) {
3
+ type File = {
4
+ status : 'tracked' | 'staged' | 'untracked' ;
5
+ path : string ;
6
+ } ;
7
+
8
+ async function runCommand ( command : string , files : Array < string > ) {
9
+ const gitCommand = `git ${ command } ${ files . join ( ' ' ) } ` ;
10
+ await execCommand ( gitCommand ) ;
11
+ console . log ( '\x1b[0m' , `"${ gitCommand } "` , '\x1b[32m' , 'did great 🤟' ) ;
12
+ }
13
+
14
+ export async function gitStatus ( ) : Promise < Array < File > > {
12
15
const status = await execCommand ( 'git status --porcelain=v2 -uall' ) ;
13
- /**
14
- * @type Array<File>
15
- */
16
- const initialFiles = [ ] ;
17
16
const files = status
18
17
. split ( / \n / g)
19
18
. filter ( ( line ) => line )
@@ -26,51 +25,31 @@ async function gitStatus() {
26
25
if ( stagedIndication !== '.' ) {
27
26
prev . push ( {
28
27
status : 'staged' ,
29
- path
28
+ path,
30
29
} ) ;
31
30
}
32
31
if ( changedIndication !== '.' ) {
33
32
prev . push ( {
34
33
status : 'tracked' ,
35
- path
34
+ path,
36
35
} ) ;
37
36
}
38
37
} else if ( index === '?' ) {
39
38
prev . push ( {
40
39
status : 'untracked' ,
41
- path
40
+ path,
42
41
} ) ;
43
42
}
44
43
return prev ;
45
- } , initialFiles ) ;
44
+ } , [ ] ) ;
46
45
47
46
return files ;
48
47
}
49
48
50
- /**
51
- * @param {string } command
52
- * @param {Array<string> } files
53
- */
54
- async function runCommand ( command , files ) {
55
- const gitCommand = `git ${ command } ${ files . join ( ' ' ) } ` ;
56
- await execCommand ( gitCommand ) ;
57
- console . log ( '\x1b[0m' , `"${ gitCommand } "` , '\x1b[32m' , 'did great 🤟' ) ;
58
- }
59
-
60
- /**
61
- * @param {Array<string> } files
62
- */
63
- async function gitAdd ( files ) {
49
+ export async function gitAdd ( files : Array < string > ) {
64
50
await runCommand ( 'add' , files ) ;
65
51
}
66
52
67
- /**
68
- * @param {Array<string> } files
69
- */
70
- async function gitReset ( files ) {
53
+ export async function gitReset ( files : Array < string > ) {
71
54
await runCommand ( 'reset HEAD -- ' , files ) ;
72
55
}
73
-
74
- exports . gitAdd = gitAdd ;
75
- exports . gitReset = gitReset ;
76
- exports . gitStatus = gitStatus ;
0 commit comments