-
Notifications
You must be signed in to change notification settings - Fork 391
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
Draft
SarahSoutoul
wants to merge
19
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.
Draft
Changes from all commits
Commits
Show all changes
19 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 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
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
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,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(); |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"$schema": "https://typedoc.org/schema.json", | ||
"entryPoints": ["./src/index.ts", "./src/experimental.ts"] | ||
"entryPoints": ["./src/index.ts", "./src/experimental.ts", "./src/hooks/*.{ts,tsx}"] | ||
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. Do you think we still need this? @NWylynko |
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ export type UseSignInReturn = | |
}; | ||
|
||
/** | ||
* @inline | ||
* @inline | ||
*/ | ||
export type UseSignUpReturn = | ||
| { | ||
|
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
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.
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.
This comment can go right? @NWylynko