-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add script to delete a version of the docs (#833)
This is to make it easier to update docs. We use this when updating the docs for a patch release.
- Loading branch information
1 parent
de02729
commit 0a6bd39
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
const rootPath = path.join(import.meta.dirname, '..'); | ||
|
||
async function removeFromVersionsJSON(version) { | ||
const versionsFile = path.join(rootPath, 'versions.json'); | ||
|
||
console.log(`Removing version ${version} from ${versionsFile}`); | ||
|
||
const versions = JSON.parse(await fs.readFile(versionsFile, 'utf-8')); | ||
|
||
if (!versions.includes(version)) { | ||
throw new Error('Unknown version'); | ||
} | ||
|
||
const newVersions = versions.filter((v) => v !== version); | ||
|
||
await fs.writeFile(versionsFile, `${JSON.stringify(newVersions, null, 2)}\n`, 'utf-8'); | ||
} | ||
|
||
async function removeVersionedDocs(version) { | ||
const directory = path.join(rootPath, 'versioned_docs', `version-${version}`); | ||
|
||
console.log(`Deleting ${directory}`); | ||
|
||
await fs.rm(directory, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
} | ||
|
||
async function removeVersionedSidebar(version) { | ||
const file = path.join(rootPath, 'versioned_sidebars', `version-${version}-sidebars.json`); | ||
|
||
console.log(`Deleting ${file}`); | ||
|
||
await fs.rm(file); | ||
} | ||
|
||
async function main() { | ||
const [, , version] = process.argv; | ||
|
||
if (!version) { | ||
throw new Error('Version not set'); | ||
} | ||
|
||
await removeFromVersionsJSON(version); | ||
await removeVersionedDocs(version); | ||
await removeVersionedSidebar(version); | ||
|
||
console.log(`Version ${version} is removed`) | ||
} | ||
|
||
main().catch(err => { | ||
console.log(err.stack); | ||
process.exit(1); | ||
}); |