(
sourceDir: string,
targetDir: string,
options?: SyncOptions,
)
| 24 | |
| 25 | export class FileSyncer { |
| 26 | async sync( |
| 27 | sourceDir: string, |
| 28 | targetDir: string, |
| 29 | options?: SyncOptions, |
| 30 | ): Promise<SyncResult> { |
| 31 | const result: SyncResult = { |
| 32 | updated: [], |
| 33 | skipped: [], |
| 34 | created: [], |
| 35 | deleted: [], |
| 36 | sourceFiles: [], |
| 37 | errors: [], |
| 38 | } |
| 39 | |
| 40 | // Ensure directories exist |
| 41 | if (!fs.existsSync(sourceDir)) { |
| 42 | throw new Error(`Source directory does not exist: ${sourceDir}`) |
| 43 | } |
| 44 | if (!fs.existsSync(targetDir)) { |
| 45 | throw new Error(`Target directory does not exist: ${targetDir}`) |
| 46 | } |
| 47 | |
| 48 | // Walk through source directory and sync files |
| 49 | await this.syncDirectory(sourceDir, targetDir, sourceDir, result) |
| 50 | |
| 51 | if (options?.deleteRemoved && options.previousSourceFiles) { |
| 52 | const currentSourceFileSet = new Set(result.sourceFiles) |
| 53 | await this.deleteRemovedFiles( |
| 54 | targetDir, |
| 55 | options.previousSourceFiles, |
| 56 | currentSourceFileSet, |
| 57 | result, |
| 58 | ) |
| 59 | } |
| 60 | |
| 61 | return result |
| 62 | } |
| 63 | |
| 64 | private async syncDirectory( |
| 65 | currentPath: string, |
nothing calls this directly
no test coverage detected