yaakdoc 0.1.0 → 0.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 +42 -0
- package/dist/cli.js +34 -4
- package/dist/index.d.ts +20 -79
- package/dist/index.js +3 -2
- package/dist/{preview-2YFamRKo.js → preview-Ba1BfVZV.js} +42 -567
- package/dist/site-X7q76qYf.js +609 -0
- package/dist/static.d.ts +2 -0
- package/dist/static.js +1 -0
- package/dist/version-Bwv0ibuY.d.ts +133 -0
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -23,3 +23,45 @@ await server.close();
|
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
`yaakdoc` also re-exports `defineConfig`, `defineTheme` and `defineSnippet`.
|
|
26
|
+
|
|
27
|
+
`build`, `createDevServer` and `resolveContext` take `cwd`, `configFile` and `overrides` (config values that win over the config file). They also take `exportData`, the Yaak export as an object, to use instead of reading it from a file.
|
|
28
|
+
|
|
29
|
+
### Without Vite: `yaakdoc/static`
|
|
30
|
+
|
|
31
|
+
`yaakdoc/static` is the part of the engine that doesn't need Vite. It loads the config and export, prepares the document, and writes a site with a theme that's already built. Use it to bundle yaakdoc into an environment where Vite can't run, the way the [Yaak plugin](https://github.com/jozsefsallai/yaakdoc/tree/master/packages/yaak-plugin) does.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import {
|
|
35
|
+
emptyOutDir,
|
|
36
|
+
resolveContext,
|
|
37
|
+
themeFromDefinition,
|
|
38
|
+
withBase,
|
|
39
|
+
writeSite,
|
|
40
|
+
} from "yaakdoc/static";
|
|
41
|
+
|
|
42
|
+
const context = await resolveContext({
|
|
43
|
+
exportData,
|
|
44
|
+
|
|
45
|
+
overrides: {
|
|
46
|
+
outDir: "site",
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
// Supply the theme instead of loading it from a package or path.
|
|
50
|
+
resolveTheme: (spec, { themeOptions }) => {
|
|
51
|
+
return themeFromDefinition(myTheme, {
|
|
52
|
+
manifest: "/themes/my-theme/theme.ts",
|
|
53
|
+
themeOptions,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await emptyOutDir(context.config.outDir, context.root);
|
|
59
|
+
|
|
60
|
+
// ...copy the theme's prebuilt client assets into the output directory...
|
|
61
|
+
await writeSite(context, {
|
|
62
|
+
render,
|
|
63
|
+
assets: withBase(assets, context.config.base),
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The theme's client assets and its `render` function come from `bundleTheme(context, outDir, { base: "./" })` in the main entry. It builds the theme with Vite once, and the `"./"` base makes the client assets work under any base path.
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as VERSION } from "./site-X7q76qYf.js";
|
|
2
|
+
import { a as createDevServer, n as eject, o as build, r as init, t as preview } from "./preview-Ba1BfVZV.js";
|
|
3
|
+
import { ConfigError, mergeConfig } from "@yaakdoc/config";
|
|
4
|
+
import { relative, resolve } from "node:path";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
3
6
|
import { consola } from "consola";
|
|
4
7
|
import colors from "picocolors";
|
|
5
8
|
import * as p from "@clack/prompts";
|
|
6
9
|
import { defineCommand, runMain } from "citty";
|
|
10
|
+
//#region src/cli/overrides.ts
|
|
11
|
+
/**
|
|
12
|
+
* Reads the value of `--overrides`: inline JSON (starting with `{`) or the path of a JSON file. The
|
|
13
|
+
* result is merged over the config file and validated together with it.
|
|
14
|
+
*/
|
|
15
|
+
function readOverrides(value, cwd = process.cwd()) {
|
|
16
|
+
const inline = value.trimStart().startsWith("{");
|
|
17
|
+
let text = value;
|
|
18
|
+
if (!inline) try {
|
|
19
|
+
text = readFileSync(resolve(cwd, value), "utf8");
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new ConfigError(`Could not read overrides ${value}: ${error.message}`);
|
|
22
|
+
}
|
|
23
|
+
let parsed;
|
|
24
|
+
try {
|
|
25
|
+
parsed = JSON.parse(text);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw new ConfigError(`Invalid JSON in ${inline ? "--overrides" : `overrides ${value}`}: ${error.message}`);
|
|
28
|
+
}
|
|
29
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new ConfigError("--overrides must be a JSON object");
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
7
33
|
//#region src/cli/index.ts
|
|
8
34
|
const sharedArgs = {
|
|
9
35
|
export: {
|
|
@@ -39,6 +65,10 @@ const sharedArgs = {
|
|
|
39
65
|
type: "string",
|
|
40
66
|
alias: "w",
|
|
41
67
|
description: "Workspace to document (id or name)"
|
|
68
|
+
},
|
|
69
|
+
overrides: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Config values merged over the config file (a JSON file or inline JSON)"
|
|
42
72
|
}
|
|
43
73
|
};
|
|
44
74
|
function overridesFrom(args) {
|
|
@@ -49,14 +79,14 @@ function overridesFrom(args) {
|
|
|
49
79
|
if (args.base) overrides.base = args.base;
|
|
50
80
|
if (args.environment) overrides.environment = args.environment;
|
|
51
81
|
if (args.workspace) overrides.workspace = args.workspace;
|
|
52
|
-
return overrides;
|
|
82
|
+
return args.overrides ? mergeConfig(readOverrides(args.overrides), overrides) : overrides;
|
|
53
83
|
}
|
|
54
84
|
const rel = (path) => relative(process.cwd(), path) || ".";
|
|
55
85
|
function summary(context) {
|
|
56
86
|
const requests = Object.keys(context.document.requests).length;
|
|
57
87
|
const folders = Object.keys(context.document.folders).length;
|
|
58
88
|
return [
|
|
59
|
-
`${colors.dim("Export")} ${rel(context.exportPath)} ${colors.dim(`(Yaak ${context.source.yaakVersion})`)}`,
|
|
89
|
+
`${colors.dim("Export")} ${context.exportPath ? rel(context.exportPath) : "(in memory)"} ${colors.dim(`(Yaak ${context.source.yaakVersion})`)}`,
|
|
60
90
|
`${colors.dim("Workspace")} ${context.document.workspace.name} ${colors.dim(`· ${requests} requests, ${folders} folders`)}`,
|
|
61
91
|
`${colors.dim("Environment")} ${context.document.environment?.name ?? colors.dim("none")}`,
|
|
62
92
|
`${colors.dim("Theme")} ${context.theme.name} ${colors.dim(context.theme.packageName ?? rel(context.theme.root))}`,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,84 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _ as themePackageCandidates, a as withBase, c as Route, f as resolveContext, g as themeFromDefinition, h as resolveTheme, i as emptyOutDir, l as YaakdocOptions, m as ThemeError, n as RenderEntry, o as writeSite, p as ResolvedTheme, r as assertSafeOutDir, s as Context, t as VERSION, u as matchRoute } from "./version-Bwv0ibuY.js";
|
|
2
|
+
import { ResolvedConfig, YaakdocConfig, YaakdocConfig as YaakdocConfig$1, defineConfig } from "@yaakdoc/config";
|
|
3
|
+
import { ThemeDefinition, defineTheme } from "@yaakdoc/react/theme";
|
|
3
4
|
import { Snippet, defineSnippet } from "@yaakdoc/snippets";
|
|
4
|
-
import { PreparedDocument, YaakDocument } from "@yaakdoc/core";
|
|
5
5
|
import { Plugin, ViteDevServer } from "vite";
|
|
6
6
|
import { Server } from "node:http";
|
|
7
|
-
import {
|
|
8
|
-
//#region src/node/theme.d.ts
|
|
9
|
-
type ResolvedTheme = {
|
|
10
|
-
name: string;
|
|
11
|
-
definition: ThemeDefinition$1;
|
|
12
|
-
/** Directory of the theme manifest. */
|
|
13
|
-
root: string;
|
|
14
|
-
manifest: string;
|
|
15
|
-
/** Absolute paths. */
|
|
16
|
-
entry: string;
|
|
17
|
-
client: string | null;
|
|
18
|
-
styles: string[];
|
|
19
|
-
/** Validated theme options. */
|
|
20
|
-
options: Record<string, unknown>;
|
|
21
|
-
/** Package name, when the theme comes from npm. */
|
|
22
|
-
packageName: string | null;
|
|
23
|
-
/** Files (importers) used as fallbacks when a theme dependency is not installed locally. */
|
|
24
|
-
fallbackImporters: string[];
|
|
25
|
-
highlight: {
|
|
26
|
-
light: string;
|
|
27
|
-
dark: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export declare class ThemeError extends Error {
|
|
31
|
-
name: string;
|
|
32
|
-
}
|
|
33
|
-
/** Candidate package names for a theme spec: `kiseki` → `@yaakdoc/theme-kiseki`, `yaakdoc-theme-kiseki`. */
|
|
34
|
-
export declare function themePackageCandidates(spec: string): string[];
|
|
35
|
-
/** Loads and validates a theme from a short name, package name or local path. */
|
|
36
|
-
export declare function resolveTheme(spec: string, options: {
|
|
37
|
-
root: string;
|
|
38
|
-
themeOptions: Record<string, unknown>;
|
|
39
|
-
}): Promise<ResolvedTheme>;
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/node/context.d.ts
|
|
42
|
-
type YaakdocOptions = {
|
|
43
|
-
/** Project directory (default: `process.cwd()`). */
|
|
44
|
-
cwd?: string;
|
|
45
|
-
/** Explicit config file. */
|
|
46
|
-
configFile?: string;
|
|
47
|
-
/** Config overrides (e.g. from CLI flags). Takes precedence over the config file. */
|
|
48
|
-
overrides?: YaakdocConfig$1;
|
|
49
|
-
};
|
|
50
|
-
type Route = {
|
|
51
|
-
/** URL path including the base, e.g. `/docs/products/`. */
|
|
52
|
-
path: string;
|
|
53
|
-
/** Output file relative to outDir, e.g. `products/index.html`. */
|
|
54
|
-
file: string;
|
|
55
|
-
page: PageData;
|
|
56
|
-
};
|
|
57
|
-
type Context = {
|
|
58
|
-
cwd: string;
|
|
59
|
-
root: string;
|
|
60
|
-
configFile: string | null;
|
|
61
|
-
config: ResolvedConfig$1;
|
|
62
|
-
exportPath: string;
|
|
63
|
-
source: YaakDocument;
|
|
64
|
-
theme: ResolvedTheme;
|
|
65
|
-
document: PreparedDocument;
|
|
66
|
-
site: SiteData;
|
|
67
|
-
routes: Route[];
|
|
68
|
-
notFound: Route;
|
|
69
|
-
/** Markdown/text outputs keyed by URL path (e.g. `/products.md`, `/llms.txt`). */
|
|
70
|
-
textFiles: Map<string, string>;
|
|
71
|
-
/** Local branding assets keyed by URL path → absolute file path. */
|
|
72
|
-
assets: Map<string, string>;
|
|
73
|
-
/** Files that trigger a full rebuild of the context when changed. */
|
|
74
|
-
watchFiles: string[];
|
|
75
|
-
};
|
|
76
|
-
export declare const VERSION: string;
|
|
77
|
-
/** Loads config, export and theme, and prepares everything needed to render the site. */
|
|
78
|
-
export declare function resolveContext(options?: YaakdocOptions): Promise<Context>;
|
|
79
|
-
/** Finds the route for a URL path (ignoring query/hash; `/x` matches `/x/`). */
|
|
80
|
-
export declare function matchRoute(context: Context, pathname: string): Route | null;
|
|
81
|
-
//#endregion
|
|
7
|
+
import { Assets } from "@yaakdoc/react";
|
|
82
8
|
//#region src/node/build.d.ts
|
|
83
9
|
type BuildResult = {
|
|
84
10
|
outDir: string;
|
|
@@ -88,6 +14,20 @@ type BuildResult = {
|
|
|
88
14
|
};
|
|
89
15
|
/** Builds the static site: client assets, prerendered HTML for every route, Markdown and llms.txt. */
|
|
90
16
|
export declare function build(options?: YaakdocOptions): Promise<BuildResult>;
|
|
17
|
+
type ThemeBundle = {
|
|
18
|
+
/** Client assets, relative to the output directory. */
|
|
19
|
+
assets: Assets;
|
|
20
|
+
/** The SSR entry (exports `render`), in a temporary directory inside the output directory. */
|
|
21
|
+
ssrEntry: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Builds the theme with Vite: the island runtime and CSS into `outDir` (emptied first), and the SSR
|
|
25
|
+
* entry, fully bundled so it runs from anywhere. Pass `base: "./"` for client assets that work
|
|
26
|
+
* under any base path (used to precompile the theme bundled into the Yaak plugin).
|
|
27
|
+
*/
|
|
28
|
+
export declare function bundleTheme(context: Context, outDir: string, options?: {
|
|
29
|
+
base?: string;
|
|
30
|
+
}): Promise<ThemeBundle>;
|
|
91
31
|
//#endregion
|
|
92
32
|
//#region src/node/dev.d.ts
|
|
93
33
|
type DevServerOptions = YaakdocOptions & {
|
|
@@ -150,6 +90,7 @@ export declare function init(options?: InitOptions): Promise<{
|
|
|
150
90
|
//#endregion
|
|
151
91
|
//#region src/node/plugin.d.ts
|
|
152
92
|
export declare const VIRTUAL_SERVER = "virtual:yaakdoc/entry-server";
|
|
93
|
+
/** The SSR entry exports `render` (see `RenderEntry`). */
|
|
153
94
|
export declare const VIRTUAL_CLIENT = "virtual:yaakdoc/entry-client";
|
|
154
95
|
/**
|
|
155
96
|
* The yaakdoc Vite plugin: virtual SSR/client entries, theme-scoped `@/` alias, and fallback
|
|
@@ -174,4 +115,4 @@ export declare function preview(options?: PreviewOptions): Promise<{
|
|
|
174
115
|
close: () => Promise<void>;
|
|
175
116
|
}>;
|
|
176
117
|
//#endregion
|
|
177
|
-
export { type BuildResult, type Context, type DevServer, type DevServerOptions, type EjectOptions, type EjectResult, type InitOptions, type PreviewOptions, type ResolvedConfig, type ResolvedTheme, type Route, type Snippet, type ThemeDefinition, type YaakdocConfig, type YaakdocOptions, defineConfig, defineSnippet, defineTheme };
|
|
118
|
+
export { type BuildResult, type Context, type DevServer, type DevServerOptions, type EjectOptions, type EjectResult, type InitOptions, type PreviewOptions, type RenderEntry, type ResolvedConfig, type ResolvedTheme, type Route, type Snippet, type ThemeBundle, type ThemeDefinition, ThemeError, VERSION, type YaakdocConfig, type YaakdocOptions, assertSafeOutDir, defineConfig, defineSnippet, defineTheme, emptyOutDir, matchRoute, resolveContext, resolveTheme, themeFromDefinition, themePackageCandidates, withBase, writeSite };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as matchRoute, c as VERSION, d as themeFromDefinition, f as themePackageCandidates, i as writeSite, l as ThemeError, n as emptyOutDir, r as withBase, s as resolveContext, t as assertSafeOutDir, u as resolveTheme } from "./site-X7q76qYf.js";
|
|
2
|
+
import { a as createDevServer, c as VIRTUAL_CLIENT, i as schemaUrl, l as VIRTUAL_SERVER, n as eject, o as build, r as init, s as bundleTheme, t as preview, u as yaakdocPlugin } from "./preview-Ba1BfVZV.js";
|
|
2
3
|
import { defineConfig } from "@yaakdoc/config";
|
|
3
4
|
import { defineTheme } from "@yaakdoc/react/theme";
|
|
4
5
|
import { defineSnippet } from "@yaakdoc/snippets";
|
|
5
|
-
export { ThemeError, VERSION, VIRTUAL_CLIENT, VIRTUAL_SERVER, build, createDevServer, defineConfig, defineSnippet, defineTheme, eject, init, matchRoute, preview, resolveContext, resolveTheme, schemaUrl, themePackageCandidates, yaakdocPlugin };
|
|
6
|
+
export { ThemeError, VERSION, VIRTUAL_CLIENT, VIRTUAL_SERVER, assertSafeOutDir, build, bundleTheme, createDevServer, defineConfig, defineSnippet, defineTheme, eject, emptyOutDir, init, matchRoute, preview, resolveContext, resolveTheme, schemaUrl, themeFromDefinition, themePackageCandidates, withBase, writeSite, yaakdocPlugin };
|