-
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
Open
SarahSoutoul
wants to merge
60
commits into
main
Choose a base branch
from
ss/DOCS-10983
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
780cae5
Initial setup
SarahSoutoul 128df3c
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul a584905
Test
SarahSoutoul 8d2e9e2
Refactor typedoc
SarahSoutoul 70c5908
Bring back removed info
SarahSoutoul d49447e
Add missing code templating
SarahSoutoul 7b9b11b
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul b653539
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 3f1f920
Remove jsdocs changes to have in separate PR
SarahSoutoul 3cc87f9
Bring back session list
SarahSoutoul 64da460
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 16f9663
Fix setActive returns
SarahSoutoul febc294
Fix returns for useAuth
SarahSoutoul c32a435
Update the custom theme to get the useAuth options markdown generated…
NWylynko 263dba2
replace @unionInline with @embedType that covers more type inlining
NWylynko 316c861
Fix SetActive return after Nick fix
SarahSoutoul 40dbc8b
Add new extract returns and params script
NWylynko bc7873c
Add new extract returns and params script
NWylynko 2ebb4f2
Remove unwanted changes
SarahSoutoul 906c42c
Billing hooks jsdoc work
SarahSoutoul 113bb22
Refine useCheckout
SarahSoutoul d58bcbd
Add billing hooks params to files without headings
SarahSoutoul 3bde171
Fix some issues billing hooks
SarahSoutoul ecd1435
Additional fixes and clean up
SarahSoutoul 3262527
Clean up PR
SarahSoutoul 11d3506
Fix conflicts
SarahSoutoul 6bdc23d
Remove unnecessary comment
SarahSoutoul b6b7f80
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul f0ebf2e
Replace link
SarahSoutoul 1cfd43a
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 038c99d
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 45f698d
Changes post coderabbit feedback
SarahSoutoul 9f9ce0e
Add changeset
SarahSoutoul 4cd4165
Fix typo spotted by code rabbit
SarahSoutoul b1888f9
Fix build issues
SarahSoutoul 912fa9c
Fix headings for usePaymentElement
SarahSoutoul 5c29779
Fix added comments by formatter
SarahSoutoul 6b4f930
Simplify returns useSubscription
SarahSoutoul 9df0c27
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 9430645
Resolve coderabbit feedback
SarahSoutoul c0b8e19
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 32a4c45
Fix link useCheckout and types useSubscription
SarahSoutoul db76fb7
Refinements code rabbit feedback
SarahSoutoul 9ff65e9
Change finalize comment
SarahSoutoul a8c4ada
Change description useReverification for consistency
SarahSoutoul 9e4f120
Minor refinements code rabbit
SarahSoutoul 9b36954
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 3029aa3
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 623e24b
Fix useReverification generic parameter
SarahSoutoul b6e0a0e
fix formatting
SarahSoutoul 7c7ddb6
Fix build
SarahSoutoul 1996e7e
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 7b37cee
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 6afd559
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 7389079
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 574c180
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul 4e09572
switch from rm and mv to rimraf and cpy for cross platform development
NWylynko 5932883
output the -params.mdx and -return.mdx next to the source markdown fo…
NWylynko 9e58a57
Merge branch 'main' into ss/DOCS-10983
SarahSoutoul f5a92f9
Remove redundant
SarahSoutoul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| // @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 | ||
| * @returns {boolean} True if a file was created | ||
| */ | ||
| function extractParametersSection(filePath) { | ||
| const content = fs.readFileSync(filePath, 'utf-8'); | ||
| const fileName = path.basename(filePath, '.mdx'); | ||
| const dirName = path.dirname(filePath); | ||
|
|
||
| // 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(); | ||
| const processedParams = replaceGenericTypesInParamsTable(paramsContent); | ||
|
|
||
| // Write to new file | ||
| const newFilePath = path.join(dirName, targetFileName); | ||
| 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)) { | ||
| paramsCount++; | ||
| } | ||
| } | ||
|
|
||
| console.log(`[extract-returns] Extracted ${returnsCount} Returns sections`); | ||
| console.log(`[extract-returns] Extracted ${paramsCount} Parameters sections`); | ||
| } | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.