@theholocron/astro-config 8.9.0-alpha.1 → 8.9.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/dist/index.d.ts +61 -1
- package/dist/index.js +37 -4
- package/package.json +18 -15
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Astro Config
|
|
2
2
|
|
|
3
|
-
An [Astro configuration](https://docs.astro.build/en/reference/configuration-reference/) factory for theholocron docs sites.
|
|
3
|
+
An [Astro configuration](https://docs.astro.build/en/reference/configuration-reference/) factory for the theholocron docs sites.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -61,9 +61,37 @@ export default defineConfig({
|
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
### API reference from TSDoc
|
|
65
|
+
|
|
66
|
+
`apiReference()` generates a package's API reference from its TSDoc comments each time the docs are built or served (nothing generated is committed). It returns a Starlight plugin and a sidebar group:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { apiReference, defineConfig } from "@theholocron/astro-config";
|
|
70
|
+
import { createStarlightTypeDocPlugin } from "starlight-typedoc";
|
|
71
|
+
|
|
72
|
+
const arrayUtils = apiReference({
|
|
73
|
+
createPlugin: createStarlightTypeDocPlugin,
|
|
74
|
+
root: new URL("./", import.meta.url),
|
|
75
|
+
package: "utils/array-utils",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export default defineConfig({
|
|
79
|
+
docs: {
|
|
80
|
+
name: "Utils",
|
|
81
|
+
github: "utils",
|
|
82
|
+
sidebar: [{ label: "array-utils", items: [{ label: "Overview", slug: "array-utils" }, arrayUtils.group] }],
|
|
83
|
+
},
|
|
84
|
+
plugins: [arrayUtils.plugin],
|
|
85
|
+
starlight,
|
|
86
|
+
docsTheme,
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`entryPoints` (default `["src/index.ts"]`, relative to the package), `label` (default "API reference") and `skipErrorChecking` (default `false`) are optional. Set `skipErrorChecking` for a package whose types come from sources TypeDoc cannot type-check on its own, such as this one's from Starlight; TypeDoc then does not stop the build on type errors. `starlight-typedoc` ships TypeScript source, so, like `starlight` and `docsTheme`, you import it in your own config and pass it in; install `starlight-typedoc`, `typedoc` and `typedoc-plugin-markdown` in the site.
|
|
91
|
+
|
|
64
92
|
## What it generates
|
|
65
93
|
|
|
66
|
-
- `site` — `https://theholocron.
|
|
94
|
+
- `site` — only when you pass it (for example `https://docs.theholocron.dev`); without it Starlight cannot generate a sitemap
|
|
67
95
|
- `base` — `/${docs.slug}`
|
|
68
96
|
- Starlight integration with the `@theholocron/docs-theme` plugin
|
|
69
97
|
- GitHub social link to `https://github.com/theholocron/${docs.slug}`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,80 @@
|
|
|
1
1
|
import { defineConfig as defineConfig$1 } from "astro/config";
|
|
2
2
|
import starlight from "@astrojs/starlight";
|
|
3
3
|
import { docsTheme } from "@theholocron/docs-theme";
|
|
4
|
+
import { createStarlightTypeDocPlugin } from "starlight-typedoc";
|
|
4
5
|
type StarlightSidebar = NonNullable<Parameters<typeof starlight>[0]["sidebar"]>;
|
|
6
|
+
type StarlightPlugins = NonNullable<Parameters<typeof starlight>[0]["plugins"]>;
|
|
7
|
+
/**
|
|
8
|
+
* The GitHub org a site's repo belongs to when `docs.org` is not given. This package is published with no dependency on
|
|
9
|
+
* the CLI and runs without a `holocron.config`, so it keeps its own one named default instead of a repeated literal.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_ORG = "theholocron";
|
|
12
|
+
/** The docs site's identity: its title, its GitHub repo name and its sidebar. */
|
|
5
13
|
export interface DocsConfig {
|
|
14
|
+
/** The site title Starlight shows (passed as Starlight's `title`). */
|
|
6
15
|
name: string;
|
|
16
|
+
/** The repo name under the GitHub org; builds the social link and the default `base` (`/<github>`). */
|
|
7
17
|
github: string;
|
|
18
|
+
/** The GitHub org that owns the repo. Defaults to {@link DEFAULT_ORG}. */
|
|
19
|
+
org?: string;
|
|
20
|
+
/** The Starlight sidebar definition, passed to Starlight unchanged. */
|
|
8
21
|
sidebar: StarlightSidebar;
|
|
9
22
|
}
|
|
23
|
+
/** Everything `defineConfig` needs to build the Astro config for a Starlight docs site. */
|
|
10
24
|
export interface DocsConfigInput {
|
|
25
|
+
/** The docs site's name, repo and sidebar. */
|
|
11
26
|
docs: DocsConfig;
|
|
27
|
+
/** The `starlight` integration, imported by the site's own config so Astro's loader handles it. */
|
|
12
28
|
starlight: typeof starlight;
|
|
29
|
+
/** The `docsTheme` Starlight plugin from `@theholocron/docs-theme`, imported by the site's own config. */
|
|
13
30
|
docsTheme: typeof docsTheme;
|
|
31
|
+
/** Further Starlight plugins, added after the docs theme (for example the ones `apiReference()` returns). */
|
|
32
|
+
plugins?: StarlightPlugins;
|
|
33
|
+
/** Astro's `srcDir`. Omitted from the config when unset, so Astro's default (`./src`) applies. */
|
|
14
34
|
srcDir?: string;
|
|
35
|
+
/** Astro's `outDir`, the build output folder. Omitted from the config when unset, so Astro's default applies. */
|
|
15
36
|
outDir?: string;
|
|
37
|
+
/** Astro's `publicDir`, the folder of static assets. Omitted from the config when unset, so Astro's default applies. */
|
|
16
38
|
publicDir?: string;
|
|
39
|
+
/** Astro's `base`, the path the site is served under. Defaults to `/<docs.github>`. */
|
|
17
40
|
base?: string;
|
|
41
|
+
/** The site's absolute origin (for example `https://docs.theholocron.dev`). Starlight needs it to generate a sitemap. */
|
|
42
|
+
site?: string;
|
|
18
43
|
}
|
|
19
|
-
|
|
44
|
+
/** Builds the Astro config for a Starlight docs site: the docs theme, a GitHub social link, the React integration and an `@` alias to the docs source folder. */
|
|
45
|
+
export declare function defineConfig({ docs, starlight, docsTheme, plugins, srcDir, outDir, publicDir, base, site }: DocsConfigInput): ReturnType<typeof defineConfig$1>;
|
|
46
|
+
/** Options for `apiReference`. */
|
|
47
|
+
export interface ApiReferenceInput {
|
|
48
|
+
/** `createStarlightTypeDocPlugin` from your own `starlight-typedoc` import, as with `starlight` and `docsTheme`. */
|
|
49
|
+
createPlugin: typeof createStarlightTypeDocPlugin;
|
|
50
|
+
/** The repo root, as a URL or path: `new URL("./", import.meta.url)` from a config at the root. */
|
|
51
|
+
root: URL | string;
|
|
52
|
+
/** The package's folder from the repo root (`utils/array-utils`). */
|
|
53
|
+
package: string;
|
|
54
|
+
/** Entry points, relative to the package. Defaults to `src/index.ts`. */
|
|
55
|
+
entryPoints?: string[];
|
|
56
|
+
/** The sidebar group's label. Defaults to "API reference". */
|
|
57
|
+
label?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Tell TypeDoc not to stop on type errors. For a package whose types come from sources TypeDoc cannot check on its
|
|
60
|
+
* own (this package's, from Starlight); the build would otherwise fail on them. Defaults to `false`.
|
|
61
|
+
*/
|
|
62
|
+
skipErrorChecking?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** What `apiReference` returns: the Starlight plugin and the sidebar group that belong together. */
|
|
65
|
+
export interface ApiReference {
|
|
66
|
+
/** Add to `defineConfig({ plugins })`. */
|
|
67
|
+
plugin: StarlightPlugins[number];
|
|
68
|
+
/** Put in the sidebar where the reference should appear. */
|
|
69
|
+
group: StarlightSidebar[number];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The generated API reference of one package: its TSDoc comments, run through TypeDoc each time the docs are built
|
|
73
|
+
* or served, as pages under `<package>/api` and a collapsed sidebar group. Nothing generated is committed.
|
|
74
|
+
*
|
|
75
|
+
* `starlight-typedoc` ships TypeScript source, so, like `starlight` and `docsTheme`, it is imported by the site's
|
|
76
|
+
* own config and passed in, which keeps Astro's loader in charge of it. Install `starlight-typedoc`, `typedoc` and
|
|
77
|
+
* `typedoc-plugin-markdown` in the site.
|
|
78
|
+
*/
|
|
79
|
+
export declare function apiReference({ createPlugin, root, package: dir, entryPoints, label, skipErrorChecking }: ApiReferenceInput): ApiReference;
|
|
20
80
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
1
2
|
import react from "@astrojs/react";
|
|
2
3
|
import { defineConfig as defineConfig$1 } from "astro/config";
|
|
3
4
|
// index.ts
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The GitHub org a site's repo belongs to when `docs.org` is not given. This package is published with no dependency on
|
|
7
|
+
* the CLI and runs without a `holocron.config`, so it keeps its own one named default instead of a repeated literal.
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_ORG = "theholocron";
|
|
10
|
+
/** Builds the Astro config for a Starlight docs site: the docs theme, a GitHub social link, the React integration and an `@` alias to the docs source folder. */
|
|
11
|
+
function defineConfig({ docs, starlight, docsTheme, plugins, srcDir, outDir, publicDir, base, site }) {
|
|
5
12
|
return defineConfig$1({
|
|
13
|
+
...site && { site },
|
|
6
14
|
base: base ?? `/${docs.github}`,
|
|
7
15
|
...srcDir && { srcDir },
|
|
8
16
|
...outDir && { outDir },
|
|
@@ -10,14 +18,39 @@ function defineConfig({ docs, starlight, docsTheme, srcDir, outDir, publicDir, b
|
|
|
10
18
|
vite: { resolve: { alias: { "@": new URL(srcDir ?? "src", `file://${process.cwd()}/`).pathname } } },
|
|
11
19
|
integrations: [starlight({
|
|
12
20
|
title: docs.name,
|
|
13
|
-
plugins: [docsTheme()],
|
|
21
|
+
plugins: [docsTheme(), ...plugins ?? []],
|
|
14
22
|
social: [{
|
|
15
23
|
icon: "github",
|
|
16
24
|
label: "GitHub",
|
|
17
|
-
href: `https://github.com
|
|
25
|
+
href: `https://github.com/${docs.org ?? "theholocron"}/${docs.github}`
|
|
18
26
|
}],
|
|
19
27
|
sidebar: docs.sidebar
|
|
20
28
|
}), react()]
|
|
21
29
|
});
|
|
22
30
|
}
|
|
23
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The generated API reference of one package: its TSDoc comments, run through TypeDoc each time the docs are built
|
|
33
|
+
* or served, as pages under `<package>/api` and a collapsed sidebar group. Nothing generated is committed.
|
|
34
|
+
*
|
|
35
|
+
* `starlight-typedoc` ships TypeScript source, so, like `starlight` and `docsTheme`, it is imported by the site's
|
|
36
|
+
* own config and passed in, which keeps Astro's loader in charge of it. Install `starlight-typedoc`, `typedoc` and
|
|
37
|
+
* `typedoc-plugin-markdown` in the site.
|
|
38
|
+
*/
|
|
39
|
+
function apiReference({ createPlugin, root, package: dir, entryPoints = ["src/index.ts"], label = "API reference", skipErrorChecking = false }) {
|
|
40
|
+
const [plugin, group] = createPlugin();
|
|
41
|
+
const inPackage = (path) => fileURLToPath(new URL(`${dir}/${path}`, root));
|
|
42
|
+
return {
|
|
43
|
+
group,
|
|
44
|
+
plugin: plugin({
|
|
45
|
+
entryPoints: entryPoints.map(inPackage),
|
|
46
|
+
tsconfig: inPackage("tsconfig.json"),
|
|
47
|
+
output: `${dir}/api`,
|
|
48
|
+
sidebar: {
|
|
49
|
+
label,
|
|
50
|
+
collapsed: true
|
|
51
|
+
},
|
|
52
|
+
...skipErrorChecking ? { typeDoc: { skipErrorChecking: true } } : {}
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { DEFAULT_ORG, apiReference, defineConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/astro-config",
|
|
3
|
-
"version": "8.9.0-alpha.
|
|
3
|
+
"version": "8.9.0-alpha.15",
|
|
4
4
|
"description": "Astro configuration factory for theholocron docs sites.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -32,17 +32,20 @@
|
|
|
32
32
|
"dist/"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@astrojs/react": "^
|
|
36
|
-
"@astrojs/starlight": "^0.
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"react": "^19.
|
|
41
|
-
"
|
|
42
|
-
"tsdown": "^0.23.
|
|
35
|
+
"@astrojs/react": "^7.1.2",
|
|
36
|
+
"@astrojs/starlight": "^0.42.9",
|
|
37
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
38
|
+
"astro": "^7.4.5",
|
|
39
|
+
"react": "^19.3.1",
|
|
40
|
+
"react-dom": "^19.3.1",
|
|
41
|
+
"starlight-typedoc": "^0.23.2",
|
|
42
|
+
"tsdown": "^0.23.5",
|
|
43
|
+
"typedoc": "^0.28.20",
|
|
44
|
+
"typedoc-plugin-markdown": "^4.14.1",
|
|
43
45
|
"typescript": "^5.9.3",
|
|
44
|
-
"vitest": "^5.0
|
|
45
|
-
"@theholocron/
|
|
46
|
+
"vitest": "^5.1.0",
|
|
47
|
+
"@theholocron/docs-theme": "^1.11.0-alpha.2",
|
|
48
|
+
"@theholocron/tsconfig": "8.9.0-alpha.15"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
48
51
|
"@astrojs/react": ">=6.0.0",
|
|
@@ -57,10 +60,10 @@
|
|
|
57
60
|
"access": "public"
|
|
58
61
|
},
|
|
59
62
|
"scripts": {
|
|
60
|
-
"
|
|
61
|
-
"
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"lint:code": "eslint .",
|
|
65
|
+
"test:unit": "vitest run --coverage",
|
|
62
66
|
"test:watch": "vitest",
|
|
63
|
-
"
|
|
64
|
-
"verification.unitTests": "vitest run"
|
|
67
|
+
"typecheck": "tsc --noEmit"
|
|
65
68
|
}
|
|
66
69
|
}
|