chore(ci): make sure to create synced files
...and intermediate directories if they don't already exist
This commit is contained in:
committed by
Tobias Fried
parent
6d2358ffe7
commit
13248a3270
1
.github/workflows/sync-docs.yaml
vendored
1
.github/workflows/sync-docs.yaml
vendored
@@ -86,6 +86,7 @@ jobs:
|
|||||||
git checkout -b $BRANCH
|
git checkout -b $BRANCH
|
||||||
|
|
||||||
# Commit and push changes
|
# Commit and push changes
|
||||||
|
git add .
|
||||||
git commit -am "chore(docs): sync readme section"
|
git commit -am "chore(docs): sync readme section"
|
||||||
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ matrix.repository }}.git" $BRANCH
|
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ matrix.repository }}.git" $BRANCH
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ const SYNC_FILES: Array<string | Array<string>> = [
|
|||||||
const targetRepo = process.argv[process.argv.length - 1];
|
const targetRepo = process.argv[process.argv.length - 1];
|
||||||
if (!targetRepo) throw new Error("Target repository not provided");
|
if (!targetRepo) throw new Error("Target repository not provided");
|
||||||
|
|
||||||
|
|
||||||
const readmePath = path.resolve(__dirname, `../${README_PATH}`);
|
const readmePath = path.resolve(__dirname, `../${README_PATH}`);
|
||||||
const readmeContent = fs.readFileSync(readmePath, "utf8");
|
const readmeContent = fs.readFileSync(readmePath, "utf8");
|
||||||
|
|
||||||
@@ -36,6 +35,7 @@ const SYNC_FILES: Array<string | Array<string>> = [
|
|||||||
const filePath = path.resolve(__dirname, `../${fileName}`);
|
const filePath = path.resolve(__dirname, `../${fileName}`);
|
||||||
const fileContent = fs.readFileSync(filePath, "utf8");
|
const fileContent = fs.readFileSync(filePath, "utf8");
|
||||||
|
|
||||||
|
// If target file has aliases, remove them
|
||||||
if (Array.isArray(file)) {
|
if (Array.isArray(file)) {
|
||||||
for (const alias of file) {
|
for (const alias of file) {
|
||||||
const targetPath = path.resolve(__dirname, `../../${targetRepo}/${alias}`);
|
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}`);
|
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);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user