-
Notifications
You must be signed in to change notification settings - Fork 402
chore(shared,clerk-react,types): Improve Typedoc #5372
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
Changes from all commits
5379b24
3021340
b72434e
896a794
f600257
f44dbc5
f108423
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,7 @@ | ||
| --- | ||
| '@clerk/shared': patch | ||
| '@clerk/clerk-react': patch | ||
| '@clerk/types': patch | ||
| --- | ||
|
|
||
| Improve JSDoc documentation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,43 @@ | ||
| // @ts-check | ||
| import { MarkdownRendererEvent } from 'typedoc-plugin-markdown'; | ||
| import { MarkdownPageEvent, MarkdownRendererEvent } from 'typedoc-plugin-markdown'; | ||
|
|
||
| /** | ||
| * A list of files where we want to remove any headings | ||
| */ | ||
| const FILES_WITHOUT_HEADINGS = [ | ||
| 'use-organization-return.mdx', | ||
| 'use-organization-params.mdx', | ||
| 'paginated-resources.mdx', | ||
| 'pages-or-infinite-options.mdx', | ||
| 'pages-or-infinite-options.mdx', | ||
| 'paginated-hook-config.mdx', | ||
| 'use-organization-list-return.mdx', | ||
| 'use-organization-list-params.mdx', | ||
| ]; | ||
|
|
||
| /** | ||
| * An array of tuples where the first element is the file name and the second element is the new path. | ||
| */ | ||
| const LINK_REPLACEMENTS = [ | ||
|
Contributor
Author
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. Sometimes there are relative links like |
||
| ['clerk-paginated-response', '/docs/references/javascript/types/clerk-paginated-response'], | ||
| ['paginated-resources', '#paginated-resources'], | ||
| ]; | ||
|
|
||
| /** | ||
| * Inside the generated MDX files are links to other generated MDX files. These relative links need to be replaced with absolute links to pages that exist on clerk.com. | ||
| * For example, `[Foobar](../../foo/bar.mdx)` needs to be replaced with `[Foobar](/docs/foo/bar)`. | ||
| * It also shouldn't matter how level deep the relative link is. | ||
| * | ||
| * This function returns an array of `{ pattern: string, replace: string }` to pass into the `typedoc-plugin-replace-text` plugin. | ||
| */ | ||
| function getRelativeLinkReplacements() { | ||
| return LINK_REPLACEMENTS.map(([fileName, newPath]) => { | ||
| return { | ||
| pattern: new RegExp(`\\((?:\\.{1,2}\\/)+.*?${fileName}\\.mdx\\)`, 'g'), | ||
| replace: `(${newPath})`, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} str | ||
|
|
@@ -13,8 +51,9 @@ function toKebabCase(str) { | |
| */ | ||
| export function load(app) { | ||
| app.renderer.on(MarkdownRendererEvent.BEGIN, output => { | ||
| // Do not output README.mdx files | ||
| // Modify the output object | ||
| output.urls = output.urls | ||
| // Do not output README.mdx files | ||
| ?.filter(e => !e.url.endsWith('README.mdx')) | ||
| .map(e => { | ||
| // Convert URLs (by default camelCase) to kebab-case | ||
|
|
@@ -23,7 +62,37 @@ export function load(app) { | |
| e.url = kebabUrl; | ||
| e.model.url = kebabUrl; | ||
|
|
||
| /** | ||
| * For the `@clerk/shared` package it outputs the hooks as for example: shared/react/hooks/use-clerk/functions/use-clerk.mdx. | ||
| * It also places the interfaces as shared/react/hooks/use-organization/interfaces/use-organization-return.mdx | ||
| * Group all those .mdx files under shared/react/hooks | ||
| */ | ||
| if (e.url.includes('shared/react/hooks')) { | ||
| e.url = e.url.replace(/\/[^/]+\/(functions|interfaces)\//, '/'); | ||
| e.model.url = e.url; | ||
| } | ||
|
|
||
| return e; | ||
| }); | ||
| }); | ||
|
|
||
| app.renderer.on(MarkdownPageEvent.END, output => { | ||
| const fileName = output.url.split('/').pop(); | ||
| const linkReplacements = getRelativeLinkReplacements(); | ||
|
|
||
| for (const { pattern, replace } of linkReplacements) { | ||
| if (output.contents) { | ||
| output.contents = output.contents.replace(pattern, replace); | ||
| } | ||
| } | ||
|
|
||
| if (fileName) { | ||
| if (FILES_WITHOUT_HEADINGS.includes(fileName)) { | ||
| if (output.contents) { | ||
| // Remove any headings from the file, irrespective of the level | ||
| output.contents = output.contents.replace(/^#+\s.+/gm, ''); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "tabWidth": 2, | ||
| "semi": false, | ||
| "singleQuote": true, | ||
| "printWidth": 120, | ||
| "useTabs": false, | ||
| "bracketSpacing": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| /*/ | ||
| !/src/ | ||
| !/docs/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <!-- #region nextjs-01 --> | ||
|
|
||
| ```tsx {{ filename: 'app/external-data/page.tsx' }} | ||
| 'use client'; | ||
|
|
||
| import { useAuth } from '@clerk/nextjs'; | ||
|
|
||
| export default function ExternalDataPage() { | ||
| const { userId, sessionId, getToken, isLoaded, isSignedIn } = useAuth(); | ||
|
|
||
| const fetchExternalData = async () => { | ||
| const token = await getToken(); | ||
|
|
||
| // Fetch data from an external API | ||
| const response = await fetch('https://api.example.com/data', { | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| }, | ||
| }); | ||
|
|
||
| return response.json(); | ||
| }; | ||
|
|
||
| if (!isLoaded) { | ||
| return <div>Loading...</div>; | ||
| } | ||
|
|
||
| if (!isSignedIn) { | ||
| return <div>Sign in to view this page</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <p> | ||
| Hello, {userId}! Your current active session is {sessionId}. | ||
| </p> | ||
| <button onClick={fetchExternalData}>Fetch Data</button> | ||
| </div> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| <!-- #endregion nextjs-01 --> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!-- #region nextjs-01 --> | ||
|
|
||
| ```tsx {{ filename: 'app/sign-in/page.tsx' }} | ||
| 'use client'; | ||
|
|
||
| import { useSignIn } from '@clerk/nextjs'; | ||
|
|
||
| export default function SignInPage() { | ||
| const { isLoaded, signIn } = useSignIn(); | ||
|
|
||
| if (!isLoaded) { | ||
| // Handle loading state | ||
| return null; | ||
| } | ||
|
|
||
| return <div>The current sign-in attempt status is {signIn?.status}.</div>; | ||
| } | ||
| ``` | ||
|
|
||
| <!-- #endregion nextjs-01 --> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!-- #region nextjs-01 --> | ||
|
|
||
| ```tsx {{ filename: 'app/sign-up/page.tsx' }} | ||
| 'use client'; | ||
|
|
||
| import { useSignUp } from '@clerk/nextjs'; | ||
|
|
||
| export default function SignUpPage() { | ||
| const { isLoaded, signUp } = useSignUp(); | ||
|
|
||
| if (!isLoaded) { | ||
| // Handle loading state | ||
| return null; | ||
| } | ||
|
|
||
| return <div>The current sign-up attempt status is {signUp?.status}.</div>; | ||
| } | ||
| ``` | ||
|
|
||
| <!-- #endregion nextjs-01 --> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ import { createGetToken, createSignOut } from './utils'; | |
| * | ||
| * The following example demonstrates how to use the `useAuth()` hook to access the current auth state, like whether the user is signed in or not. It also includes a basic example for using the `getToken()` method to retrieve a session token for fetching data from an external resource. | ||
| * | ||
| * <Tabs items='React,Next.js'> | ||
|
Contributor
Author
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. If you use these MDX components (they are not resolved, just passed along) in such way, they won't be rendered in IntelliSense |
||
| * <Tab> | ||
| * | ||
| * ```tsx {{ filename: 'src/pages/ExternalDataPage.tsx' }} | ||
| * import { useAuth } from '@clerk/clerk-react' | ||
| * | ||
|
|
@@ -58,6 +61,14 @@ import { createGetToken, createSignOut } from './utils'; | |
| * ) | ||
| * } | ||
| * ``` | ||
| * | ||
| * </Tab> | ||
| * <Tab> | ||
| * | ||
| * {@include ../../docs/use-auth.md#nextjs-01} | ||
| * | ||
| * </Tab> | ||
| * </Tabs> | ||
| */ | ||
| export const useAuth = (initialAuthState: any = {}): UseAuthReturn => { | ||
| useAssertWrappedByClerkProvider('useAuth'); | ||
|
|
||
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.
Some of the files only contain the contents of a single interface.
For example:
# Parameters Table goes hereSo since I want to use the table contents as a partial/include somewhere else I need to get rid off the heading. But since I don't want to remove headings everywhere I'm removing them only from the files I want to use in such way.