From e4ebf5fae13d338dbcc296cc5cf8962cc543cf5a Mon Sep 17 00:00:00 2001 From: Revone Date: Fri, 22 Nov 2024 17:48:13 +1300 Subject: [PATCH] fix: Skip writing when the ci process cannot read the subpackages directory. --- scripts/testToExample.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/testToExample.ts b/scripts/testToExample.ts index b2761f8..dbd6576 100644 --- a/scripts/testToExample.ts +++ b/scripts/testToExample.ts @@ -254,7 +254,14 @@ function updateExamples(testDir: string, sourceBaseDir: string): void { * Replace content between markers in README.md. */ function replaceExamplesInReadme(readmePath: string, newExamples: string[]): void { - const readmeContent = fs.readFileSync(readmePath, 'utf-8'); + let readmeContent: string; + + try { + readmeContent = fs.readFileSync(readmePath, 'utf-8'); + } catch (error) { + console.warn(`Failed to read ${fileName} at ${readmePath}: ${error}`); + return; + } const startIdx = readmeContent.indexOf(START_MARKER); const endIdx = readmeContent.indexOf(END_MARKER); @@ -269,7 +276,7 @@ function replaceExamplesInReadme(readmePath: string, newExamples: string[]): voi const updatedContent = `${before}\n\n${newExamples.join('\n\n')}\n\n${after}`; fs.writeFileSync(readmePath, updatedContent, 'utf-8'); - console.log(`README.md updated with new examples.`); + console.log(`${fileName} updated with new examples.`); } // Run the script