MCPcopy Create free account
hub / github.com/dyoshikawa/rulesync / writeAiFiles

Function writeAiFiles

src/types/feature-processor.ts:59–93  ·  view source on GitHub ↗

* Once converted to rulesync/tool files, write them to the filesystem. * Returns the count and paths of files written.

(aiFiles: AiFile[])

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 9

readFileContentOrNullFunction · 0.85
addTrailingNewlineFunction · 0.85
fileContentsEquivalentFunction · 0.85
writeFileContentFunction · 0.85
setFileContentMethod · 0.45
getFileContentMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…