@domphy/press 0.19.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/dist/build-6Q2QN246.js +1370 -0
- package/dist/cli.js +92 -0
- package/dist/index.d.ts +203 -0
- package/dist/index.js +272 -0
- package/dist/index.js.map +1 -0
- package/dist/islands.js +1 -0
- package/dist/serve-LQBYPP6C.js +105 -0
- package/package.json +78 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
#!/usr/bin/env node
|
|
3
|
+
|
|
4
|
+
// src/cli.ts
|
|
5
|
+
import { existsSync, watch } from "fs";
|
|
6
|
+
import { resolve } from "path";
|
|
7
|
+
import { pathToFileURL } from "url";
|
|
8
|
+
var args = process.argv.slice(2);
|
|
9
|
+
var command = args[0];
|
|
10
|
+
function flag(name) {
|
|
11
|
+
const index = args.indexOf(name);
|
|
12
|
+
return index !== -1 ? args[index + 1] : void 0;
|
|
13
|
+
}
|
|
14
|
+
async function loadConfig(configFile) {
|
|
15
|
+
const configPath = resolve(process.cwd(), configFile);
|
|
16
|
+
if (!existsSync(configPath)) {
|
|
17
|
+
console.error(`Config not found: ${configPath}`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const { default: userConfig } = await import(pathToFileURL(configPath).href);
|
|
21
|
+
return typeof userConfig === "function" ? await userConfig() : userConfig;
|
|
22
|
+
}
|
|
23
|
+
if (command === "build") {
|
|
24
|
+
const config = await loadConfig(flag("--config") ?? "press.config.ts");
|
|
25
|
+
const srcDir = resolve(process.cwd(), flag("--src") ?? config.srcDir ?? ".");
|
|
26
|
+
const outDir = resolve(process.cwd(), flag("--out") ?? config.outDir ?? "dist");
|
|
27
|
+
const publicDir = resolve(process.cwd(), "public");
|
|
28
|
+
const { buildSite } = await import("./build-6Q2QN246.js");
|
|
29
|
+
await buildSite({
|
|
30
|
+
config: { ...config, srcDir: config.srcDir ?? ".", outDir: config.outDir ?? "dist" },
|
|
31
|
+
srcDir,
|
|
32
|
+
outDir,
|
|
33
|
+
publicDir: existsSync(publicDir) ? publicDir : void 0
|
|
34
|
+
});
|
|
35
|
+
} else if (command === "dev") {
|
|
36
|
+
const port = Number(flag("--port") ?? 3e3);
|
|
37
|
+
const configFile = flag("--config") ?? "press.config.ts";
|
|
38
|
+
const config = await loadConfig(configFile);
|
|
39
|
+
const srcDir = resolve(process.cwd(), flag("--src") ?? config.srcDir ?? ".");
|
|
40
|
+
const outDir = resolve(process.cwd(), flag("--out") ?? config.outDir ?? ".press-dev");
|
|
41
|
+
const publicDir = resolve(process.cwd(), "public");
|
|
42
|
+
const { buildSite } = await import("./build-6Q2QN246.js");
|
|
43
|
+
const { startDevServer } = await import("./serve-LQBYPP6C.js");
|
|
44
|
+
async function rebuild() {
|
|
45
|
+
const start = Date.now();
|
|
46
|
+
try {
|
|
47
|
+
await buildSite({
|
|
48
|
+
config: { ...config, srcDir: config.srcDir ?? ".", outDir: config.outDir ?? ".press-dev" },
|
|
49
|
+
srcDir,
|
|
50
|
+
outDir,
|
|
51
|
+
publicDir: existsSync(publicDir) ? publicDir : void 0
|
|
52
|
+
});
|
|
53
|
+
console.log(`Rebuilt in ${Date.now() - start}ms`);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error("Build error:", error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await rebuild();
|
|
59
|
+
const { notify } = startDevServer(outDir, port);
|
|
60
|
+
let rebuildTimer = null;
|
|
61
|
+
watch(srcDir, { recursive: true }, (_event, filename) => {
|
|
62
|
+
if (!filename?.endsWith(".md") && !filename?.endsWith(".ts") && !filename?.endsWith(".js")) return;
|
|
63
|
+
if (rebuildTimer) clearTimeout(rebuildTimer);
|
|
64
|
+
rebuildTimer = setTimeout(async () => {
|
|
65
|
+
rebuildTimer = null;
|
|
66
|
+
console.log(`Changed: ${filename}`);
|
|
67
|
+
await rebuild();
|
|
68
|
+
notify();
|
|
69
|
+
}, 150);
|
|
70
|
+
});
|
|
71
|
+
console.log(`Watching ${srcDir}`);
|
|
72
|
+
} else if (command === "preview") {
|
|
73
|
+
const port = Number(flag("--port") ?? 4173);
|
|
74
|
+
const configFile = flag("--config") ?? "press.config.ts";
|
|
75
|
+
let outDir = flag("--out");
|
|
76
|
+
if (!outDir) {
|
|
77
|
+
const config = existsSync(resolve(process.cwd(), configFile)) ? await loadConfig(configFile) : null;
|
|
78
|
+
outDir = resolve(process.cwd(), config?.outDir ?? "dist");
|
|
79
|
+
} else {
|
|
80
|
+
outDir = resolve(process.cwd(), outDir);
|
|
81
|
+
}
|
|
82
|
+
if (!existsSync(outDir)) {
|
|
83
|
+
console.error(`No build at ${outDir}. Run "domphy-press build" first.`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
const { startServer } = await import("./serve-LQBYPP6C.js");
|
|
87
|
+
startServer(outDir, port);
|
|
88
|
+
} else {
|
|
89
|
+
console.error(`Unknown command: ${command ?? "(none)"}`);
|
|
90
|
+
console.error("Usage: domphy-press build | dev | preview");
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { DomphyElement, ElementNode } from '@domphy/core';
|
|
2
|
+
import { TocEntry } from '@domphy/markdown';
|
|
3
|
+
export { TocEntry } from '@domphy/markdown';
|
|
4
|
+
import { Server } from 'node:http';
|
|
5
|
+
|
|
6
|
+
interface NavItem {
|
|
7
|
+
text: string;
|
|
8
|
+
link?: string;
|
|
9
|
+
items?: {
|
|
10
|
+
text: string;
|
|
11
|
+
link: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
interface SidebarItem {
|
|
15
|
+
text: string;
|
|
16
|
+
link?: string;
|
|
17
|
+
items?: SidebarItem[];
|
|
18
|
+
collapsed?: boolean;
|
|
19
|
+
badge?: {
|
|
20
|
+
text: string;
|
|
21
|
+
type?: "tip" | "info" | "warning" | "danger";
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface SocialLink {
|
|
25
|
+
/** Built-in names: "github" | "twitter" | "discord" | "youtube" | "linkedin" | "mastodon".
|
|
26
|
+
* Or an absolute URL to a custom SVG/image. */
|
|
27
|
+
icon: string;
|
|
28
|
+
link: string;
|
|
29
|
+
ariaLabel?: string;
|
|
30
|
+
}
|
|
31
|
+
interface EditLink {
|
|
32
|
+
/** Pattern with :path placeholder, e.g. "https://github.com/org/repo/edit/main/docs/:path" */
|
|
33
|
+
pattern: string;
|
|
34
|
+
text?: string;
|
|
35
|
+
}
|
|
36
|
+
interface ThemeConfig {
|
|
37
|
+
nav: NavItem[];
|
|
38
|
+
/** Keys are route prefixes (e.g. "/guide/"). Longest match wins. */
|
|
39
|
+
sidebar: Record<string, SidebarItem[]>;
|
|
40
|
+
logo?: string;
|
|
41
|
+
search?: false | {
|
|
42
|
+
placeholder?: string;
|
|
43
|
+
limit?: number;
|
|
44
|
+
};
|
|
45
|
+
footerMessage?: string;
|
|
46
|
+
socialLinks?: SocialLink[];
|
|
47
|
+
editLink?: EditLink;
|
|
48
|
+
/** TOC heading level range. Default [2, 3]. */
|
|
49
|
+
outline?: {
|
|
50
|
+
level: [number, number];
|
|
51
|
+
};
|
|
52
|
+
/** Enable mermaid diagrams. Pass { cdn } to override CDN URL. */
|
|
53
|
+
mermaid?: boolean | {
|
|
54
|
+
cdn?: string;
|
|
55
|
+
};
|
|
56
|
+
/** Dismissible announcement bar shown above the page. */
|
|
57
|
+
announcementBar?: {
|
|
58
|
+
id?: string;
|
|
59
|
+
text: string;
|
|
60
|
+
dismissible?: boolean;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface LocaleConfig {
|
|
64
|
+
label: string;
|
|
65
|
+
lang: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
themeConfig?: Partial<ThemeConfig>;
|
|
69
|
+
}
|
|
70
|
+
interface SiteConfig {
|
|
71
|
+
title: string;
|
|
72
|
+
description: string;
|
|
73
|
+
base: string;
|
|
74
|
+
hostname: string;
|
|
75
|
+
srcDir: string;
|
|
76
|
+
outDir: string;
|
|
77
|
+
head: string[];
|
|
78
|
+
themeConfig: ThemeConfig;
|
|
79
|
+
locales?: Record<string, LocaleConfig>;
|
|
80
|
+
/** Show last-updated date sourced from git. Default false. */
|
|
81
|
+
lastUpdated?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface IslandRef {
|
|
84
|
+
id: string;
|
|
85
|
+
kind: "search";
|
|
86
|
+
}
|
|
87
|
+
interface RenderedDoc {
|
|
88
|
+
frontmatter: Record<string, unknown>;
|
|
89
|
+
body: DomphyElement[];
|
|
90
|
+
toc: TocEntry[];
|
|
91
|
+
islands: IslandRef[];
|
|
92
|
+
title: string;
|
|
93
|
+
}
|
|
94
|
+
interface RenderDocOptions {
|
|
95
|
+
filePath: string;
|
|
96
|
+
docsDir: string;
|
|
97
|
+
repoRoot: string;
|
|
98
|
+
highlight: (code: string, lang: string) => string;
|
|
99
|
+
}
|
|
100
|
+
interface SearchDocument {
|
|
101
|
+
route: string;
|
|
102
|
+
title: string;
|
|
103
|
+
text: string;
|
|
104
|
+
toc: TocEntry[];
|
|
105
|
+
}
|
|
106
|
+
interface PageEntry {
|
|
107
|
+
route: string;
|
|
108
|
+
outFile: string;
|
|
109
|
+
filePath: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type UserConfig = Omit<SiteConfig, "base" | "srcDir" | "outDir" | "head"> & {
|
|
113
|
+
base?: string;
|
|
114
|
+
srcDir?: string;
|
|
115
|
+
outDir?: string;
|
|
116
|
+
head?: string[];
|
|
117
|
+
};
|
|
118
|
+
declare function defineConfig(config: UserConfig): SiteConfig;
|
|
119
|
+
|
|
120
|
+
interface BuildOptions {
|
|
121
|
+
config: SiteConfig;
|
|
122
|
+
srcDir: string;
|
|
123
|
+
outDir: string;
|
|
124
|
+
publicDir?: string;
|
|
125
|
+
}
|
|
126
|
+
declare function buildSite(options: BuildOptions): Promise<void>;
|
|
127
|
+
|
|
128
|
+
declare function startServer(root: string, port: number): Server;
|
|
129
|
+
declare function startDevServer(root: string, port: number): {
|
|
130
|
+
server: Server;
|
|
131
|
+
notify: () => void;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
declare function renderDoc(source: string, options: RenderDocOptions): Promise<RenderedDoc>;
|
|
135
|
+
|
|
136
|
+
declare function routeForFile(srcRelativePath: string): string;
|
|
137
|
+
declare function outFileForRoute(route: string): string;
|
|
138
|
+
declare function discoverPages(srcDir: string): PageEntry[];
|
|
139
|
+
declare function flattenSidebar(items: SidebarItem[]): {
|
|
140
|
+
text: string;
|
|
141
|
+
link: string;
|
|
142
|
+
}[];
|
|
143
|
+
declare function sidebarForRoute(route: string, config: SiteConfig): SidebarItem[];
|
|
144
|
+
declare function prevNextForRoute(route: string, config: SiteConfig): {
|
|
145
|
+
prev?: {
|
|
146
|
+
text: string;
|
|
147
|
+
link: string;
|
|
148
|
+
};
|
|
149
|
+
next?: {
|
|
150
|
+
text: string;
|
|
151
|
+
link: string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
interface SearchResult {
|
|
156
|
+
route: string;
|
|
157
|
+
pageTitle: string;
|
|
158
|
+
heading: string;
|
|
159
|
+
slug: string;
|
|
160
|
+
isPage: boolean;
|
|
161
|
+
score: number;
|
|
162
|
+
href: string;
|
|
163
|
+
}
|
|
164
|
+
declare function buildSearchIndex(docs: SearchDocument[]): string;
|
|
165
|
+
declare function queryIndex(serializedIndex: string, query: string, limit?: number): SearchResult[];
|
|
166
|
+
interface SearchWidgetOptions {
|
|
167
|
+
indexUrl?: string;
|
|
168
|
+
placeholder?: string;
|
|
169
|
+
limit?: number;
|
|
170
|
+
}
|
|
171
|
+
declare function searchWidget(options?: SearchWidgetOptions): DomphyElement;
|
|
172
|
+
declare function mountSearch(host: HTMLElement, options?: SearchWidgetOptions): ElementNode;
|
|
173
|
+
|
|
174
|
+
interface FenceMeta {
|
|
175
|
+
lang: string;
|
|
176
|
+
highlightLines: Set<number>;
|
|
177
|
+
lineNumbers: boolean;
|
|
178
|
+
title: string | null;
|
|
179
|
+
}
|
|
180
|
+
declare function parseFenceInfo(info: string): FenceMeta;
|
|
181
|
+
declare function createHighlighter(): Promise<(code: string, lang: string) => string>;
|
|
182
|
+
declare function renderFence(code: string, info: string, highlight: (code: string, lang: string) => string): string;
|
|
183
|
+
|
|
184
|
+
interface LayoutContext {
|
|
185
|
+
route: string;
|
|
186
|
+
title: string;
|
|
187
|
+
body: DomphyElement[];
|
|
188
|
+
toc: TocEntry[];
|
|
189
|
+
frontmatter: Record<string, unknown>;
|
|
190
|
+
config: SiteConfig;
|
|
191
|
+
/** ISO date string from git log, if lastUpdated:true and git available. */
|
|
192
|
+
lastUpdated?: string;
|
|
193
|
+
/** Estimated reading time in minutes. */
|
|
194
|
+
readingTime?: number;
|
|
195
|
+
/** Relative path from srcDir (e.g. "guide/index.md"), used for editLink. */
|
|
196
|
+
filePath?: string;
|
|
197
|
+
}
|
|
198
|
+
declare function pageShell(ctx: LayoutContext): DomphyElement;
|
|
199
|
+
declare function homeShell(ctx: LayoutContext): DomphyElement;
|
|
200
|
+
|
|
201
|
+
declare function pressCSS(): string;
|
|
202
|
+
|
|
203
|
+
export { type EditLink, type FenceMeta, type IslandRef, type LayoutContext, type LocaleConfig, type NavItem, type PageEntry, type RenderDocOptions, type RenderedDoc, type SearchDocument, type SearchResult, type SearchWidgetOptions, type SidebarItem, type SiteConfig, type SocialLink, type ThemeConfig, type UserConfig, buildSearchIndex, buildSite, createHighlighter, defineConfig, discoverPages, flattenSidebar, homeShell, mountSearch, outFileForRoute, pageShell, parseFenceInfo, pressCSS, prevNextForRoute, queryIndex, renderDoc, renderFence, routeForFile, searchWidget, sidebarForRoute, startDevServer, startServer };
|