Skip to content

Commit 16607eb

Browse files
committed
chore: update
1 parent 87c10a8 commit 16607eb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/log.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import path from 'path';
44
export class LogFile {
55
private basePath;
66
private fileName;
7+
private operation;
78

89
constructor(
9-
operation: string,
10+
operation: 'Restore' | 'Backup',
1011
basePath: string = process.cwd()
1112
) {
1213
this.basePath = basePath;
14+
this.operation = operation;
1315

14-
this.fileName = `${Date.now()}-${operation}.jsonl`;
16+
this.fileName = `${operation}-${Date.now()}.jsonl`;
1517
}
1618

1719
private async write(data: string) {
@@ -20,17 +22,24 @@ export class LogFile {
2022
data + '\n'
2123
);
2224
}
25+
get isRestored() {
26+
return String(this.operation).toLowerCase() === 'restore';
27+
}
2328

2429
async append(data: {
2530
target: string,
2631
source: string,
2732
type: 'file' | 'directory',
2833
status: 'success' | 'error' | 'skip',
2934
}) {
30-
await this.write(JSON.stringify({
35+
const obj = {
3136
...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));
3544
}
3645
}

0 commit comments

Comments
 (0)