Generate prop documentation for Svelte components.
NOTE This is a work in progress. See the v0.1.0 project roadmap.
The aim of this project is to quickly generate documentation for a Svelte component given its exported properties. The output format could be text, markdown or JSON.
The easiest way to annotate a component property is to write a trailing comment.
In the following example, we know there are three possible values for kind
: "primary," "secondary" or "tertiary." We also know that "primary" is the default value.
<script>
export let kind = "primary"; // 'primary' | 'secondary' | 'tertiary'
</script>
As a compiler, svelte supports parsing and walking components as an AST. Therefore, it is straightforward to extract trailing comments for a writable variable declaration.
The input is a glob of svelte components. For each component:
let
) using the svelte.compile
APIsvelte.parse
APInpx hindsight 'src/**/*.svelte'
yarn add -D hindsight
yarn run hindsight 'src/**/*.svelte'
const hindsight = require("hindsight");
(async () => {
const types = await hindsight({ include: ["temp/**/*.{svelte,html}"] });
})();