File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -4,14 +4,16 @@ import path from 'path';
4
4
export class LogFile {
5
5
private basePath ;
6
6
private fileName ;
7
+ private operation ;
7
8
8
9
constructor (
9
- operation : string ,
10
+ operation : 'Restore' | 'Backup' ,
10
11
basePath : string = process . cwd ( )
11
12
) {
12
13
this . basePath = basePath ;
14
+ this . operation = operation ;
13
15
14
- this . fileName = `${ Date . now ( ) } - ${ operation } .jsonl` ;
16
+ this . fileName = `${ operation } - ${ Date . now ( ) } .jsonl` ;
15
17
}
16
18
17
19
private async write ( data : string ) {
@@ -20,17 +22,24 @@ export class LogFile {
20
22
data + '\n'
21
23
) ;
22
24
}
25
+ get isRestored ( ) {
26
+ return String ( this . operation ) . toLowerCase ( ) === 'restore' ;
27
+ }
23
28
24
29
async append ( data : {
25
30
target : string ,
26
31
source : string ,
27
32
type : 'file' | 'directory' ,
28
33
status : 'success' | 'error' | 'skip' ,
29
34
} ) {
30
- await this . write ( JSON . stringify ( {
35
+ const obj = {
31
36
...data ,
32
- target : path . relative ( this . basePath , data . target ) ,
33
- // timestamp: Date.now(),
34
- } ) ) ;
37
+ ...(
38
+ this . isRestored
39
+ ? { source : path . relative ( this . basePath , data . source ) }
40
+ : { target : path . relative ( this . basePath , data . target ) }
41
+ )
42
+ }
43
+ return this . write ( JSON . stringify ( obj ) ) ;
35
44
}
36
45
}
You can’t perform that action at this time.
0 commit comments