-
Notifications
You must be signed in to change notification settings - Fork 403
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 32 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
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,164 @@ | ||
| // @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; | ||
| } | ||
|
|
||
| /** | ||
| * 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'); | ||
|
|
||
| // 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'); | ||
|
|
||
| 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -57,7 +57,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", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,9 @@ interface ClerkAPIResponseOptions extends Omit<ClerkErrorParams, 'message' | 'co | |
| retryAfter?: number; | ||
| } | ||
|
|
||
| /** | ||
| * Interface representing a Clerk API Response Error. | ||
| */ | ||
|
Comment on lines
14
to
16
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. 🛠️ Refactor suggestion | 🟠 Major 🧩 Analysis chainJSDoc mismatch: refers to “Interface” but documents a class; enrich for Typedoc Replace the summary and add basic tags to align with the PR goal (Typedoc metadata). Apply this diff: -/**
- * Interface representing a Clerk API Response Error.
- */
+/**
+ * Class representing a Clerk API response error thrown when the Clerk API returns an error payload.
+ * @public
+ * @remarks Use `status`, `errors`, `clerkTraceId`, and `retryAfter` to inspect details.
+ * @see isClerkApiResponseError
+ */Additionally (outside this range), consider:
Example snippet: export class ClerkAPIResponseError extends ClerkError implements ClerkAPIResponseErrorInterface {
/** HTTP status code returned by the API. */
public status: number;
/** Unique trace identifier for support/debugging. */
public clerkTraceId?: string;
/** Retry-After value (in seconds) when rate limited or similar. */
public retryAfter?: number;
/** Parsed list of API errors. */
public errors: ClerkAPIError[];
/** Returns a stringified representation of this error. */
public toString(): string { /* unchanged body */ }
// Keeps message unformatted for backward compatibility
protected static override formatMessage(name: string, msg: string, _: string, __: string | undefined): string {
return msg;
}
}Please re-run your Typedoc flow (pnpm run typedoc:generate) to confirm the class and its members render with the updated descriptions, and that constructor params/fields appear as expected. As per coding guidelines. 🏁 Script executed: #!/bin/bash
file=$(fd clerkApiResponseError.ts)
echo "Found file: $file"
sed -n '1,30p' "$file"Length of output: 1203 🏁 Script executed: #!/bin/bash
file="packages/shared/src/errors/clerkApiResponseError.ts"
sed -n '30,100p' "$file"Length of output: 1081 Fix JSDoc header and document public API Replace at packages/shared/src/errors/clerkApiResponseError.ts (lines 15–17): -/**
- * Interface representing a Clerk API Response Error.
- */
+/**
+ * Class representing a Clerk API response error thrown when the Clerk API returns an error payload.
+ * @public
+ * @remarks Use `status`, `errors`, `clerkTraceId`, and `retryAfter` to inspect details.
+ * @see isClerkApiResponseError
+ */
🤖 Prompt for AI Agents |
||
| export class ClerkAPIResponseError extends ClerkError implements ClerkAPIResponseErrorInterface { | ||
| static name = 'ClerkAPIResponseError'; | ||
| status: number; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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:
Also applies to: 62-67, 87-90, 154-156
🤖 Prompt for AI Agents