-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simplify types * WIP document types * example jsdoc comment * extract types during build * fix link * silence typescript * run snippets through prettier * various style tweaks * small refactor * prevent self-linking * add types to sidebar * include types in search index * tweak docs * only show sub-sub-sections when on the page in question * fix header margins * remove unused properties * fix diffs while we're in here * links inside tooltips * remove jsdoc comments, for now * handle long comments * fix some tooltip UX * remove transition - apparently disrupts navigation. TODO investigate
- Loading branch information
1 parent
667a565
commit df6f126
Showing
17 changed files
with
416 additions
and
233 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,56 @@ | ||
import fs from 'fs'; | ||
import ts from 'typescript'; | ||
import prettier from 'prettier'; | ||
|
||
const code = fs.readFileSync('types/index.d.ts', 'utf-8'); | ||
const node = ts.createSourceFile('index.d.ts', code, ts.ScriptTarget.Latest); | ||
|
||
const types = []; | ||
|
||
for (const statement of node.statements) { | ||
if ( | ||
ts.isClassDeclaration(statement) || | ||
ts.isInterfaceDeclaration(statement) || | ||
ts.isTypeAliasDeclaration(statement) || | ||
ts.isModuleDeclaration(statement) | ||
) { | ||
// @ts-ignore no idea why it's complaining here | ||
const name = statement.name?.escapedText; | ||
|
||
let start = statement.pos; | ||
let comment = ''; | ||
|
||
// @ts-ignore i think typescript is bad at typescript | ||
if (statement.jsDoc) { | ||
// @ts-ignore | ||
comment = statement.jsDoc[0].comment; | ||
// @ts-ignore | ||
start = statement.jsDoc[0].end; | ||
} | ||
|
||
const i = code.indexOf('export', start); | ||
start = i + 6; | ||
|
||
const snippet = prettier.format(code.slice(start, statement.end).trim(), { | ||
parser: 'typescript', | ||
printWidth: 60, | ||
useTabs: true, | ||
singleQuote: true, | ||
trailingComma: 'none' | ||
}); | ||
|
||
types.push({ name, comment, snippet }); | ||
} | ||
} | ||
|
||
// should already be sorted, but just in case | ||
types.sort((a, b) => (a.name < b.name ? -1 : 1)); | ||
|
||
fs.writeFileSync( | ||
'../../documentation/types.js', | ||
` | ||
/* This file is generated by running \`node scripts/extract-types.js\` | ||
in the packages/kit directory — do not edit it */ | ||
export const types = ${JSON.stringify(types, null, ' ')}; | ||
`.trim() | ||
); |
This file contains 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 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 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.