|
| 1 | +import { |
| 2 | + access, |
| 3 | + copyFile, |
| 4 | + mkdir, |
| 5 | + readdir, |
| 6 | + readFile, |
| 7 | + rm, |
| 8 | + writeFile, |
| 9 | +} from "node:fs/promises"; |
| 10 | +import { join } from "node:path"; |
| 11 | + |
| 12 | +async function main() { |
| 13 | + const monorepoRoot = join(process.cwd(), "..", ".."); |
| 14 | + const packagesRoot = join(monorepoRoot, "packages"); |
| 15 | + const outDir = join(process.cwd(), "docs", "plugins"); |
| 16 | + |
| 17 | + await rm(outDir, { force: true, recursive: true }); |
| 18 | + await mkdir(outDir, { recursive: true }); |
| 19 | + |
| 20 | + // Copy the monorepo README as the docs intro page |
| 21 | + const repoReadme = join(monorepoRoot, "README.md"); |
| 22 | + const introDoc = join(process.cwd(), "docs", "intro.md"); |
| 23 | + try { |
| 24 | + await access(repoReadme); |
| 25 | + const raw = await readFile(repoReadme, "utf8"); |
| 26 | + // Rewrite repo-relative links that would 404 on the docs site |
| 27 | + const rewritten = raw.replace( |
| 28 | + /\((?:\.\/)?LICENSE(?:\.md)?\)/g, |
| 29 | + "(#license)", |
| 30 | + ); |
| 31 | + await writeFile(introDoc, rewritten, "utf8"); |
| 32 | + } catch { |
| 33 | + // ignore if the root README does not exist |
| 34 | + } |
| 35 | + |
| 36 | + // Copy each package README under docs/plugins |
| 37 | + const packages = await readdir(packagesRoot, { withFileTypes: true }); |
| 38 | + |
| 39 | + for (const dir of packages) { |
| 40 | + if (!dir.isDirectory() || dir.name === "tsconfig") continue; |
| 41 | + const readme = join(packagesRoot, dir.name, "README.md"); |
| 42 | + try { |
| 43 | + await access(readme); |
| 44 | + await copyFile(readme, join(outDir, `${dir.name}.md`)); |
| 45 | + } catch { |
| 46 | + /* ignore */ |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +main().catch((err) => { |
| 52 | + console.error(err); |
| 53 | + process.exit(1); |
| 54 | +}); |
0 commit comments