Improve local client
This commit is contained in:
parent
a75b3469a3
commit
bbec7f14dd
6 changed files with 276 additions and 55 deletions
|
|
@ -8,7 +8,8 @@ export class FileWatcher {
|
|||
|
||||
public constructor(
|
||||
private readonly basePath: string,
|
||||
private readonly client: SyncClient
|
||||
private readonly client: SyncClient,
|
||||
private readonly ignorePatterns: string[] = []
|
||||
) {}
|
||||
|
||||
public start(): void {
|
||||
|
|
@ -22,7 +23,8 @@ export class FileWatcher {
|
|||
recursive: true,
|
||||
renameDetection: true,
|
||||
renameTimeout: 125,
|
||||
ignoreInitial: true
|
||||
ignoreInitial: true,
|
||||
ignore: (filePath: string) => this.shouldIgnore(filePath)
|
||||
});
|
||||
|
||||
this.watcher.on("add", (filePath: string) => {
|
||||
|
|
@ -56,6 +58,19 @@ export class FileWatcher {
|
|||
this.client.logger.info("File watcher stopped");
|
||||
}
|
||||
|
||||
private shouldIgnore(filePath: string): boolean {
|
||||
const rel = path
|
||||
.relative(this.basePath, filePath)
|
||||
.replace(/\\/g, "/");
|
||||
return this.ignorePatterns.some((pattern) => {
|
||||
if (pattern.endsWith("/**")) {
|
||||
const prefix = pattern.slice(0, -3);
|
||||
return rel === prefix || rel.startsWith(prefix + "/");
|
||||
}
|
||||
return rel === pattern;
|
||||
});
|
||||
}
|
||||
|
||||
private handleCreate(relativePath: RelativePath): void {
|
||||
this.client
|
||||
.syncLocallyCreatedFile(relativePath)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue