chore(ci): make sure to create synced files

...and intermediate directories if they don't already exist
This commit is contained in:
rektdeckard
2024-12-29 21:49:15 -07:00
committed by Tobias Fried
parent 6d2358ffe7
commit 13248a3270
2 changed files with 7 additions and 2 deletions

View File

@@ -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

View File

@@ -15,7 +15,6 @@ const SYNC_FILES: Array<string | Array<string>> = [
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<string | Array<string>> = [
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<string | Array<string>> = [
}
}
// 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);
}
})();