-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
131 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script setup> | ||
|
||
import {data} from "./data/api.data"; | ||
|
||
</script> | ||
|
||
# API index | ||
|
||
## Methods | ||
|
||
<ul> | ||
<li v-for="[name, comment] in data.methods"> | ||
<span style="display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"><a href="#">{{ name }}</a> - {{ comment }}</span> | ||
</li> | ||
</ul> | ||
|
||
## Options | ||
|
||
<ul> | ||
<li v-for="[name, contexts] in data.options"> | ||
{{ name }} - {{ contexts.join(", ") }} | ||
</li> | ||
</ul> |
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,63 @@ | ||
import {rollups, sort} from "d3"; | ||
import {FunctionDeclaration, InterfaceDeclaration, Project} from "ts-morph"; | ||
|
||
// These interfaces tend to represent things that Plot constructs internally, | ||
// rather than objects that the user is expected to provide. | ||
function isInternalInterface(name) { | ||
return ( | ||
name === "AutoSpec" || | ||
name === "Channel" || | ||
name === "ChannelTransform" || | ||
name === "Context" || | ||
name === "Dimensions" || | ||
name === "Plot" || | ||
name === "Scale" | ||
); | ||
} | ||
|
||
export default { | ||
async load() { | ||
const project = new Project({tsConfigFilePath: "tsconfig.json"}); | ||
const allMethods: {name: string; comment: string | undefined}[] = []; | ||
const allOptions: {name: string; context: string}[] = []; | ||
for (const [name, declarations] of project.getSourceFile("src/index.d.ts")!.getExportedDeclarations()) { | ||
for (const declaration of declarations) { | ||
if (declaration instanceof FunctionDeclaration) { | ||
allMethods.push({ | ||
name: declaration.getName()!, | ||
comment: declaration | ||
.getJsDocs()[0] | ||
?.getDescription() | ||
.replace(/\n/g, " ") | ||
.replace(/[*_]/g, "") | ||
.replace(/[.:]($|\s+).*/g, "") | ||
.trim() | ||
}); | ||
} else if (declaration instanceof InterfaceDeclaration) { | ||
if (isInternalInterface(name)) continue; | ||
for (const property of declaration.getProperties()) { | ||
allOptions.push({name: property.getName(), context: name}); | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
methods: sort( | ||
rollups( | ||
allMethods, | ||
(D) => D.find((d) => d.comment)?.comment, | ||
(d) => d.name | ||
), | ||
([name]) => name | ||
), | ||
options: sort( | ||
rollups( | ||
allOptions, | ||
(D) => D.map((d) => d.context).sort(), | ||
(d) => d.name | ||
), | ||
([name]) => name | ||
) | ||
}; | ||
} | ||
}; |
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