Skip to content

Commit

Permalink
make replacement in docs/basics recursive into subdirectories
Browse files Browse the repository at this point in the history
Signed-off-by: Sumu <[email protected]>
  • Loading branch information
sumupitchayan committed Sep 21, 2023
1 parent 2b16c26 commit 090ec8e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/replace-old-version-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ export function replaceOldVersionReferences(latestVersion: string) {
replaceRefsInFile('docs/plus/index.md', `${latestVersionNumber - 1}`, latestVersion);

// update all references in docs/basics/**
const docsFileNames = fs.readdirSync('docs/basics/', { encoding: 'utf-8' });
docsFileNames.forEach(function (filePath) {
replaceRefsInFile(path.join('docs/basics/', filePath), `${latestVersionNumber - 1}`, latestVersion);
recursiveReplaceRefsInDir('docs/basics/', `${latestVersionNumber - 1}`, latestVersion);
}

function recursiveReplaceRefsInDir(dir: string, toReplace: string, substitution: string) {
fs.readdirSync(dir, { encoding: 'utf-8' }).forEach(file => {
let fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
recursiveReplaceRefsInDir(fullPath, toReplace, substitution);
} else {
replaceRefsInFile(fullPath, toReplace, substitution)
}
});
}

Expand Down

0 comments on commit 090ec8e

Please sign in to comment.