* Once converted to rulesync/tool files, write them to the filesystem. * Returns the count and paths of files written.
(aiFiles: AiFile[])
| 57 | * Returns the count and paths of files written. |
| 58 | */ |
| 59 | async writeAiFiles(aiFiles: AiFile[]): Promise<WriteResult> { |
| 60 | let changedCount = 0; |
| 61 | const changedPaths: string[] = []; |
| 62 | for (const aiFile of aiFiles) { |
| 63 | const filePath = aiFile.getFilePath(); |
| 64 | const existingFileContent = await readFileContentOrNull(filePath); |
| 65 | |
| 66 | if (existingFileContent !== null && aiFile.shouldMergeExistingFileContent()) { |
| 67 | aiFile.setFileContent(existingFileContent); |
| 68 | } |
| 69 | |
| 70 | const contentWithNewline = addTrailingNewline(aiFile.getFileContent()); |
| 71 | const existingContent = existingFileContent; |
| 72 | |
| 73 | if ( |
| 74 | fileContentsEquivalent({ |
| 75 | filePath, |
| 76 | expected: contentWithNewline, |
| 77 | existing: existingContent, |
| 78 | }) |
| 79 | ) { |
| 80 | continue; |
| 81 | } |
| 82 | |
| 83 | if (this.dryRun) { |
| 84 | this.logger.info(`[DRY RUN] Would write: ${filePath}`); |
| 85 | } else { |
| 86 | await writeFileContent(filePath, contentWithNewline); |
| 87 | } |
| 88 | changedCount++; |
| 89 | changedPaths.push(aiFile.getRelativePathFromCwd()); |
| 90 | } |
| 91 | |
| 92 | return { count: changedCount, paths: changedPaths }; |
| 93 | } |
| 94 | |
| 95 | async removeAiFiles(aiFiles: AiFile[]): Promise<void> { |
| 96 | for (const aiFile of aiFiles) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…