-
Notifications
You must be signed in to change notification settings - Fork 402
docs(repo): Generate all params and return types (hooks work) #6901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 48 commits
780cae5
128df3c
a584905
8d2e9e2
70c5908
d49447e
7b9b11b
b653539
3f1f920
3cc87f9
64da460
16f9663
febc294
c32a435
263dba2
316c861
40dbc8b
bc7873c
2ebb4f2
906c42c
113bb22
d58bcbd
3bde171
ecd1435
3262527
11d3506
6bdc23d
b6b7f80
f0ebf2e
1cfd43a
038c99d
45f698d
9f9ce0e
4cd4165
b1888f9
912fa9c
5c29779
6b4f930
9df0c27
9430645
c0b8e19
32a4c45
db76fb7
9ff65e9
a8c4ada
9e4f120
9b36954
3029aa3
623e24b
b6e0a0e
7c7ddb6
1996e7e
7b37cee
6afd559
7389079
574c180
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/shared': minor | ||
| '@clerk/types': minor | ||
| --- | ||
|
|
||
| Ensure all hooks use typedoc for clerk docs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| // @ts-check | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| /** | ||
| * Extracts the "## Returns" section from a markdown file and writes it to a separate file. | ||
| * @param {string} filePath - The path to the markdown file | ||
| * @returns {boolean} True if a file was created | ||
| */ | ||
| function extractReturnsSection(filePath) { | ||
| const content = fs.readFileSync(filePath, 'utf-8'); | ||
|
|
||
| // Find the "## Returns" section | ||
| const returnsStart = content.indexOf('## Returns'); | ||
|
|
||
| if (returnsStart === -1) { | ||
| return false; // No Returns section found | ||
| } | ||
|
|
||
| // Find the next heading after "## Returns" (or end of file) | ||
| const afterReturns = content.slice(returnsStart + 10); // Skip past "## Returns" | ||
| const nextHeadingMatch = afterReturns.match(/\n## /); | ||
| const returnsEnd = | ||
| nextHeadingMatch && typeof nextHeadingMatch.index === 'number' | ||
| ? returnsStart + 10 + nextHeadingMatch.index | ||
| : content.length; | ||
|
|
||
| // Extract the Returns section and trim trailing whitespace | ||
| const returnsContent = content.slice(returnsStart, returnsEnd).trimEnd(); | ||
|
|
||
| // Generate the new filename: use-auth.mdx -> use-auth-return.mdx | ||
| const fileName = path.basename(filePath, '.mdx'); | ||
| const dirName = path.dirname(filePath); | ||
| const newFilePath = path.join(dirName, `${fileName}-return.mdx`); | ||
|
|
||
| // Write the extracted Returns section to the new file | ||
| fs.writeFileSync(newFilePath, returnsContent, 'utf-8'); | ||
|
|
||
| console.log(`[extract-returns] Created ${path.relative(process.cwd(), newFilePath)}`); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Replaces generic type names in the parameters table with expanded types. | ||
| * @param {string} content | ||
| * @returns {string} | ||
| */ | ||
| function replaceGenericTypesInParamsTable(content) { | ||
| // Replace Fetcher in the parameters table | ||
| content = content.replace( | ||
| /(\|\s*`fetcher`\s*\|\s*)`Fetcher`(\s*\|)/g, | ||
| '$1`Fetcher extends (...args: any[]) => Promise<any>`$2', | ||
| ); | ||
| return content; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the "## Parameters" section from a markdown file and writes it to a separate file. | ||
| * @param {string} filePath - The path to the markdown file | ||
| * @param {string} dirName - The directory containing the files | ||
| * @returns {boolean} True if a file was created | ||
| */ | ||
| function extractParametersSection(filePath, dirName) { | ||
| const content = fs.readFileSync(filePath, 'utf-8'); | ||
| const fileName = path.basename(filePath, '.mdx'); | ||
|
|
||
|
Comment on lines
+62
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Params written to wrong directory; props deletion path wrong (critical). extractParametersSection writes -params.mdx at the package root and deletes -props.mdx there, not next to the source file. This will misplace files for nested MDX and fail to delete the actual props file. Align with extractReturnsSection by using the file’s own directory and drop the extra dirName param. Apply these diffs: - * @param {string} dirName - The directory containing the files
* @returns {boolean} True if a file was created
*/
-function extractParametersSection(filePath, dirName) {
+function extractParametersSection(filePath) {- // Delete any existing -props file (TypeDoc-generated)
- const propsFilePath = path.join(dirName, propsFileName);
+ // Delete any existing -props file (TypeDoc-generated)
+ const dirForFile = path.dirname(filePath);
+ const propsFilePath = path.join(dirForFile, propsFileName);- // Write to new file
- const newFilePath = path.join(dirName, targetFileName);
+ // Write to new file (next to source)
+ const newFilePath = path.join(dirForFile, targetFileName);
fs.writeFileSync(newFilePath, paramsContent, 'utf-8');- // Extract Parameters sections
- if (extractParametersSection(filePath, dir)) {
+ // Extract Parameters sections
+ if (extractParametersSection(filePath)) {
paramsCount++;
}Also applies to: 62-67, 87-90, 154-156 🤖 Prompt for AI Agents |
||
| // Always use -params suffix | ||
| const suffix = '-params'; | ||
| const targetFileName = `${fileName}${suffix}.mdx`; | ||
| const propsFileName = `${fileName}-props.mdx`; | ||
|
|
||
| // Delete any existing -props file (TypeDoc-generated) | ||
| const propsFilePath = path.join(dirName, propsFileName); | ||
| if (fs.existsSync(propsFilePath)) { | ||
| fs.unlinkSync(propsFilePath); | ||
| console.log(`[extract-returns] Deleted ${path.relative(process.cwd(), propsFilePath)}`); | ||
| } | ||
|
|
||
| // Find the "## Parameters" section | ||
| const paramsStart = content.indexOf('## Parameters'); | ||
|
|
||
| if (paramsStart === -1) { | ||
| return false; // No Parameters section found | ||
| } | ||
|
|
||
| // Find the next heading after "## Parameters" (or end of file) | ||
| const afterParams = content.slice(paramsStart + 13); // Skip past "## Parameters" | ||
| const nextHeadingMatch = afterParams.match(/\n## /); | ||
| const paramsEnd = | ||
| nextHeadingMatch && typeof nextHeadingMatch.index === 'number' | ||
| ? paramsStart + 13 + nextHeadingMatch.index | ||
| : content.length; | ||
|
|
||
| // Extract the Parameters section and trim trailing whitespace | ||
| const paramsContent = content.slice(paramsStart, paramsEnd).trimEnd(); | ||
|
|
||
| // Write to new file | ||
| const newFilePath = path.join(dirName, targetFileName); | ||
| fs.writeFileSync(newFilePath, paramsContent, 'utf-8'); | ||
|
|
||
| const processedParams = replaceGenericTypesInParamsTable(fs.readFileSync(newFilePath, 'utf-8')); | ||
| fs.writeFileSync(newFilePath, processedParams, 'utf-8'); | ||
|
|
||
| console.log(`[extract-returns] Created ${path.relative(process.cwd(), newFilePath)}`); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Recursively reads all .mdx files in a directory, excluding generated files | ||
| * @param {string} dir - The directory to read | ||
| * @returns {string[]} Array of file paths | ||
| */ | ||
| function getAllMdxFiles(dir) { | ||
| /** @type {string[]} */ | ||
| const files = []; | ||
|
|
||
| if (!fs.existsSync(dir)) { | ||
| return files; | ||
| } | ||
|
|
||
| const entries = fs.readdirSync(dir, { withFileTypes: true }); | ||
|
|
||
| for (const entry of entries) { | ||
| const fullPath = path.join(dir, entry.name); | ||
|
|
||
| if (entry.isDirectory()) { | ||
| files.push(...getAllMdxFiles(fullPath)); | ||
| } else if (entry.isFile() && entry.name.endsWith('.mdx')) { | ||
| // Exclude generated files | ||
| const isGenerated = | ||
| entry.name.endsWith('-return.mdx') || entry.name.endsWith('-params.mdx') || entry.name.endsWith('-props.mdx'); | ||
| if (!isGenerated) { | ||
| files.push(fullPath); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return files; | ||
| } | ||
|
|
||
| /** | ||
| * Main function to process all clerk-react files | ||
| */ | ||
| function main() { | ||
| const packages = ['clerk-react']; | ||
| const dirs = packages.map(folder => path.join(__dirname, 'temp-docs', folder)); | ||
|
|
||
| for (const dir of dirs) { | ||
| if (!fs.existsSync(dir)) { | ||
| console.log(`[extract-returns] ${dir} directory not found, skipping extraction`); | ||
| continue; | ||
| } | ||
|
|
||
| const mdxFiles = getAllMdxFiles(dir); | ||
| console.log(`[extract-returns] Processing ${mdxFiles.length} files in ${dir}/`); | ||
|
|
||
| let returnsCount = 0; | ||
| let paramsCount = 0; | ||
|
|
||
| for (const filePath of mdxFiles) { | ||
| // Extract Returns sections | ||
| if (extractReturnsSection(filePath)) { | ||
| returnsCount++; | ||
| } | ||
|
|
||
| // Extract Parameters sections | ||
| if (extractParametersSection(filePath, dir)) { | ||
| paramsCount++; | ||
| } | ||
| } | ||
|
|
||
| console.log(`[extract-returns] Extracted ${returnsCount} Returns sections`); | ||
| console.log(`[extract-returns] Extracted ${paramsCount} Parameters sections`); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -56,7 +56,7 @@ | |||||
| "test:typedoc": "pnpm typedoc:generate && cd ./.typedoc && vitest run", | ||||||
| "turbo:clean": "turbo daemon clean", | ||||||
| "typedoc:generate": "pnpm build:declarations && pnpm typedoc:generate:skip-build", | ||||||
| "typedoc:generate:skip-build": "typedoc --tsconfig tsconfig.typedoc.json && rm -rf .typedoc/docs && mv .typedoc/temp-docs .typedoc/docs", | ||||||
| "typedoc:generate:skip-build": "typedoc --tsconfig tsconfig.typedoc.json && node .typedoc/extract-returns-and-params.mjs && rm -rf .typedoc/docs && mv .typedoc/temp-docs .typedoc/docs", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make script cross‑platform (avoid POSIX
Apply this diff: -"typedoc:generate:skip-build": "typedoc --tsconfig tsconfig.typedoc.json && node .typedoc/extract-returns-and-params.mjs && rm -rf .typedoc/docs && mv .typedoc/temp-docs .typedoc/docs",
+"typedoc:generate:skip-build": "typedoc --tsconfig tsconfig.typedoc.json && node .typedoc/extract-returns-and-params.mjs && rimraf .typedoc/docs && cpy \".typedoc/temp-docs/**\" .typedoc/docs --parents && rimraf .typedoc/temp-docs",📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| "version-packages": "changeset version && pnpm install --lockfile-only --engine-strict=false", | ||||||
| "version-packages:canary": "./scripts/canary.mjs", | ||||||
| "version-packages:snapshot": "./scripts/snapshot.mjs", | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.