-
Notifications
You must be signed in to change notification settings - Fork 343
Auto-generate experimental warnings and usage docs for typekits from library metadata #9564
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 all commits
ecd4435
b002ac5
0e0dc1e
f6c5749
aa2b623
7b6e19e
27e2db9
cb879ff
22f90fe
f88c271
1bd3d39
e5d4397
02c2ea8
8329284
55ff5d7
f454442
499a3a7
5bb12a1
5b5706c
584f40f
843912c
882add9
eeb575d
a1b68fe
4717332
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 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/tspd" | ||
| --- | ||
|
|
||
| Auto-generate experimental warnings and usage documentation for typekits |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: internal | ||
| packages: | ||
| - "@typespec/http" | ||
| --- | ||
|
|
||
| Provide example usage of the experimental typekit in reference documentation | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,16 +12,68 @@ import { format as prettierFormat } from "prettier"; | |
| import { TypekitCollection } from "../typekit-docs.js"; | ||
| import { TypekitSection } from "./typekit-section.js"; | ||
|
|
||
| export function createTypekitDocs(typekit: TypekitCollection) { | ||
| export function createTypekitDocs(typekit: TypekitCollection, packageName: string) { | ||
| const isCompilerPackage = packageName === "@typespec/compiler"; | ||
|
|
||
| // Construct import path: for experimental typekits, use /experimental/typekit pattern | ||
| const typekitImportPath = typekit.isExperimental | ||
| ? `${packageName}/experimental/typekit` | ||
| : `${packageName}/typekit`; | ||
|
|
||
| // Build import statements for code blocks | ||
| const registrationImport = | ||
| typekit.isExperimental && !isCompilerPackage ? `import "${typekitImportPath}";\n` : ""; | ||
| const typekitImport = `import { $ } from "@typespec/compiler/typekit";`; | ||
|
|
||
| // Build explanation text | ||
| const sideEffectsExplanation = | ||
| typekit.isExperimental && !isCompilerPackage | ||
| ? "\n\nThe first import registers the typekit extensions. This import only needs to exist once in your compilation as only its side effects are important." | ||
| : ""; | ||
|
|
||
| const jsxContent = ( | ||
| <Output> | ||
| <md.SourceFile path={`typekits.mdx`}> | ||
| <> | ||
| <md.Frontmatter jsValue={{ title: "[API] Typekits" }} /> | ||
| {code` | ||
| import { Badge } from '@astrojs/starlight/components'; | ||
| import { Badge${typekit.isExperimental ? ", Aside" : ""} } from '@astrojs/starlight/components'; | ||
| `} | ||
| </> | ||
| {typekit.isExperimental && ( | ||
|
Contributor
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. This is still too complex and difficult to read. It should be possible to simplify the logic if the text of the pre-import and post-import documentation is conditional, instead of making large conditional code blocks.
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. Done (commit 4717332). Simplified the logic by extracting conditional text to variables ( |
||
| <> | ||
| {code` | ||
|
|
||
| <Aside type="caution"> | ||
markcowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| **Experimental Feature**: These typekits are currently experimental. The API surface is volatile and may have breaking changes without notice. Use with caution in production environments. | ||
| </Aside> | ||
| `} | ||
| </> | ||
| )} | ||
| {!isCompilerPackage && ( | ||
| <> | ||
| {code` | ||
|
|
||
| To use these typekits in your TypeSpec emitter or tool, you need to import the typekit module: | ||
markcowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| \`\`\`ts | ||
| ${registrationImport}${typekitImport} | ||
| \`\`\`${sideEffectsExplanation} | ||
| `} | ||
| </> | ||
| )} | ||
| {isCompilerPackage && ( | ||
| <> | ||
| {code` | ||
|
|
||
| To use these typekits in your TypeSpec emitter or tool, you need to import the typekit module: | ||
markcowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| \`\`\`ts | ||
| ${typekitImport} | ||
| \`\`\` | ||
| `} | ||
| </> | ||
| )} | ||
| <md.Section> | ||
| <For each={Object.values(typekit.namespaces)}> | ||
| {(x) => <TypekitSection typekit={x} />} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.