@integr8-media/config 1.0.0 → 1.2.0
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 +280 -17
- package/biome/biome.json +52 -1
- package/dist/cli-DIsoGTED.mjs +2644 -0
- package/dist/registrySite.d.mts +959 -0
- package/dist/registrySite.mjs +3 -0
- package/dist/registrySiteBin.d.mts +1 -0
- package/dist/registrySiteBin.mjs +5 -0
- package/dist/tsdown.d.mts +16 -3
- package/dist/tsdown.mjs +17 -4
- package/dist/vitest.d.mts +10 -3
- package/dist/vitest.mjs +18 -3
- package/lefthook/base.yml +0 -3
- package/package.json +9 -2
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
import { n as ConfigErrorCode, t as ConfigError } from "./configError-DPT5pJ9Z.mjs";
|
|
2
|
+
import { Server } from "node:http";
|
|
3
|
+
/** A file of a registry item. */
|
|
4
|
+
interface RegistryFile {
|
|
5
|
+
path: string;
|
|
6
|
+
type?: string | undefined;
|
|
7
|
+
/** Where the file lands in a shadcn project. */
|
|
8
|
+
target?: string | undefined;
|
|
9
|
+
/** The file's text. Left out of `registry.json`, present in `<name>.json`. */
|
|
10
|
+
content?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** An entry of `registry.json`. */
|
|
13
|
+
interface RegistryIndexItem {
|
|
14
|
+
name: string;
|
|
15
|
+
/** For example `registry:ui`. */
|
|
16
|
+
type: string;
|
|
17
|
+
title?: string | undefined;
|
|
18
|
+
description?: string | undefined;
|
|
19
|
+
categories?: string[] | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** `registry.json`. */
|
|
22
|
+
interface RegistryIndex {
|
|
23
|
+
/** The package name. */
|
|
24
|
+
name: string;
|
|
25
|
+
items: RegistryIndexItem[];
|
|
26
|
+
}
|
|
27
|
+
/** A full item (`<name>.json`), with file contents. */
|
|
28
|
+
interface RegistryItem extends RegistryIndexItem {
|
|
29
|
+
dependencies?: string[] | undefined;
|
|
30
|
+
/** Full URLs of the items it needs. */
|
|
31
|
+
registryDependencies?: string[] | undefined;
|
|
32
|
+
files?: RegistryFile[] | undefined;
|
|
33
|
+
/** Theme tokens added to the project's CSS. */
|
|
34
|
+
cssVars?: {
|
|
35
|
+
light?: Record<string, string>;
|
|
36
|
+
dark?: Record<string, string>;
|
|
37
|
+
} | undefined;
|
|
38
|
+
/** Rules and at-rules added to the project's CSS. */
|
|
39
|
+
css?: Record<string, unknown> | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** An `[id, label]` pair, for categories and preview themes. */
|
|
42
|
+
type SiteEntry = readonly [id: string, label: string];
|
|
43
|
+
/** Where the site's fonts come from. See {@link RegistrySiteConfig.fonts}. */
|
|
44
|
+
type SiteFonts = "copy-from-ui" | "build" | false;
|
|
45
|
+
/** Texts and links that make the site look like this package's. */
|
|
46
|
+
interface SiteBrand {
|
|
47
|
+
/** Product name, for example `Integr8 Window Manager`. Used in titles and labels. Required. */
|
|
48
|
+
name: string;
|
|
49
|
+
/**
|
|
50
|
+
* Shown after `integr8/` in the header, for example `window-manager`. Defaults to the name
|
|
51
|
+
* without a leading "Integr8", in kebab-case.
|
|
52
|
+
*/
|
|
53
|
+
slug?: string | undefined;
|
|
54
|
+
/** Two letters in the header badge. Defaults to `i8`. */
|
|
55
|
+
mark?: string | undefined;
|
|
56
|
+
/** Small text above the hero title; the version is added (`Window manager · v1.0.0`). Defaults to `Registry`. */
|
|
57
|
+
eyebrow?: string | undefined;
|
|
58
|
+
/** Hero title. Defaults to `name`. */
|
|
59
|
+
heroTitle?: string | undefined;
|
|
60
|
+
/** The last words of the hero title, in the brand gradient (for example `inside your React app.`). */
|
|
61
|
+
heroAccent?: string | undefined;
|
|
62
|
+
/** Text under the hero title. Defaults to the `description` of `package.json`. */
|
|
63
|
+
lead?: string | undefined;
|
|
64
|
+
/** The page `<title>` of the landing page. Defaults to `name`. */
|
|
65
|
+
title?: string | undefined;
|
|
66
|
+
/** The meta description. Defaults to the `description` of `package.json`. */
|
|
67
|
+
description?: string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* First part of the footer. `{packageName}` and `{version}` are filled in.
|
|
70
|
+
* Defaults to `{packageName} · v{version}`.
|
|
71
|
+
*/
|
|
72
|
+
footer?: string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Link to the source repository. Defaults to `https://github.com/$GITHUB_REPOSITORY`, else
|
|
75
|
+
* the `repository` of `package.json`.
|
|
76
|
+
*/
|
|
77
|
+
repositoryUrl?: string | undefined;
|
|
78
|
+
/** Add a "Playground" link to the header (it opens the Ladle playground). Defaults to `false`. */
|
|
79
|
+
playgroundLink?: boolean | undefined;
|
|
80
|
+
/** Extra numbers in the hero, after the component count (for example `{ value: '5', label: 'themes' }`). */
|
|
81
|
+
extraStats?: readonly {
|
|
82
|
+
value: string;
|
|
83
|
+
label: string;
|
|
84
|
+
}[] | undefined;
|
|
85
|
+
/** Command in the hero. Defaults to the command of the last setup step. */
|
|
86
|
+
heroCommand?: string | undefined;
|
|
87
|
+
}
|
|
88
|
+
/** One numbered step in "Get started". */
|
|
89
|
+
interface SiteSetupStep {
|
|
90
|
+
title: string;
|
|
91
|
+
/** Inline Markdown (`code`, **bold**, [links](https://x.dev)). */
|
|
92
|
+
text?: string | undefined;
|
|
93
|
+
/** The copyable command. */
|
|
94
|
+
command: string;
|
|
95
|
+
}
|
|
96
|
+
/** A card with a code sample under the steps. */
|
|
97
|
+
interface SiteSetupExtra {
|
|
98
|
+
title: string;
|
|
99
|
+
/** Inline Markdown. */
|
|
100
|
+
text?: string | undefined;
|
|
101
|
+
code: string;
|
|
102
|
+
/** Label above the code, for example a file name. */
|
|
103
|
+
caption?: string | undefined;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The "Get started" section. Texts, commands and code may use `{registryUrl}`,
|
|
107
|
+
* `{uiRegistryUrl}`, `{version}` and `{packageName}`; any other `{...}` stays as written
|
|
108
|
+
* (so `{name}` in a `components.json` sample is kept).
|
|
109
|
+
*/
|
|
110
|
+
interface SiteSetup {
|
|
111
|
+
/** Heading before the accent. Defaults to `<Three> commands to` (from the step count). */
|
|
112
|
+
title?: string | undefined;
|
|
113
|
+
/** Gradient part of the heading. Defaults to `your first screen.` */
|
|
114
|
+
accent?: string | undefined;
|
|
115
|
+
/** Text under the heading. */
|
|
116
|
+
lead?: string | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The steps. Defaults to: set up shadcn, add the ui theme (when `ui` is set), add the first
|
|
119
|
+
* item of the registry.
|
|
120
|
+
*/
|
|
121
|
+
steps?: readonly SiteSetupStep[] | undefined;
|
|
122
|
+
/** Cards after the steps, for example an app example. */
|
|
123
|
+
extras?: readonly SiteSetupExtra[] | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* The registry alias for `components.json`, for example `@integr8-wm`. Defaults to `@integr8`,
|
|
126
|
+
* or `@integr8-<slug>` when `ui` is set (the ui registry then has `@integr8`).
|
|
127
|
+
*/
|
|
128
|
+
namespace?: string | undefined;
|
|
129
|
+
/** Add the "Shorter names" card (the `components.json` registry setting). Defaults to `true`. */
|
|
130
|
+
shortNames?: boolean | undefined;
|
|
131
|
+
}
|
|
132
|
+
/** Longer texts of the landing page. Each has a default. */
|
|
133
|
+
interface SiteCopy {
|
|
134
|
+
/** Text under "See it before you copy it." */
|
|
135
|
+
previewLead?: string | undefined;
|
|
136
|
+
/** Text under "Everything in the kit." */
|
|
137
|
+
componentsLead?: string | undefined;
|
|
138
|
+
}
|
|
139
|
+
/** The ui registry, when the items depend on it. Leave `ui` out in the ui package itself. */
|
|
140
|
+
interface SiteUi {
|
|
141
|
+
/** Where the ui registry JSON files are served, for example `https://host/integr8-ui/r`. */
|
|
142
|
+
registryUrl: string;
|
|
143
|
+
/** Where the ui item pages are. Defaults to the registry URL without `/r`, plus `/components/`. */
|
|
144
|
+
docsUrl?: string | undefined;
|
|
145
|
+
/** The ui package name, for the fonts copy. Defaults to `@integr8-media/ui`. */
|
|
146
|
+
packageName?: string | undefined;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Which Ladle stories show which item: a map of item name to parts of story ids (Ladle ids look
|
|
150
|
+
* like `components--window-default`; a story matches when its id contains a part), or a function
|
|
151
|
+
* that returns the parts for an item. Items without parts have no live preview.
|
|
152
|
+
*/
|
|
153
|
+
type SiteStories = Readonly<Record<string, readonly string[]>> | ((itemName: string) => readonly string[] | undefined);
|
|
154
|
+
/** Settings of the bundle-size breakdown (`integr8-registry-site size`). */
|
|
155
|
+
interface SiteBundleSizes {
|
|
156
|
+
/** The built entry to measure, relative to the repo root. Defaults to `dist/index.mjs`. */
|
|
157
|
+
entry?: string | undefined;
|
|
158
|
+
/** Label for this package's own code in the tables. Defaults to `<package name> (dist)`. */
|
|
159
|
+
ownCodeLabel?: string | undefined;
|
|
160
|
+
/** Packages the app provides, left out of the measure. Defaults to React and React DOM. */
|
|
161
|
+
external?: readonly string[] | undefined;
|
|
162
|
+
}
|
|
163
|
+
/** The commands `integr8-registry-site build` runs before it renders the pages. */
|
|
164
|
+
interface SiteCommands {
|
|
165
|
+
/** Builds fonts (needed with `fonts: 'build'`), for example `node scripts/buildAssets.mjs`. Runs first. */
|
|
166
|
+
assets?: string | undefined;
|
|
167
|
+
/** Builds the registry JSON into `dist/registry/`. Defaults to `node scripts/buildRegistry.mjs`. */
|
|
168
|
+
registry?: string | undefined;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The per-repo configuration of the registry site: the file `registry/site.config.mjs`.
|
|
172
|
+
* Only `brand.name` is required.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```js
|
|
176
|
+
* // registry/site.config.mjs
|
|
177
|
+
* import { defineRegistrySite } from '@integr8-media/config/registry-site';
|
|
178
|
+
*
|
|
179
|
+
* export default defineRegistrySite({
|
|
180
|
+
* brand: { name: 'Integr8 Window Manager', slug: 'window-manager' },
|
|
181
|
+
* categories: [['shell', 'Shell'], ['window', 'Windows']],
|
|
182
|
+
* ui: { registryUrl: 'https://minalouisleon.github.io/integr8-ui/r' },
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
interface RegistrySiteConfig {
|
|
187
|
+
/** Names, texts and links. */
|
|
188
|
+
brand: SiteBrand;
|
|
189
|
+
/**
|
|
190
|
+
* Item groups in page order, as `[id, label]` pairs matched against each item's first registry
|
|
191
|
+
* category. Items in no group go last under "Other". Defaults to the categories found in the
|
|
192
|
+
* registry, in order of first appearance.
|
|
193
|
+
*/
|
|
194
|
+
categories?: readonly SiteEntry[] | undefined;
|
|
195
|
+
/** Which stories preview which item. Defaults to the stories whose id starts with `<item>--`. */
|
|
196
|
+
stories?: SiteStories | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* The story shown first in the landing page's live preview: an item name (its first story) or
|
|
199
|
+
* a story id. Defaults to the first story.
|
|
200
|
+
*/
|
|
201
|
+
defaultStory?: string | undefined;
|
|
202
|
+
/** The ui registry. Leave out in the ui package itself. */
|
|
203
|
+
ui?: SiteUi | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Fonts of the site: `'copy-from-ui'` copies `dist/fonts.css` and `dist/fonts/` from the
|
|
206
|
+
* installed ui package (needs `ui`), `'build'` copies the ones this repo built into `dist/`,
|
|
207
|
+
* `false` uses system fonts. Defaults to `'copy-from-ui'` with `ui`, else `false`.
|
|
208
|
+
*/
|
|
209
|
+
fonts?: SiteFonts | undefined;
|
|
210
|
+
/** The "Get started" section. */
|
|
211
|
+
setup?: SiteSetup | undefined;
|
|
212
|
+
/** Longer landing page texts. */
|
|
213
|
+
copy?: SiteCopy | undefined;
|
|
214
|
+
/** Themes the live preview can switch between, as `[id, label]` pairs. Leave out for no switcher. */
|
|
215
|
+
previewThemes?: readonly SiteEntry[] | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* The "add the theme first" note on item pages: `{ item }` names the theme item, `skip` lists
|
|
218
|
+
* items without the note. Defaults to the ui theme when `ui` is set, else no note.
|
|
219
|
+
*/
|
|
220
|
+
themeNote?: {
|
|
221
|
+
item: string;
|
|
222
|
+
skip?: readonly string[] | undefined;
|
|
223
|
+
} | false | undefined;
|
|
224
|
+
/** Bundle-size breakdown for `integr8-registry-site size`. Off unless set. */
|
|
225
|
+
bundleSizes?: SiteBundleSizes | false | undefined;
|
|
226
|
+
/** Build steps. */
|
|
227
|
+
commands?: SiteCommands | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* Where the registry JSON files are served; `{name}` and `{version}` are filled in. The
|
|
230
|
+
* `REGISTRY_BASE_URL` variable wins. Defaults to the GitHub Pages URL of the repository.
|
|
231
|
+
*/
|
|
232
|
+
registryUrl?: string | undefined;
|
|
233
|
+
/** Build the Ladle playground and embed it. Defaults to `true`. */
|
|
234
|
+
playground?: boolean | undefined;
|
|
235
|
+
}
|
|
236
|
+
/** The facts of `package.json` the site needs. */
|
|
237
|
+
interface SitePackage {
|
|
238
|
+
name: string;
|
|
239
|
+
version: string;
|
|
240
|
+
description?: string | undefined;
|
|
241
|
+
repository?: string | {
|
|
242
|
+
url?: string | undefined;
|
|
243
|
+
} | undefined;
|
|
244
|
+
}
|
|
245
|
+
/** Environment variables the site reads (`GITHUB_REPOSITORY`, `REGISTRY_BASE_URL`). */
|
|
246
|
+
type SiteEnv = Readonly<Record<string, string | undefined>>;
|
|
247
|
+
/** A {@link RegistrySiteConfig} with every default filled in. */
|
|
248
|
+
interface ResolvedSiteConfig {
|
|
249
|
+
brand: {
|
|
250
|
+
name: string;
|
|
251
|
+
slug: string;
|
|
252
|
+
mark: string;
|
|
253
|
+
eyebrow: string;
|
|
254
|
+
heroTitle: string;
|
|
255
|
+
heroAccent: string;
|
|
256
|
+
lead: string;
|
|
257
|
+
title: string;
|
|
258
|
+
description: string;
|
|
259
|
+
footer: string;
|
|
260
|
+
repositoryUrl: string | undefined;
|
|
261
|
+
playgroundLink: boolean;
|
|
262
|
+
extraStats: readonly {
|
|
263
|
+
value: string;
|
|
264
|
+
label: string;
|
|
265
|
+
}[];
|
|
266
|
+
heroCommand: string | undefined;
|
|
267
|
+
};
|
|
268
|
+
categories: readonly SiteEntry[] | undefined;
|
|
269
|
+
stories: SiteStories | undefined;
|
|
270
|
+
defaultStory: string | undefined;
|
|
271
|
+
ui: {
|
|
272
|
+
registryUrl: string;
|
|
273
|
+
docsUrl: string;
|
|
274
|
+
packageName: string;
|
|
275
|
+
} | undefined;
|
|
276
|
+
fonts: SiteFonts;
|
|
277
|
+
setup: {
|
|
278
|
+
title: string | undefined;
|
|
279
|
+
accent: string;
|
|
280
|
+
lead: string;
|
|
281
|
+
steps: readonly SiteSetupStep[] | undefined;
|
|
282
|
+
extras: readonly SiteSetupExtra[];
|
|
283
|
+
namespace: string;
|
|
284
|
+
shortNames: boolean;
|
|
285
|
+
};
|
|
286
|
+
copy: {
|
|
287
|
+
previewLead: string | undefined;
|
|
288
|
+
componentsLead: string;
|
|
289
|
+
};
|
|
290
|
+
previewThemes: readonly SiteEntry[];
|
|
291
|
+
themeNote: {
|
|
292
|
+
item: string;
|
|
293
|
+
skip: readonly string[];
|
|
294
|
+
external: boolean;
|
|
295
|
+
} | undefined;
|
|
296
|
+
bundleSizes: {
|
|
297
|
+
entry: string;
|
|
298
|
+
ownCodeLabel: string;
|
|
299
|
+
external: readonly string[];
|
|
300
|
+
} | undefined;
|
|
301
|
+
commands: {
|
|
302
|
+
assets: string | undefined;
|
|
303
|
+
registry: string;
|
|
304
|
+
};
|
|
305
|
+
registryUrl: string | undefined;
|
|
306
|
+
playground: boolean;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Checks a site config and returns it. Use it in `registry/site.config.mjs` to get early,
|
|
310
|
+
* readable errors and editor hints.
|
|
311
|
+
*
|
|
312
|
+
* @param config - The config object.
|
|
313
|
+
* @returns The same config, typed.
|
|
314
|
+
* @throws {@link ConfigError} with code `INVALID_OPTION`, naming the option and what is wrong
|
|
315
|
+
* (a missing `brand.name`, an unknown option, `fonts: 'copy-from-ui'` without `ui`, a repeated
|
|
316
|
+
* category id, and so on).
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```js
|
|
320
|
+
* export default defineRegistrySite({ brand: { name: 'Integr8 Forms' } });
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
export declare function defineRegistrySite(config: RegistrySiteConfig): RegistrySiteConfig;
|
|
324
|
+
/**
|
|
325
|
+
* The URL the registry JSON files are served from, without a trailing slash. The
|
|
326
|
+
* `REGISTRY_BASE_URL` variable wins over `registryUrl` in the config; without either, it is the
|
|
327
|
+
* GitHub Pages URL of the `repository` in `package.json`.
|
|
328
|
+
*
|
|
329
|
+
* @param configured - `registryUrl` from the site config.
|
|
330
|
+
* @param pkg - Name, version and repository of the package.
|
|
331
|
+
* @param env - Environment variables.
|
|
332
|
+
* @returns The folder URL, for example `https://owner.github.io/repo/r`.
|
|
333
|
+
* @throws {@link ConfigError} with code `INVALID_OPTION` when none of the three gives a URL.
|
|
334
|
+
*/
|
|
335
|
+
export declare function resolveRegistryUrl(configured: string | undefined, pkg: SitePackage, env: SiteEnv): string;
|
|
336
|
+
/**
|
|
337
|
+
* The folder where the ui item pages are: the ui registry URL without a trailing `/r`, then
|
|
338
|
+
* `components/`.
|
|
339
|
+
*
|
|
340
|
+
* @param registryUrl - The ui registry URL.
|
|
341
|
+
* @returns A URL ending with `/`.
|
|
342
|
+
*/
|
|
343
|
+
export declare function uiDocsUrlOf(registryUrl: string): string;
|
|
344
|
+
/**
|
|
345
|
+
* Validates a site config and fills in every default.
|
|
346
|
+
*
|
|
347
|
+
* @param config - The repo's config.
|
|
348
|
+
* @param context - `package.json` facts and the environment (default: the process environment).
|
|
349
|
+
* @returns The full config the renderers use.
|
|
350
|
+
* @throws {@link ConfigError} with code `INVALID_OPTION` for bad input.
|
|
351
|
+
*/
|
|
352
|
+
export declare function resolveSiteConfig(config: RegistrySiteConfig, context: {
|
|
353
|
+
pkg: SitePackage;
|
|
354
|
+
env?: SiteEnv | undefined;
|
|
355
|
+
}): ResolvedSiteConfig;
|
|
356
|
+
/** A Ladle story as shown on a page. */
|
|
357
|
+
interface LadleStory {
|
|
358
|
+
id: string;
|
|
359
|
+
name: string;
|
|
360
|
+
}
|
|
361
|
+
/** The `stories` of Ladle's `meta.json`: id → details. */
|
|
362
|
+
type LadleStoryMap = Readonly<Record<string, {
|
|
363
|
+
name?: string | undefined;
|
|
364
|
+
}>>;
|
|
365
|
+
/**
|
|
366
|
+
* The stories of a parsed Ladle `meta.json`. Anything that is not a story map gives `{}`.
|
|
367
|
+
*
|
|
368
|
+
* @param meta - The parsed `playground/dist/meta.json`.
|
|
369
|
+
* @returns Story id → details.
|
|
370
|
+
*/
|
|
371
|
+
export declare function readLadleStories(meta: unknown): LadleStoryMap;
|
|
372
|
+
/**
|
|
373
|
+
* The Ladle stories that preview an item.
|
|
374
|
+
*
|
|
375
|
+
* - `stories` not set: the stories whose id starts with `<item>--` (the id of `Button.stories.tsx`
|
|
376
|
+
* starts with `button--`).
|
|
377
|
+
* - a map or a function: the stories whose id contains one of the item's parts. An item the map
|
|
378
|
+
* does not list has no stories, so no preview.
|
|
379
|
+
*
|
|
380
|
+
* @param itemName - The registry item name.
|
|
381
|
+
* @param mapping - The `stories` option of the site config.
|
|
382
|
+
* @param ladle - Every story in the playground.
|
|
383
|
+
* @returns The matching stories in playground order.
|
|
384
|
+
*/
|
|
385
|
+
export declare function storiesOf(itemName: string, mapping: SiteStories | undefined, ladle: LadleStoryMap): LadleStory[];
|
|
386
|
+
/**
|
|
387
|
+
* The story the landing page's "Preview" button opens: `<item>--default` when it is one of the
|
|
388
|
+
* item's stories, else its first one.
|
|
389
|
+
*
|
|
390
|
+
* @param itemName - The registry item name.
|
|
391
|
+
* @param stories - The item's stories, from {@link storiesOf}.
|
|
392
|
+
* @returns A story id, or `undefined` for an item without stories.
|
|
393
|
+
*/
|
|
394
|
+
export declare function previewStoryOf(itemName: string, stories: readonly LadleStory[]): string | undefined;
|
|
395
|
+
/**
|
|
396
|
+
* The story the live preview shows first: `defaultStory` as an item name (its preview story), or
|
|
397
|
+
* as a story id. `undefined` when it names neither, so the page falls back to its first story.
|
|
398
|
+
*
|
|
399
|
+
* @param defaultStory - The `defaultStory` option.
|
|
400
|
+
* @param previewStories - Item name → preview story id.
|
|
401
|
+
* @param ladle - Every story in the playground.
|
|
402
|
+
* @returns A story id, or `undefined`.
|
|
403
|
+
*/
|
|
404
|
+
export declare function defaultStoryOf(defaultStory: string | undefined, previewStories: Readonly<Record<string, string>>, ladle: LadleStoryMap): string | undefined;
|
|
405
|
+
/** One generated HTML page. */
|
|
406
|
+
interface SitePage {
|
|
407
|
+
/** Path inside `site/`, with forward slashes: `index.html`, `components/button/index.html`. */
|
|
408
|
+
path: string;
|
|
409
|
+
html: string;
|
|
410
|
+
}
|
|
411
|
+
/** Everything the pages are rendered from. */
|
|
412
|
+
interface SiteRenderInput {
|
|
413
|
+
config: ResolvedSiteConfig;
|
|
414
|
+
index: RegistryIndex;
|
|
415
|
+
/** Full items with file contents, one per entry of `index.items`. */
|
|
416
|
+
items: readonly RegistryItem[];
|
|
417
|
+
/** Where the item JSON files are served. */
|
|
418
|
+
baseUrl: string;
|
|
419
|
+
version: string;
|
|
420
|
+
/** Every story of the Ladle playground; `{}` without a playground. */
|
|
421
|
+
ladle: LadleStoryMap;
|
|
422
|
+
/** The playground is part of the site. */
|
|
423
|
+
playground: boolean;
|
|
424
|
+
/** The fonts stylesheet is part of the site. */
|
|
425
|
+
fonts: boolean;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Renders every page of the site, without touching the file system.
|
|
429
|
+
*
|
|
430
|
+
* @param input - Config, the registry and what the site contains.
|
|
431
|
+
* @returns The landing page and one page per item.
|
|
432
|
+
*/
|
|
433
|
+
export declare function renderSiteFiles(input: SiteRenderInput): SitePage[];
|
|
434
|
+
/**
|
|
435
|
+
* Checks that a built playground loads its assets from where the site serves it.
|
|
436
|
+
*
|
|
437
|
+
* A Ladle build made without `--base <site path>playground/` asks for `/assets/...`, which is a
|
|
438
|
+
* 404 under `site/playground/`, so every preview iframe stays blank.
|
|
439
|
+
*
|
|
440
|
+
* @param html - The text of `playground/dist/index.html`.
|
|
441
|
+
* @param base - The expected base, from {@link playgroundBase}.
|
|
442
|
+
* @throws {@link RegistrySiteError} with code `PLAYGROUND_BASE_MISMATCH` when an asset URL is
|
|
443
|
+
* absolute but outside `base`.
|
|
444
|
+
*/
|
|
445
|
+
export declare function checkPlaygroundBase(html: string, base: string): void;
|
|
446
|
+
/** Options of {@link buildRegistrySite}. */
|
|
447
|
+
interface BuildRegistrySiteOptions {
|
|
448
|
+
/** The repo root. Defaults to the current folder. */
|
|
449
|
+
root?: string | undefined;
|
|
450
|
+
/** The config object, or the path of the config file. Defaults to `registry/site.config.mjs`. */
|
|
451
|
+
config?: RegistrySiteConfig | string | undefined;
|
|
452
|
+
/** Environment variables (`REGISTRY_BASE_URL`, `SITE_BASE_PATH`, `GITHUB_REPOSITORY`). */
|
|
453
|
+
env?: SiteEnv | undefined;
|
|
454
|
+
/** Path the site is served from. Defaults to `SITE_BASE_PATH`, else `/`. */
|
|
455
|
+
siteBasePath?: string | undefined;
|
|
456
|
+
/** Build without the playground even when `playground/dist` exists. */
|
|
457
|
+
playground?: boolean | undefined;
|
|
458
|
+
/** Receives one line of progress. Defaults to writing to stdout. */
|
|
459
|
+
log?: ((line: string) => void) | undefined;
|
|
460
|
+
}
|
|
461
|
+
/** What {@link buildRegistrySite} did. */
|
|
462
|
+
interface BuildRegistrySiteResult {
|
|
463
|
+
/** `false` when `integr8.site` is `false`: nothing was built. */
|
|
464
|
+
enabled: boolean;
|
|
465
|
+
siteDir: string;
|
|
466
|
+
/** Number of HTML pages written. */
|
|
467
|
+
pages: number;
|
|
468
|
+
fonts: boolean;
|
|
469
|
+
playground: boolean;
|
|
470
|
+
baseUrl: string;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Loads and validates a site config file.
|
|
474
|
+
*
|
|
475
|
+
* @param root - The repo root.
|
|
476
|
+
* @param file - The config file, relative to `root`. Defaults to `registry/site.config.mjs`.
|
|
477
|
+
* @returns The default export of the file.
|
|
478
|
+
* @throws {@link RegistrySiteError} with code `CONFIG_NOT_FOUND` when the file is missing.
|
|
479
|
+
*/
|
|
480
|
+
export declare function loadSiteConfig(root: string, file?: string): Promise<RegistrySiteConfig>;
|
|
481
|
+
/**
|
|
482
|
+
* Builds the registry site into `site/`: the landing page, one page per item, the registry JSON
|
|
483
|
+
* (`r/`), the fonts and the Ladle playground. Needs `dist/registry/` (the registry builder's
|
|
484
|
+
* output) and, for live previews, `playground/dist/` built with the base from
|
|
485
|
+
* {@link playgroundBase}.
|
|
486
|
+
*
|
|
487
|
+
* Does nothing (and does not fail) when `"integr8": { "site": false }` is set in `package.json`.
|
|
488
|
+
*
|
|
489
|
+
* @param options - Root, config, environment and site path; all optional.
|
|
490
|
+
* @returns What was built.
|
|
491
|
+
* @throws {@link ConfigError} with code `INVALID_OPTION` for a bad config,
|
|
492
|
+
* {@link RegistrySiteError} for a missing config, registry or fonts, a bad switch value, or a
|
|
493
|
+
* playground built with the wrong `--base`.
|
|
494
|
+
*/
|
|
495
|
+
export declare function buildRegistrySite(options?: BuildRegistrySiteOptions): Promise<BuildRegistrySiteResult>;
|
|
496
|
+
/** A module and the minified bytes it adds to a bundle. */
|
|
497
|
+
interface ModuleSize {
|
|
498
|
+
/** The module path as esbuild reports it (forward slashes). */
|
|
499
|
+
path: string;
|
|
500
|
+
bytes: number;
|
|
501
|
+
}
|
|
502
|
+
/** The modules of one package in a bundle. */
|
|
503
|
+
interface PackageSize {
|
|
504
|
+
/** Package name, or the own-code label for this package's built files. */
|
|
505
|
+
name: string;
|
|
506
|
+
/** Minified bytes of all its modules in the bundle. */
|
|
507
|
+
bytes: number;
|
|
508
|
+
/** Its modules, largest first. */
|
|
509
|
+
modules: ModuleSize[];
|
|
510
|
+
}
|
|
511
|
+
/** One export's measured size. */
|
|
512
|
+
interface ExportSize {
|
|
513
|
+
name: string;
|
|
514
|
+
minifiedBytes: number;
|
|
515
|
+
brotliBytes: number;
|
|
516
|
+
/** The package with the most bytes in its bundle. */
|
|
517
|
+
largest?: string | undefined;
|
|
518
|
+
}
|
|
519
|
+
/** Label for this package's own built files, when none is given. */
|
|
520
|
+
export declare const OWN_CODE = "this package (dist)";
|
|
521
|
+
/**
|
|
522
|
+
* The package a bundled module belongs to: the name after the last `node_modules/` (with its
|
|
523
|
+
* scope), `ownCode` for `dist/`, and `(other)` for anything else (such as `<stdin>`).
|
|
524
|
+
*
|
|
525
|
+
* @param path - The module path.
|
|
526
|
+
* @param ownCode - Label for this package's own code.
|
|
527
|
+
* @returns A package name or label.
|
|
528
|
+
*/
|
|
529
|
+
export declare function packageOf(path: string, ownCode?: string): string;
|
|
530
|
+
/**
|
|
531
|
+
* Groups the inputs of one esbuild output by package, largest first. Modules that add no bytes
|
|
532
|
+
* (removed by tree shaking) are left out.
|
|
533
|
+
*
|
|
534
|
+
* @param inputs - `metafile.outputs[file].inputs`.
|
|
535
|
+
* @param ownCode - Label for this package's own code.
|
|
536
|
+
* @returns One entry per package.
|
|
537
|
+
*/
|
|
538
|
+
export declare function groupByPackage(inputs: Readonly<Record<string, {
|
|
539
|
+
bytesInOutput: number;
|
|
540
|
+
}>>, ownCode?: string): PackageSize[];
|
|
541
|
+
/** `12345` → `12.35 kB` (1 kB = 1000 bytes, like size-limit). */
|
|
542
|
+
export declare function formatKb(bytes: number): string;
|
|
543
|
+
/** The part of a module path after its package folder (or after `dist/`), for short lines. */
|
|
544
|
+
export declare function shortPath(path: string): string;
|
|
545
|
+
/** Input of {@link formatReport}. */
|
|
546
|
+
interface SizeReport {
|
|
547
|
+
/** For example `import { DatePicker }`. */
|
|
548
|
+
label: string;
|
|
549
|
+
/** From {@link groupByPackage}. */
|
|
550
|
+
groups: readonly PackageSize[];
|
|
551
|
+
/** Size of the minified bundle. */
|
|
552
|
+
minifiedBytes: number;
|
|
553
|
+
/** Size of the minified bundle after brotli. */
|
|
554
|
+
brotliBytes: number;
|
|
555
|
+
/** Largest modules listed under each package. Default 3. */
|
|
556
|
+
topModules?: number | undefined;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* The text report for one import: totals, then one line per package with its minified size, an
|
|
560
|
+
* estimate of its brotli share, and its share of the bundle, then its largest modules.
|
|
561
|
+
*
|
|
562
|
+
* The brotli share of a package is estimated from its minified share: compression works on the
|
|
563
|
+
* whole bundle, so an exact per-package brotli size does not exist.
|
|
564
|
+
*
|
|
565
|
+
* @param report - The measured import.
|
|
566
|
+
* @returns Text, one line per row.
|
|
567
|
+
*/
|
|
568
|
+
export declare function formatReport(report: SizeReport): string;
|
|
569
|
+
/**
|
|
570
|
+
* One line per export, largest brotli size first: the overview printed when no export is named.
|
|
571
|
+
*
|
|
572
|
+
* @param rows - The measured exports.
|
|
573
|
+
* @returns Text, one line per export.
|
|
574
|
+
*/
|
|
575
|
+
export declare function formatSummary(rows: readonly ExportSize[]): string;
|
|
576
|
+
/**
|
|
577
|
+
* The runtime export names of a module, from esbuild's metafile (`outputs[file].exports`),
|
|
578
|
+
* sorted. Names starting with `_` are left out.
|
|
579
|
+
*
|
|
580
|
+
* @param exportNames - The names esbuild reports.
|
|
581
|
+
* @returns Unique public names.
|
|
582
|
+
*/
|
|
583
|
+
export declare function publicExports(exportNames: readonly string[]): string[];
|
|
584
|
+
/**
|
|
585
|
+
* The file for a URL path: folders serve their `index.html`; `null` for paths outside the root
|
|
586
|
+
* or without a file.
|
|
587
|
+
*
|
|
588
|
+
* @param root - The folder to serve.
|
|
589
|
+
* @param urlPath - The path of the request URL.
|
|
590
|
+
* @returns An absolute file path, or `null`.
|
|
591
|
+
*/
|
|
592
|
+
export declare function resolveSiteFile(root: string, urlPath: string): Promise<string | null>;
|
|
593
|
+
/**
|
|
594
|
+
* Creates (does not start) the static server for a folder.
|
|
595
|
+
*
|
|
596
|
+
* @param root - The folder to serve, normally `site/`.
|
|
597
|
+
* @returns A Node HTTP server. Folders without a trailing slash are redirected, so relative
|
|
598
|
+
* links on the page resolve; responses are never cached.
|
|
599
|
+
*/
|
|
600
|
+
export declare function createSiteServer(root: string): Server;
|
|
601
|
+
/**
|
|
602
|
+
* Serves a folder on a port and resolves when it is listening.
|
|
603
|
+
*
|
|
604
|
+
* @param root - The folder to serve.
|
|
605
|
+
* @param port - The port (`0` picks a free one).
|
|
606
|
+
* @returns The running server.
|
|
607
|
+
*/
|
|
608
|
+
export declare function serveSite(root: string, port: number): Promise<Server>;
|
|
609
|
+
/** What the command needs from the outside; tests replace these. */
|
|
610
|
+
interface CliDeps {
|
|
611
|
+
/** The repo root. */
|
|
612
|
+
cwd: string;
|
|
613
|
+
env: SiteEnv;
|
|
614
|
+
/** Normal output. */
|
|
615
|
+
log: (line: string) => void;
|
|
616
|
+
/** Error output. */
|
|
617
|
+
error: (line: string) => void;
|
|
618
|
+
/** Runs a shell command in the repo and returns its exit code. */
|
|
619
|
+
run: (command: string, cwd: string, env: SiteEnv) => Promise<number>;
|
|
620
|
+
/** Starts the static server. */
|
|
621
|
+
serve: typeof serveSite;
|
|
622
|
+
}
|
|
623
|
+
/** The usage text. */
|
|
624
|
+
export declare const USAGE = "Usage: integr8-registry-site <command> [options]\n\nCommands:\n build Build site/ (assets, Ladle playground, registry JSON, pages).\n serve Serve site/ on http://localhost:4173 (PORT=5000 to change).\n dev build, then serve. The playground is always built for http://localhost:<port>/.\n enabled Print true or false: the value of \"integr8.site\" in package.json.\n size Bundle-size breakdown of the package's exports (needs \"bundleSizes\" in the config).\n\nOptions:\n --config <file> Site config. Default: registry/site.config.mjs\n --site-base-path <path> Path the site is served from. Default: $SITE_BASE_PATH, else /\n --no-playground Build without the Ladle playground (no live previews)\n\nThe site is off when package.json has \"integr8\": { \"site\": false }: every command then\nprints a note and exits with code 0.";
|
|
625
|
+
/**
|
|
626
|
+
* Runs the `integr8-registry-site` command.
|
|
627
|
+
*
|
|
628
|
+
* @param argv - The arguments after the program name.
|
|
629
|
+
* @param deps - Working folder, environment, output and process runner (default: the real ones).
|
|
630
|
+
* @returns The exit code: `0` on success and when the site is switched off, `1` on an error.
|
|
631
|
+
*/
|
|
632
|
+
export declare function runCli(argv: readonly string[], deps?: CliDeps): Promise<number>;
|
|
633
|
+
/** A group of items on the landing page and in the sidebar. */
|
|
634
|
+
interface SiteGroup<T> {
|
|
635
|
+
id: string;
|
|
636
|
+
label: string;
|
|
637
|
+
items: T[];
|
|
638
|
+
}
|
|
639
|
+
/** Escapes text for HTML content and attribute values. */
|
|
640
|
+
export declare function escapeHtml(text: unknown): string;
|
|
641
|
+
/** The short label of a registry type: `registry:ui` → `component`. */
|
|
642
|
+
export declare function typeLabel(type: string): string;
|
|
643
|
+
/**
|
|
644
|
+
* Groups registry items by their first category, in the order of `categories`. Items without a
|
|
645
|
+
* known category go last, under "Other". Without `categories`, the groups are the categories
|
|
646
|
+
* found in the items, in order of first appearance (labelled from their ids).
|
|
647
|
+
*
|
|
648
|
+
* @param items - Registry items.
|
|
649
|
+
* @param categories - Ordered `[id, label]` pairs, from the site config.
|
|
650
|
+
* @returns Only the groups that have items.
|
|
651
|
+
*/
|
|
652
|
+
export declare function groupItems<T extends {
|
|
653
|
+
name: string;
|
|
654
|
+
categories?: string[] | undefined;
|
|
655
|
+
}>(items: readonly T[], categories?: readonly SiteEntry[] | undefined): SiteGroup<T>[];
|
|
656
|
+
/** Options for the Markdown renderers. */
|
|
657
|
+
interface MarkdownOptions {
|
|
658
|
+
/** Link target of inline code that names a documented export. */
|
|
659
|
+
linkFor?: ((name: string) => string | null | undefined) | undefined;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Inline Markdown: `code`, **bold** and [links](url). Inline code that names a documented
|
|
663
|
+
* export becomes a link to it, through `linkFor`.
|
|
664
|
+
*
|
|
665
|
+
* @param text - Markdown text on one line.
|
|
666
|
+
* @param options - `linkFor`, to link documented exports.
|
|
667
|
+
* @returns HTML.
|
|
668
|
+
*/
|
|
669
|
+
export declare function inlineMarkdown(text: string, options?: MarkdownOptions): string;
|
|
670
|
+
/**
|
|
671
|
+
* Block Markdown for TSDoc text: paragraphs, `-` lists and fenced code blocks.
|
|
672
|
+
*
|
|
673
|
+
* @param markdown - Markdown text.
|
|
674
|
+
* @param options - `linkFor`, to link documented exports.
|
|
675
|
+
* @returns HTML.
|
|
676
|
+
*/
|
|
677
|
+
export declare function renderMarkdown(markdown: string | undefined, options?: MarkdownOptions): string;
|
|
678
|
+
/** The brand parts of the page header. */
|
|
679
|
+
interface ShellBrand {
|
|
680
|
+
/** Product name; the header link is labelled `<name> home`. */
|
|
681
|
+
name: string;
|
|
682
|
+
/** Shown after `integr8/`. */
|
|
683
|
+
slug: string;
|
|
684
|
+
/** Two letters in the badge. */
|
|
685
|
+
mark: string;
|
|
686
|
+
}
|
|
687
|
+
/** Options of {@link renderShell}. */
|
|
688
|
+
interface ShellOptions {
|
|
689
|
+
/** Page title. */
|
|
690
|
+
title: string;
|
|
691
|
+
/** Meta description. */
|
|
692
|
+
description: string;
|
|
693
|
+
/** Header and footer texts. */
|
|
694
|
+
brand: ShellBrand;
|
|
695
|
+
/** Relative path from the page to the site root (`''` or `../../`). */
|
|
696
|
+
root?: string | undefined;
|
|
697
|
+
/** Fonts stylesheet, relative to the site root. */
|
|
698
|
+
fontsHref?: string | undefined;
|
|
699
|
+
/** Link to the source repository. */
|
|
700
|
+
repositoryUrl?: string | undefined;
|
|
701
|
+
/** Playground link in the header, relative to the site root. */
|
|
702
|
+
playgroundHref?: string | undefined;
|
|
703
|
+
/** Text at the start of the footer. */
|
|
704
|
+
footerNote: string;
|
|
705
|
+
/** The page's `<main>`. */
|
|
706
|
+
body: string;
|
|
707
|
+
/** Extra page script (plain JavaScript). */
|
|
708
|
+
script?: string | undefined;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* The page shell shared by every page.
|
|
712
|
+
*
|
|
713
|
+
* @param options - Title, brand, links, body and script of the page.
|
|
714
|
+
* @returns The full HTML document.
|
|
715
|
+
*/
|
|
716
|
+
export declare function renderShell(options: ShellOptions): string;
|
|
717
|
+
/**
|
|
718
|
+
* The slash-terminated path a site is served from: `''` and `/` → `/`, `ui` → `/ui/`.
|
|
719
|
+
*
|
|
720
|
+
* @param path - A path such as `/ui/` or the `SITE_BASE_PATH` variable.
|
|
721
|
+
* @returns A path that starts and ends with `/`.
|
|
722
|
+
*/
|
|
723
|
+
export declare function normalizeSitePath(path: string | undefined): string;
|
|
724
|
+
/**
|
|
725
|
+
* The `--base` the Ladle playground must be built with so that its assets load from where the
|
|
726
|
+
* site serves it: `<site path>playground/`.
|
|
727
|
+
*
|
|
728
|
+
* @param sitePath - The path the site is served from (`/` locally, `/repo/` on GitHub Pages).
|
|
729
|
+
* @returns For example `/playground/` or `/integr8-ui/playground/`.
|
|
730
|
+
*/
|
|
731
|
+
export declare function playgroundBase(sitePath: string | undefined): string;
|
|
732
|
+
/** A prop, parameter, field or enum member in an API table. */
|
|
733
|
+
interface DocMember {
|
|
734
|
+
name: string;
|
|
735
|
+
type: string;
|
|
736
|
+
optional: boolean;
|
|
737
|
+
defaultValue?: string | undefined;
|
|
738
|
+
/** Markdown. */
|
|
739
|
+
description: string;
|
|
740
|
+
deprecated?: boolean;
|
|
741
|
+
}
|
|
742
|
+
/** What kind of export a {@link ExportDoc} describes. */
|
|
743
|
+
type ExportKind = "component" | "hook" | "function" | "constant" | "class" | "interface" | "type" | "enum";
|
|
744
|
+
/** The documentation of one exported declaration. */
|
|
745
|
+
interface ExportDoc {
|
|
746
|
+
name: string;
|
|
747
|
+
kind: ExportKind;
|
|
748
|
+
/** Markdown. */
|
|
749
|
+
summary: string;
|
|
750
|
+
signature: string;
|
|
751
|
+
params?: DocMember[];
|
|
752
|
+
/** Return type. */
|
|
753
|
+
returns?: string;
|
|
754
|
+
/** Markdown from `@returns`. */
|
|
755
|
+
returnsDescription?: string;
|
|
756
|
+
members?: DocMember[];
|
|
757
|
+
extends?: string[];
|
|
758
|
+
/** Markdown (usually a fenced code block). */
|
|
759
|
+
examples: string[];
|
|
760
|
+
/** Markdown. */
|
|
761
|
+
throws: string[];
|
|
762
|
+
/** Markdown; set when the export is deprecated. */
|
|
763
|
+
deprecated?: string;
|
|
764
|
+
/** For components: the type of the props parameter. */
|
|
765
|
+
propsType?: string;
|
|
766
|
+
/** For components: defaults from the props destructuring. */
|
|
767
|
+
propDefaults?: Record<string, string>;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* The documentation of every exported declaration in a file, in source order. Components get
|
|
771
|
+
* the defaults from their props destructuring copied onto their props type's members.
|
|
772
|
+
*
|
|
773
|
+
* @param fileName - Used for the parser (`.tsx` enables JSX).
|
|
774
|
+
* @param content - The file's text.
|
|
775
|
+
* @returns One entry per documented export.
|
|
776
|
+
*/
|
|
777
|
+
export declare function extractDocs(fileName: string, content: string): ExportDoc[];
|
|
778
|
+
/** An export's docs with the file it comes from. */
|
|
779
|
+
type ItemExportDoc = ExportDoc & {
|
|
780
|
+
file: string;
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* Every documented export of an item, the main one first (the export whose kebab-case name is
|
|
784
|
+
* the item name, for example `Button` for `button`), then in file and source order.
|
|
785
|
+
*
|
|
786
|
+
* @param item - A full registry item (with file contents).
|
|
787
|
+
* @returns The exports with their docs.
|
|
788
|
+
*/
|
|
789
|
+
export declare function itemDocs(item: Pick<RegistryItem, "name" | "files">): ItemExportDoc[];
|
|
790
|
+
/**
|
|
791
|
+
* A shadcn item's `css` object as CSS text: selectors and at-rules become blocks, strings
|
|
792
|
+
* become declarations, empty objects become block-less at-rules (`@import "x";`).
|
|
793
|
+
*
|
|
794
|
+
* @param css - The item's `css` object.
|
|
795
|
+
* @param indent - Indentation of the first level.
|
|
796
|
+
* @returns CSS text.
|
|
797
|
+
*/
|
|
798
|
+
export declare function cssToText(css: Record<string, unknown>, indent?: string): string;
|
|
799
|
+
/**
|
|
800
|
+
* Import lines for the value exports of each file:
|
|
801
|
+
* `import { Button } from '@/components/ui/button';`.
|
|
802
|
+
*
|
|
803
|
+
* @param docs - The exports of an item, from {@link itemDocs}.
|
|
804
|
+
* @returns One line per file.
|
|
805
|
+
*/
|
|
806
|
+
export declare function importLines(docs: readonly ItemExportDoc[]): string[];
|
|
807
|
+
/** One item in the sidebar and the previous/next links. */
|
|
808
|
+
interface ItemRef {
|
|
809
|
+
name: string;
|
|
810
|
+
title?: string | undefined;
|
|
811
|
+
}
|
|
812
|
+
/** The item the page documents. */
|
|
813
|
+
interface ItemPageInput {
|
|
814
|
+
/** The full registry item (with file contents). */
|
|
815
|
+
item: RegistryItem;
|
|
816
|
+
/** Its Ladle stories. */
|
|
817
|
+
stories?: readonly LadleStory[] | undefined;
|
|
818
|
+
/** Names of the items that depend on it. */
|
|
819
|
+
usedBy?: readonly string[] | undefined;
|
|
820
|
+
}
|
|
821
|
+
/** The site-wide facts an item page needs. */
|
|
822
|
+
interface ItemPageSite {
|
|
823
|
+
/** The resolved site config. */
|
|
824
|
+
config: ResolvedSiteConfig;
|
|
825
|
+
/** Where the item JSON files are served. */
|
|
826
|
+
baseUrl: string;
|
|
827
|
+
/** Package version. */
|
|
828
|
+
version: string;
|
|
829
|
+
/** Package name, for the footer. */
|
|
830
|
+
registryName: string;
|
|
831
|
+
/** Every item, grouped (sidebar). */
|
|
832
|
+
groups: readonly SiteGroup<ItemRef>[];
|
|
833
|
+
/** Every item in page order (previous/next). */
|
|
834
|
+
order: readonly ItemRef[];
|
|
835
|
+
/** Export name → item name, for links. */
|
|
836
|
+
exportOwners: ReadonlyMap<string, string>;
|
|
837
|
+
/** Folder of the item pages, relative to the site root. Defaults to `components/`. */
|
|
838
|
+
docsPath?: string | undefined;
|
|
839
|
+
/** Ladle playground, relative to the site root. */
|
|
840
|
+
playgroundPath?: string | undefined;
|
|
841
|
+
/** Fonts stylesheet, relative to the site root. */
|
|
842
|
+
fontsHref?: string | undefined;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Renders the documentation page of one registry item.
|
|
846
|
+
*
|
|
847
|
+
* @param page - The item, its stories and the items that use it.
|
|
848
|
+
* @param site - Config, URLs, the item list and the optional playground and fonts.
|
|
849
|
+
* @returns The full HTML document.
|
|
850
|
+
*/
|
|
851
|
+
export declare function renderItemPage(page: ItemPageInput, site: ItemPageSite): string;
|
|
852
|
+
/** Options of {@link renderRegistryPage}. */
|
|
853
|
+
interface LandingOptions {
|
|
854
|
+
/** The resolved site config (brand, categories, setup, themes, ui). */
|
|
855
|
+
config: ResolvedSiteConfig;
|
|
856
|
+
/** Where the item JSON files are served. */
|
|
857
|
+
baseUrl: string;
|
|
858
|
+
/** The package version the registry was built from. */
|
|
859
|
+
version: string;
|
|
860
|
+
/**
|
|
861
|
+
* Relative path of the Ladle build, for example `playground/`. Leave out when the playground
|
|
862
|
+
* is not part of the site.
|
|
863
|
+
*/
|
|
864
|
+
playgroundPath?: string | undefined;
|
|
865
|
+
/** Relative path of the self-hosted fonts stylesheet. */
|
|
866
|
+
fontsHref?: string | undefined;
|
|
867
|
+
/**
|
|
868
|
+
* Relative folder of the item pages, for example `components/` (each item at
|
|
869
|
+
* `components/<name>/`). Leave out when there are none.
|
|
870
|
+
*/
|
|
871
|
+
docsPath?: string | undefined;
|
|
872
|
+
/** Item name → the Ladle story id its "Preview" button opens. Items without one get no button. */
|
|
873
|
+
previewStories?: Readonly<Record<string, string>> | undefined;
|
|
874
|
+
/** Story id shown first in the live preview. */
|
|
875
|
+
defaultStory?: string | undefined;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Renders the landing page.
|
|
879
|
+
*
|
|
880
|
+
* @param index - The registry index (`registry.json`).
|
|
881
|
+
* @param options - Config, URLs and the optional playground, fonts and item pages.
|
|
882
|
+
* @returns The full HTML document.
|
|
883
|
+
*/
|
|
884
|
+
export declare function renderRegistryPage(index: RegistryIndex, options: LandingOptions): string;
|
|
885
|
+
/**
|
|
886
|
+
* Codes carried by {@link RegistrySiteError}.
|
|
887
|
+
*
|
|
888
|
+
* - `CONFIG_NOT_FOUND`: the site config file does not exist.
|
|
889
|
+
* - `INVALID_SWITCH`: `integr8.site` in `package.json` is neither `true` nor `false`.
|
|
890
|
+
* - `REGISTRY_NOT_BUILT`: `dist/registry/registry.json` is missing, so there is nothing to render.
|
|
891
|
+
* - `PLAYGROUND_BASE_MISMATCH`: the Ladle playground was built with a different `--base` than the
|
|
892
|
+
* site serves it from, so its preview iframes would be blank.
|
|
893
|
+
* - `UI_PACKAGE_NOT_FOUND`: `fonts: 'copy-from-ui'` needs the installed ui package and it is
|
|
894
|
+
* not there.
|
|
895
|
+
* - `STEP_FAILED`: a build step (Ladle, the registry builder, the assets script) exited with an error.
|
|
896
|
+
* - `BUNDLE_SIZES_UNAVAILABLE`: the bundle-size breakdown is not configured, or its input is missing.
|
|
897
|
+
*/
|
|
898
|
+
type RegistrySiteErrorCode = "CONFIG_NOT_FOUND" | "INVALID_SWITCH" | "REGISTRY_NOT_BUILT" | "PLAYGROUND_BASE_MISMATCH" | "UI_PACKAGE_NOT_FOUND" | "STEP_FAILED" | "BUNDLE_SIZES_UNAVAILABLE";
|
|
899
|
+
/**
|
|
900
|
+
* Thrown while building the registry site, for problems with the repo's files rather than with
|
|
901
|
+
* the options (those are a `ConfigError` with code `INVALID_OPTION`).
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```ts
|
|
905
|
+
* try {
|
|
906
|
+
* await buildRegistrySite();
|
|
907
|
+
* } catch (error) {
|
|
908
|
+
* if (error instanceof RegistrySiteError && error.code === 'REGISTRY_NOT_BUILT') {
|
|
909
|
+
* // run the registry build first
|
|
910
|
+
* }
|
|
911
|
+
* }
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
export declare class RegistrySiteError extends Error {
|
|
915
|
+
/** Always `'RegistrySiteError'`. */
|
|
916
|
+
override readonly name: "RegistrySiteError";
|
|
917
|
+
/** Machine-readable reason for the error. */
|
|
918
|
+
readonly code: RegistrySiteErrorCode;
|
|
919
|
+
/**
|
|
920
|
+
* @param code - Machine-readable reason for the error.
|
|
921
|
+
* @param message - Human-readable description.
|
|
922
|
+
* @param options - Standard error options, such as `cause`.
|
|
923
|
+
*/
|
|
924
|
+
constructor(code: RegistrySiteErrorCode, message: string, options?: ErrorOptions);
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Whether the registry site is on, from `integr8.site` in a parsed `package.json`.
|
|
928
|
+
*
|
|
929
|
+
* - key missing: on (a repo that calls the site workflow wants a site)
|
|
930
|
+
* - `"integr8": { "site": false }`: off
|
|
931
|
+
* - `"integr8": { "site": true }`: on
|
|
932
|
+
*
|
|
933
|
+
* This is the only on/off switch. The reusable workflow `registry-site.yml` reads the same key,
|
|
934
|
+
* and the `integr8-registry-site` commands exit with code 0 without building when it is `false`.
|
|
935
|
+
*
|
|
936
|
+
* @param pkg - The parsed `package.json`.
|
|
937
|
+
* @returns `false` only when `integr8.site` is `false`.
|
|
938
|
+
* @throws {@link RegistrySiteError} with code `INVALID_SWITCH` for any other value, so a typo
|
|
939
|
+
* such as `"site": "false"` never silently builds (or skips) the site.
|
|
940
|
+
*
|
|
941
|
+
* @example
|
|
942
|
+
* ```ts
|
|
943
|
+
* readSiteSwitch({ name: 'x', integr8: { site: false } }); // false
|
|
944
|
+
* readSiteSwitch({ name: 'x' }); // true
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
export declare function readSiteSwitch(pkg: unknown): boolean;
|
|
948
|
+
/**
|
|
949
|
+
* Reads `package.json` in a folder and returns the parsed file with its switch.
|
|
950
|
+
*
|
|
951
|
+
* @param root - The repo root.
|
|
952
|
+
* @returns The parsed `package.json` and `enabled`, the result of {@link readSiteSwitch}.
|
|
953
|
+
* @throws {@link RegistrySiteError} with code `INVALID_SWITCH` for a bad switch value.
|
|
954
|
+
*/
|
|
955
|
+
export declare function readPackageAndSwitch(root: string): Promise<{
|
|
956
|
+
pkg: Record<string, unknown>;
|
|
957
|
+
enabled: boolean;
|
|
958
|
+
}>;
|
|
959
|
+
export { type BuildRegistrySiteOptions, type BuildRegistrySiteResult, type CliDeps, ConfigError, type ConfigErrorCode, type DocMember, type ExportDoc, type ExportKind, type ExportSize, type ItemPageInput, type ItemPageSite, type ItemRef, type LadleStory, type LadleStoryMap, type LandingOptions, type MarkdownOptions, type ModuleSize, type PackageSize, type RegistryFile, type RegistryIndex, type RegistryIndexItem, type RegistryItem, type RegistrySiteConfig, type RegistrySiteErrorCode, type ResolvedSiteConfig, type ShellOptions, type SiteBrand, type SiteBundleSizes, type SiteCommands, type SiteCopy, type SiteEntry, type SiteEnv, type SiteFonts, type SiteGroup, type SitePackage, type SitePage, type SiteRenderInput, type SiteSetup, type SiteSetupExtra, type SiteSetupStep, type SiteStories, type SiteUi, type SizeReport };
|