@svelte-docgen/server
This package provides a simple HTTP server, to allow UI apps request on demand documentation data about Svelte component(s).
In the background, this server creates TypeScript Compiler API program instance (cached).
This solution prevents from necessity of starting a new program every time, given that the cold start of tsc
takes a time.
Server is powered by Hono with cross-runtime-friendly and optimization in mind.
Installation
Use your runtimeβs package manager of your choice.
For example (pnpm
for Node.js):
pnpm install --save-dev @svelte-docgen/server
}
Prerequisites
This package depends on the following packages (peer dependencies) to be existent in your project:
svelte
svelte-docgen
typescript
Usage
Depending on what runtime you want to use, the API for each of them should remain the same.
{@htmlimport createServer from "@svelte-docgen/<runtime-name>";
const server = createServer();
server.start();
// Implement your own logic to create requests...
// Below is an example for a single one:
const data = await server.request({
filepath: "./path/to/Component.svelte",
});
server.shutdown();
}
Bun
{@htmlimport createServer from "@svelte-docgen/bun";
const server = createServer(/* options */);
}
Options
Refer to Bun.serve()
documentation.
Only omit the field fetch
request handler.
Deno
{@htmlimport createServer from "@svelte-docgen/deno";
const server = createServer(/* options */);
}
Options
Refer to Deno.serve()
documentation.
Node
{@htmlimport createServer from "@svelte-docgen/node";
const server = createServer(/* options */);
}
Options
Refer to options of Hono serve()
documentation.
Only omit the field fetch
request handler.
Methods
start()
This allows you to start (server) the HTTP server instance.
request()
Options
Name | Required? | Description |
---|---|---|
filepath |
yes | Path to the *.svelte component file. |
source |
no | Svelte component source code. You can read the component file by yourself, so the server will skip attempt to read the source - synchronously. |
keys |
no | Pick specific keys from the ParsedComponent to be generated. |
shutdown()
Gracefully shutdown the HTTP server instance.