|
| 1 | +import { resolve } from 'node:path' |
| 2 | +import { fileURLToPath } from 'node:url' |
| 3 | +import { readFileSync, writeFileSync } from 'node:fs' |
| 4 | +import { generateReferenceDocs } from '@tanstack/config/typedoc' |
| 5 | +import { glob } from 'tinyglobby' |
| 6 | + |
| 7 | +const __dirname = fileURLToPath(new URL('.', import.meta.url)) |
| 8 | + |
| 9 | +await generateReferenceDocs({ |
| 10 | + packages: [ |
| 11 | + { |
| 12 | + name: 'devtools', |
| 13 | + entryPoints: [resolve(__dirname, '../packages/devtools/src/index.ts')], |
| 14 | + tsconfig: resolve(__dirname, '../packages/devtools/tsconfig.docs.json'), |
| 15 | + outputDir: resolve(__dirname, '../docs/reference'), |
| 16 | + }, |
| 17 | + { |
| 18 | + name: 'react-devtools', |
| 19 | + entryPoints: [ |
| 20 | + resolve(__dirname, '../packages/react-devtools/src/index.ts'), |
| 21 | + ], |
| 22 | + tsconfig: resolve( |
| 23 | + __dirname, |
| 24 | + '../packages/react-devtools/tsconfig.docs.json', |
| 25 | + ), |
| 26 | + outputDir: resolve(__dirname, '../docs/framework/react/reference'), |
| 27 | + exclude: ['packages/devtools/**/*'], |
| 28 | + }, |
| 29 | + { |
| 30 | + name: 'solid-devtools', |
| 31 | + entryPoints: [ |
| 32 | + resolve(__dirname, '../packages/solid-devtools/src/index.ts'), |
| 33 | + ], |
| 34 | + tsconfig: resolve( |
| 35 | + __dirname, |
| 36 | + '../packages/solid-devtools/tsconfig.docs.json', |
| 37 | + ), |
| 38 | + outputDir: resolve(__dirname, '../docs/framework/solid/reference'), |
| 39 | + exclude: ['packages/devtools/**/*'], |
| 40 | + }, |
| 41 | + ], |
| 42 | +}) |
| 43 | + |
| 44 | +// Find all markdown files matching the pattern |
| 45 | +const markdownFiles = [ |
| 46 | + ...(await glob('docs/reference/**/*.md')), |
| 47 | + ...(await glob('docs/framework/*/reference/**/*.md')), |
| 48 | +] |
| 49 | + |
| 50 | +console.log(`Found ${markdownFiles.length} markdown files to process\n`) |
| 51 | + |
| 52 | +// Process each markdown file |
| 53 | +markdownFiles.forEach((file) => { |
| 54 | + const content = readFileSync(file, 'utf-8') |
| 55 | + let updatedContent = content |
| 56 | + updatedContent = updatedContent.replaceAll(/\]\(\.\.\//gm, '](../../') |
| 57 | + // updatedContent = content.replaceAll(/\]\(\.\//gm, '](../') |
| 58 | + updatedContent = updatedContent.replaceAll( |
| 59 | + /\]\((?!https?:\/\/|\/\/|\/|\.\/|\.\.\/|#)([^)]+)\)/gm, |
| 60 | + // @ts-expect-error |
| 61 | + (match, p1) => `](../${p1})`, |
| 62 | + ) |
| 63 | + |
| 64 | + // Write the updated content back to the file |
| 65 | + if (updatedContent !== content) { |
| 66 | + writeFileSync(file, updatedContent, 'utf-8') |
| 67 | + console.log(`Processed file: ${file}`) |
| 68 | + } |
| 69 | +}) |
| 70 | + |
| 71 | +console.log('\n✅ All markdown files have been processed!') |
| 72 | + |
| 73 | +process.exit(0) |
0 commit comments