From 13248a327014094ed13bb10748aadc740177c0a9 Mon Sep 17 00:00:00 2001 From: rektdeckard Date: Sun, 29 Dec 2024 21:49:15 -0700 Subject: [PATCH] chore(ci): make sure to create synced files ...and intermediate directories if they don't already exist --- .github/workflows/sync-docs.yaml | 1 + scripts/sync-docs.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync-docs.yaml b/.github/workflows/sync-docs.yaml index 722ef39..d0e3c81 100644 --- a/.github/workflows/sync-docs.yaml +++ b/.github/workflows/sync-docs.yaml @@ -86,6 +86,7 @@ jobs: git checkout -b $BRANCH # Commit and push changes + git add . git commit -am "chore(docs): sync readme section" git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ matrix.repository }}.git" $BRANCH diff --git a/scripts/sync-docs.ts b/scripts/sync-docs.ts index 5094fa6..a34de15 100644 --- a/scripts/sync-docs.ts +++ b/scripts/sync-docs.ts @@ -15,7 +15,6 @@ const SYNC_FILES: Array> = [ const targetRepo = process.argv[process.argv.length - 1]; if (!targetRepo) throw new Error("Target repository not provided"); - const readmePath = path.resolve(__dirname, `../${README_PATH}`); const readmeContent = fs.readFileSync(readmePath, "utf8"); @@ -36,6 +35,7 @@ const SYNC_FILES: Array> = [ const filePath = path.resolve(__dirname, `../${fileName}`); const fileContent = fs.readFileSync(filePath, "utf8"); + // If target file has aliases, remove them if (Array.isArray(file)) { for (const alias of file) { const targetPath = path.resolve(__dirname, `../../${targetRepo}/${alias}`); @@ -45,8 +45,12 @@ const SYNC_FILES: Array> = [ } } + // Write the target file and intermediate directories, or overwrite if it already exists const targetPath = path.resolve(__dirname, `../../${targetRepo}/${fileName}`); - fs.writeFileSync(targetPath, fileContent); // Overwrites the target file if it exists + if (!fs.existsSync(path.dirname(targetPath))) { + fs.mkdirSync(path.dirname(targetPath), { recursive: true }); + } + fs.writeFileSync(targetPath, fileContent); } })();