Skip to content

Commit

Permalink
chore: sync docs from third-party libs
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 20, 2024
1 parent a87ab9b commit d74b231
Show file tree
Hide file tree
Showing 4 changed files with 1,003 additions and 2 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"test": "vitest",
"test:unit": "vitest src/**/*.test.ts",
"test:e2e": "vitest e2e/e2e.test.ts",
"tsc": "tsc --noEmit"
"tsc": "tsc --noEmit",
"sync:docs": "tsx scripts/syncDocs.ts"
},
"bin": {
"tnf": "bin/tnf.js"
Expand All @@ -33,7 +34,8 @@
"compiled",
"client",
"dist",
"templates"
"templates",
"third-party-docs"
],
"exports": {
"./package.json": "./package.json",
Expand Down
40 changes: 40 additions & 0 deletions scripts/syncDocs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import assert from 'assert';
import 'zx/globals';

const DOCS_DIR = path.join(__dirname, '../third-party-docs');
const DOCS_MAP = {
mako: {
repo: 'umijs/mako',
branch: 'master',
docsDir: 'docs',
paths: ['config.md'],
},
tanstackRouter: {
repo: 'tanstack/router',
branch: 'main',
docsDir: 'docs/framework/react',
paths: ['api/router.md'],
},
};

(async () => {
for (const [pkg, info] of Object.entries(DOCS_MAP)) {
console.log(`Syncing docs for ${pkg}...`);
const { repo, branch, docsDir, paths } = info;
const repoDir = path.join(DOCS_DIR, pkg);
for (const p of paths) {
console.log(`Syncing ${p}...`);
// e.g.
// https://raw.githubusercontent.com/umijs/mako/refs/heads/master/docs/config.md
const url = `https://raw.githubusercontent.com/${repo}/refs/heads/${branch}/${docsDir}/${p}`;
const content = await fetch(url).then((res) => res.text());
const filePath = path.join(repoDir, p);
const dir = path.dirname(filePath);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(filePath, content);
}
}
})().catch((err) => {
console.error(err);
process.exit(1);
});
Loading

0 comments on commit d74b231

Please sign in to comment.