@raystack/chronicle 0.1.0-canary.111b55a
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/bin/chronicle.js +2 -0
- package/dist/cli/index.js +963 -0
- package/package.json +67 -0
- package/src/cli/__tests__/config.test.ts +25 -0
- package/src/cli/__tests__/scaffold.test.ts +10 -0
- package/src/cli/commands/build.ts +74 -0
- package/src/cli/commands/dev.ts +21 -0
- package/src/cli/commands/init.ts +154 -0
- package/src/cli/commands/serve.ts +55 -0
- package/src/cli/commands/start.ts +24 -0
- package/src/cli/index.ts +21 -0
- package/src/cli/utils/config.ts +43 -0
- package/src/cli/utils/index.ts +2 -0
- package/src/cli/utils/resolve.ts +6 -0
- package/src/cli/utils/scaffold.ts +20 -0
- package/src/components/api/code-snippets.module.css +7 -0
- package/src/components/api/code-snippets.tsx +76 -0
- package/src/components/api/endpoint-page.module.css +58 -0
- package/src/components/api/endpoint-page.tsx +283 -0
- package/src/components/api/field-row.module.css +126 -0
- package/src/components/api/field-row.tsx +204 -0
- package/src/components/api/field-section.module.css +24 -0
- package/src/components/api/field-section.tsx +100 -0
- package/src/components/api/index.ts +8 -0
- package/src/components/api/json-editor.module.css +9 -0
- package/src/components/api/json-editor.tsx +61 -0
- package/src/components/api/key-value-editor.module.css +13 -0
- package/src/components/api/key-value-editor.tsx +62 -0
- package/src/components/api/method-badge.module.css +4 -0
- package/src/components/api/method-badge.tsx +29 -0
- package/src/components/api/response-panel.module.css +8 -0
- package/src/components/api/response-panel.tsx +44 -0
- package/src/components/common/breadcrumb.tsx +3 -0
- package/src/components/common/button.tsx +3 -0
- package/src/components/common/callout.module.css +7 -0
- package/src/components/common/callout.tsx +27 -0
- package/src/components/common/code-block.tsx +3 -0
- package/src/components/common/dialog.tsx +3 -0
- package/src/components/common/index.ts +10 -0
- package/src/components/common/input-field.tsx +3 -0
- package/src/components/common/sidebar.tsx +3 -0
- package/src/components/common/switch.tsx +3 -0
- package/src/components/common/table.tsx +3 -0
- package/src/components/common/tabs.tsx +3 -0
- package/src/components/mdx/code.module.css +42 -0
- package/src/components/mdx/code.tsx +36 -0
- package/src/components/mdx/details.module.css +14 -0
- package/src/components/mdx/details.tsx +17 -0
- package/src/components/mdx/image.tsx +24 -0
- package/src/components/mdx/index.tsx +35 -0
- package/src/components/mdx/link.tsx +37 -0
- package/src/components/mdx/mermaid.module.css +9 -0
- package/src/components/mdx/mermaid.tsx +37 -0
- package/src/components/mdx/paragraph.module.css +8 -0
- package/src/components/mdx/paragraph.tsx +19 -0
- package/src/components/mdx/table.tsx +40 -0
- package/src/components/ui/breadcrumbs.tsx +72 -0
- package/src/components/ui/client-theme-switcher.tsx +18 -0
- package/src/components/ui/footer.module.css +27 -0
- package/src/components/ui/footer.tsx +31 -0
- package/src/components/ui/search.module.css +111 -0
- package/src/components/ui/search.tsx +173 -0
- package/src/lib/api-routes.ts +120 -0
- package/src/lib/config.ts +56 -0
- package/src/lib/head.tsx +45 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/openapi.ts +188 -0
- package/src/lib/page-context.tsx +95 -0
- package/src/lib/remark-unused-directives.ts +30 -0
- package/src/lib/schema.ts +99 -0
- package/src/lib/snippet-generators.ts +87 -0
- package/src/lib/source.ts +138 -0
- package/src/pages/ApiLayout.module.css +22 -0
- package/src/pages/ApiLayout.tsx +29 -0
- package/src/pages/ApiPage.tsx +68 -0
- package/src/pages/DocsLayout.tsx +18 -0
- package/src/pages/DocsPage.tsx +43 -0
- package/src/pages/NotFound.tsx +10 -0
- package/src/pages/__tests__/head.test.tsx +57 -0
- package/src/server/App.tsx +59 -0
- package/src/server/__tests__/entry-server.test.tsx +35 -0
- package/src/server/__tests__/handlers.test.ts +77 -0
- package/src/server/__tests__/og.test.ts +23 -0
- package/src/server/__tests__/router.test.ts +72 -0
- package/src/server/__tests__/vite-config.test.ts +25 -0
- package/src/server/adapters/vercel.ts +133 -0
- package/src/server/build-search-index.ts +107 -0
- package/src/server/dev.ts +156 -0
- package/src/server/entry-client.tsx +74 -0
- package/src/server/entry-prod.ts +97 -0
- package/src/server/entry-server.tsx +35 -0
- package/src/server/entry-vercel.ts +28 -0
- package/src/server/handlers/apis-proxy.ts +52 -0
- package/src/server/handlers/health.ts +3 -0
- package/src/server/handlers/llms.ts +58 -0
- package/src/server/handlers/og.ts +87 -0
- package/src/server/handlers/robots.ts +11 -0
- package/src/server/handlers/search.ts +172 -0
- package/src/server/handlers/sitemap.ts +39 -0
- package/src/server/handlers/specs.ts +9 -0
- package/src/server/index.html +12 -0
- package/src/server/prod.ts +18 -0
- package/src/server/request-handler.ts +63 -0
- package/src/server/router.ts +42 -0
- package/src/server/vite-config.ts +71 -0
- package/src/themes/default/Layout.module.css +81 -0
- package/src/themes/default/Layout.tsx +132 -0
- package/src/themes/default/Page.module.css +106 -0
- package/src/themes/default/Page.tsx +21 -0
- package/src/themes/default/Toc.module.css +48 -0
- package/src/themes/default/Toc.tsx +66 -0
- package/src/themes/default/font.ts +4 -0
- package/src/themes/default/index.ts +13 -0
- package/src/themes/paper/ChapterNav.module.css +71 -0
- package/src/themes/paper/ChapterNav.tsx +95 -0
- package/src/themes/paper/Layout.module.css +33 -0
- package/src/themes/paper/Layout.tsx +25 -0
- package/src/themes/paper/Page.module.css +174 -0
- package/src/themes/paper/Page.tsx +106 -0
- package/src/themes/paper/ReadingProgress.module.css +132 -0
- package/src/themes/paper/ReadingProgress.tsx +294 -0
- package/src/themes/paper/index.ts +8 -0
- package/src/themes/registry.ts +14 -0
- package/src/types/config.ts +80 -0
- package/src/types/content.ts +36 -0
- package/src/types/index.ts +3 -0
- package/src/types/theme.ts +22 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,963 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
18
|
+
|
|
19
|
+
// src/server/vite-config.ts
|
|
20
|
+
var exports_vite_config = {};
|
|
21
|
+
__export(exports_vite_config, {
|
|
22
|
+
createViteConfig: () => createViteConfig
|
|
23
|
+
});
|
|
24
|
+
import path5 from "path";
|
|
25
|
+
import react from "@vitejs/plugin-react";
|
|
26
|
+
import mdx from "@mdx-js/rollup";
|
|
27
|
+
import remarkDirective from "remark-directive";
|
|
28
|
+
import remarkGfm from "remark-gfm";
|
|
29
|
+
import remarkFrontmatter from "remark-frontmatter";
|
|
30
|
+
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
|
|
31
|
+
import rehypeShiki from "@shikijs/rehype";
|
|
32
|
+
async function createViteConfig(options) {
|
|
33
|
+
const { root, contentDir, isDev = false } = options;
|
|
34
|
+
return {
|
|
35
|
+
root,
|
|
36
|
+
configFile: false,
|
|
37
|
+
resolve: {
|
|
38
|
+
alias: {
|
|
39
|
+
"@": path5.resolve(root, "src"),
|
|
40
|
+
"@content": contentDir
|
|
41
|
+
},
|
|
42
|
+
dedupe: ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime"]
|
|
43
|
+
},
|
|
44
|
+
server: {
|
|
45
|
+
fs: {
|
|
46
|
+
allow: [root, contentDir]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
plugins: [
|
|
50
|
+
mdx({
|
|
51
|
+
remarkPlugins: [
|
|
52
|
+
remarkFrontmatter,
|
|
53
|
+
remarkMdxFrontmatter,
|
|
54
|
+
remarkGfm,
|
|
55
|
+
remarkDirective
|
|
56
|
+
],
|
|
57
|
+
rehypePlugins: [
|
|
58
|
+
[rehypeShiki, { themes: { light: "github-light", dark: "github-dark" }, defaultColor: false }]
|
|
59
|
+
],
|
|
60
|
+
mdExtensions: [".md"],
|
|
61
|
+
mdxExtensions: [".mdx"]
|
|
62
|
+
}),
|
|
63
|
+
react()
|
|
64
|
+
],
|
|
65
|
+
define: {
|
|
66
|
+
"process.env.CHRONICLE_CONTENT_DIR": JSON.stringify(contentDir),
|
|
67
|
+
"process.env.CHRONICLE_PROJECT_ROOT": JSON.stringify(root)
|
|
68
|
+
},
|
|
69
|
+
css: {
|
|
70
|
+
modules: {
|
|
71
|
+
localsConvention: "camelCase"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
ssr: {
|
|
75
|
+
noExternal: ["@raystack/apsara"]
|
|
76
|
+
},
|
|
77
|
+
build: {
|
|
78
|
+
rolldownOptions: {
|
|
79
|
+
input: isDev ? undefined : {
|
|
80
|
+
client: path5.resolve(root, "src/server/index.html")
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
var init_vite_config = () => {};
|
|
87
|
+
|
|
88
|
+
// src/server/dev.ts
|
|
89
|
+
var exports_dev = {};
|
|
90
|
+
__export(exports_dev, {
|
|
91
|
+
startDevServer: () => startDevServer
|
|
92
|
+
});
|
|
93
|
+
import { createServer as createViteServer } from "vite";
|
|
94
|
+
import { createServer } from "http";
|
|
95
|
+
import fsPromises from "fs/promises";
|
|
96
|
+
import { createReadStream } from "fs";
|
|
97
|
+
import path6 from "path";
|
|
98
|
+
import chalk3 from "chalk";
|
|
99
|
+
async function startDevServer(options) {
|
|
100
|
+
const { port, root, contentDir } = options;
|
|
101
|
+
const viteConfig = await createViteConfig({ root, contentDir, isDev: true });
|
|
102
|
+
const vite = await createViteServer({
|
|
103
|
+
...viteConfig,
|
|
104
|
+
server: { middlewareMode: true },
|
|
105
|
+
appType: "custom"
|
|
106
|
+
});
|
|
107
|
+
const templatePath = path6.resolve(root, "src/server/index.html");
|
|
108
|
+
const server = createServer(async (req, res) => {
|
|
109
|
+
const url = req.url || "/";
|
|
110
|
+
try {
|
|
111
|
+
if (url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/node_modules/")) {
|
|
112
|
+
vite.middlewares(req, res, () => {
|
|
113
|
+
res.statusCode = 404;
|
|
114
|
+
res.end();
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const contentFile = path6.join(contentDir, decodeURIComponent(url.split("?")[0]));
|
|
119
|
+
if (!url.endsWith(".md") && !url.endsWith(".mdx")) {
|
|
120
|
+
try {
|
|
121
|
+
const stat = await fsPromises.stat(contentFile);
|
|
122
|
+
if (stat.isFile()) {
|
|
123
|
+
const ext = path6.extname(contentFile).toLowerCase();
|
|
124
|
+
const mimeTypes = {
|
|
125
|
+
".png": "image/png",
|
|
126
|
+
".jpg": "image/jpeg",
|
|
127
|
+
".jpeg": "image/jpeg",
|
|
128
|
+
".gif": "image/gif",
|
|
129
|
+
".svg": "image/svg+xml",
|
|
130
|
+
".webp": "image/webp",
|
|
131
|
+
".ico": "image/x-icon",
|
|
132
|
+
".pdf": "application/pdf",
|
|
133
|
+
".json": "application/json",
|
|
134
|
+
".yaml": "text/yaml",
|
|
135
|
+
".yml": "text/yaml",
|
|
136
|
+
".txt": "text/plain"
|
|
137
|
+
};
|
|
138
|
+
res.setHeader("Content-Type", mimeTypes[ext] || "application/octet-stream");
|
|
139
|
+
createReadStream(contentFile).pipe(res);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
} catch {}
|
|
143
|
+
}
|
|
144
|
+
if (/\.(js|ts|tsx|css|map)(\?|$)/.test(url)) {
|
|
145
|
+
vite.middlewares(req, res, () => {
|
|
146
|
+
res.statusCode = 404;
|
|
147
|
+
res.end();
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const { matchRoute } = await vite.ssrLoadModule(path6.resolve(root, "src/server/router.ts"));
|
|
152
|
+
const routeHandler = matchRoute(new URL(url, `http://localhost:${port}`).href);
|
|
153
|
+
if (routeHandler) {
|
|
154
|
+
const request = new Request(new URL(url, `http://localhost:${port}`));
|
|
155
|
+
const response = await routeHandler(request);
|
|
156
|
+
res.statusCode = response.status;
|
|
157
|
+
response.headers.forEach((value, key) => res.setHeader(key, value));
|
|
158
|
+
const body = await response.text();
|
|
159
|
+
res.end(body);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const pathname = new URL(url, `http://localhost:${port}`).pathname;
|
|
163
|
+
const slug = pathname === "/" ? [] : pathname.slice(1).split("/").filter(Boolean);
|
|
164
|
+
const source = await vite.ssrLoadModule(path6.resolve(root, "src/lib/source.ts"));
|
|
165
|
+
const { mdxComponents } = await vite.ssrLoadModule(path6.resolve(root, "src/components/mdx/index.tsx"));
|
|
166
|
+
const { loadConfig } = await vite.ssrLoadModule(path6.resolve(root, "src/lib/config.ts"));
|
|
167
|
+
const config = loadConfig();
|
|
168
|
+
const { loadApiSpecs } = await vite.ssrLoadModule(path6.resolve(root, "src/lib/openapi.ts"));
|
|
169
|
+
const apiSpecs = config.api?.length ? loadApiSpecs(config.api) : [];
|
|
170
|
+
const [tree, sourcePage] = await Promise.all([
|
|
171
|
+
source.buildPageTree(),
|
|
172
|
+
source.getPage(slug)
|
|
173
|
+
]);
|
|
174
|
+
let pageData = null;
|
|
175
|
+
let embeddedData = { config, tree, slug, frontmatter: null, filePath: null };
|
|
176
|
+
if (sourcePage) {
|
|
177
|
+
const component = await source.loadPageComponent(sourcePage);
|
|
178
|
+
const React = await import("react");
|
|
179
|
+
const MDXBody = component;
|
|
180
|
+
pageData = {
|
|
181
|
+
slug,
|
|
182
|
+
frontmatter: sourcePage.frontmatter,
|
|
183
|
+
content: MDXBody ? React.createElement(MDXBody, { components: mdxComponents }) : null
|
|
184
|
+
};
|
|
185
|
+
embeddedData.frontmatter = sourcePage.frontmatter;
|
|
186
|
+
embeddedData.filePath = sourcePage.filePath;
|
|
187
|
+
}
|
|
188
|
+
let template = await fsPromises.readFile(templatePath, "utf-8");
|
|
189
|
+
template = await vite.transformIndexHtml(url, template);
|
|
190
|
+
const dataScript = `<script>window.__PAGE_DATA__ = ${JSON.stringify(embeddedData)}</script>`;
|
|
191
|
+
template = template.replace("<!--head-outlet-->", `<!--head-outlet-->${dataScript}`);
|
|
192
|
+
const { render } = await vite.ssrLoadModule(path6.resolve(root, "src/server/entry-server.tsx"));
|
|
193
|
+
const html = render(url, { config, tree, page: pageData, apiSpecs });
|
|
194
|
+
const finalHtml = template.replace("<!--ssr-outlet-->", html);
|
|
195
|
+
res.setHeader("Content-Type", "text/html");
|
|
196
|
+
res.statusCode = 200;
|
|
197
|
+
res.end(finalHtml);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
vite.ssrFixStacktrace(e);
|
|
200
|
+
console.error(e);
|
|
201
|
+
res.statusCode = 500;
|
|
202
|
+
res.end(e.message);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
server.listen(port, () => {
|
|
206
|
+
console.log(chalk3.cyan(`
|
|
207
|
+
Chronicle dev server running at:`));
|
|
208
|
+
console.log(chalk3.green(` http://localhost:${port}
|
|
209
|
+
`));
|
|
210
|
+
});
|
|
211
|
+
const shutdown = () => {
|
|
212
|
+
vite.close();
|
|
213
|
+
server.close();
|
|
214
|
+
process.exit(0);
|
|
215
|
+
};
|
|
216
|
+
process.on("SIGINT", shutdown);
|
|
217
|
+
process.on("SIGTERM", shutdown);
|
|
218
|
+
return { server, vite };
|
|
219
|
+
}
|
|
220
|
+
var init_dev = __esm(() => {
|
|
221
|
+
init_vite_config();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// src/lib/config.ts
|
|
225
|
+
import fs3 from "fs";
|
|
226
|
+
import path7 from "path";
|
|
227
|
+
import { parse as parse2 } from "yaml";
|
|
228
|
+
function resolveConfigPath() {
|
|
229
|
+
const projectRoot = process.env.CHRONICLE_PROJECT_ROOT;
|
|
230
|
+
if (projectRoot) {
|
|
231
|
+
const rootPath = path7.join(projectRoot, CONFIG_FILE);
|
|
232
|
+
if (fs3.existsSync(rootPath))
|
|
233
|
+
return rootPath;
|
|
234
|
+
}
|
|
235
|
+
const cwdPath = path7.join(process.cwd(), CONFIG_FILE);
|
|
236
|
+
if (fs3.existsSync(cwdPath))
|
|
237
|
+
return cwdPath;
|
|
238
|
+
const contentDir = process.env.CHRONICLE_CONTENT_DIR;
|
|
239
|
+
if (contentDir) {
|
|
240
|
+
const contentPath = path7.join(contentDir, CONFIG_FILE);
|
|
241
|
+
if (fs3.existsSync(contentPath))
|
|
242
|
+
return contentPath;
|
|
243
|
+
}
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
function loadConfig() {
|
|
247
|
+
const configPath = resolveConfigPath();
|
|
248
|
+
if (!configPath) {
|
|
249
|
+
return defaultConfig;
|
|
250
|
+
}
|
|
251
|
+
const raw = fs3.readFileSync(configPath, "utf-8");
|
|
252
|
+
const userConfig = parse2(raw);
|
|
253
|
+
return {
|
|
254
|
+
...defaultConfig,
|
|
255
|
+
...userConfig,
|
|
256
|
+
theme: {
|
|
257
|
+
name: userConfig.theme?.name ?? defaultConfig.theme.name,
|
|
258
|
+
colors: { ...defaultConfig.theme?.colors, ...userConfig.theme?.colors }
|
|
259
|
+
},
|
|
260
|
+
search: { ...defaultConfig.search, ...userConfig.search },
|
|
261
|
+
footer: userConfig.footer,
|
|
262
|
+
api: userConfig.api,
|
|
263
|
+
llms: { enabled: false, ...userConfig.llms },
|
|
264
|
+
analytics: { enabled: false, ...userConfig.analytics }
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
var CONFIG_FILE = "chronicle.yaml", defaultConfig;
|
|
268
|
+
var init_config = __esm(() => {
|
|
269
|
+
defaultConfig = {
|
|
270
|
+
title: "Documentation",
|
|
271
|
+
theme: { name: "default" },
|
|
272
|
+
search: { enabled: true, placeholder: "Search..." }
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
// src/lib/openapi.ts
|
|
276
|
+
import fs4 from "fs";
|
|
277
|
+
import path8 from "path";
|
|
278
|
+
import { parse as parseYaml } from "yaml";
|
|
279
|
+
function loadApiSpecs(apiConfigs) {
|
|
280
|
+
const contentDir = process.env.CHRONICLE_CONTENT_DIR ?? process.cwd();
|
|
281
|
+
return apiConfigs.map((config) => loadApiSpec(config, contentDir));
|
|
282
|
+
}
|
|
283
|
+
function loadApiSpec(config, contentDir) {
|
|
284
|
+
const specPath = path8.resolve(contentDir, config.spec);
|
|
285
|
+
const raw = fs4.readFileSync(specPath, "utf-8");
|
|
286
|
+
const isYaml = specPath.endsWith(".yaml") || specPath.endsWith(".yml");
|
|
287
|
+
const doc = isYaml ? parseYaml(raw) : JSON.parse(raw);
|
|
288
|
+
let v3Doc;
|
|
289
|
+
if ("swagger" in doc && doc.swagger === "2.0") {
|
|
290
|
+
v3Doc = convertV2toV3(doc);
|
|
291
|
+
} else if ("openapi" in doc && doc.openapi.startsWith("3.")) {
|
|
292
|
+
v3Doc = resolveDocument(doc);
|
|
293
|
+
} else {
|
|
294
|
+
throw new Error(`Unsupported spec version in ${config.spec}`);
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
name: config.name,
|
|
298
|
+
basePath: config.basePath,
|
|
299
|
+
server: config.server,
|
|
300
|
+
auth: config.auth,
|
|
301
|
+
document: v3Doc
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function resolveRef(ref, root) {
|
|
305
|
+
const parts = ref.replace(/^#\//, "").split("/");
|
|
306
|
+
let current = root;
|
|
307
|
+
for (const part of parts) {
|
|
308
|
+
if (current && typeof current === "object" && !Array.isArray(current)) {
|
|
309
|
+
current = current[part];
|
|
310
|
+
} else {
|
|
311
|
+
throw new Error(`Cannot resolve $ref: ${ref}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return current;
|
|
315
|
+
}
|
|
316
|
+
function deepResolveRefs(obj, root, stack = new Set, cache = new Map) {
|
|
317
|
+
if (obj === null || obj === undefined || typeof obj !== "object")
|
|
318
|
+
return obj;
|
|
319
|
+
if (Array.isArray(obj)) {
|
|
320
|
+
return obj.map((item) => deepResolveRefs(item, root, stack, cache));
|
|
321
|
+
}
|
|
322
|
+
const record = obj;
|
|
323
|
+
if (typeof record.$ref === "string") {
|
|
324
|
+
const ref = record.$ref;
|
|
325
|
+
if (cache.has(ref))
|
|
326
|
+
return cache.get(ref);
|
|
327
|
+
if (stack.has(ref))
|
|
328
|
+
return { type: "object", description: "[circular]" };
|
|
329
|
+
stack.add(ref);
|
|
330
|
+
const resolved = deepResolveRefs(resolveRef(ref, root), root, stack, cache);
|
|
331
|
+
stack.delete(ref);
|
|
332
|
+
cache.set(ref, resolved);
|
|
333
|
+
return resolved;
|
|
334
|
+
}
|
|
335
|
+
const result = {};
|
|
336
|
+
for (const [key, value] of Object.entries(record)) {
|
|
337
|
+
result[key] = deepResolveRefs(value, root, stack, cache);
|
|
338
|
+
}
|
|
339
|
+
return result;
|
|
340
|
+
}
|
|
341
|
+
function resolveDocument(doc) {
|
|
342
|
+
const root = doc;
|
|
343
|
+
return deepResolveRefs(doc, root);
|
|
344
|
+
}
|
|
345
|
+
function convertV2toV3(doc) {
|
|
346
|
+
const root = doc;
|
|
347
|
+
const resolved = deepResolveRefs(doc, root);
|
|
348
|
+
const v3Paths = {};
|
|
349
|
+
for (const [pathStr, pathItem] of Object.entries(resolved.paths ?? {})) {
|
|
350
|
+
if (!pathItem)
|
|
351
|
+
continue;
|
|
352
|
+
const v3PathItem = {};
|
|
353
|
+
for (const method of ["get", "post", "put", "delete", "patch"]) {
|
|
354
|
+
const op = pathItem[method];
|
|
355
|
+
if (!op)
|
|
356
|
+
continue;
|
|
357
|
+
v3PathItem[method] = convertV2Operation(op);
|
|
358
|
+
}
|
|
359
|
+
v3Paths[pathStr] = v3PathItem;
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
openapi: "3.0.0",
|
|
363
|
+
info: resolved.info,
|
|
364
|
+
paths: v3Paths,
|
|
365
|
+
tags: resolved.tags ?? []
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function convertV2Operation(op) {
|
|
369
|
+
const params = op.parameters ?? [];
|
|
370
|
+
const v3Params = params.filter((p) => p.in !== "body").map((p) => ({
|
|
371
|
+
name: p.name,
|
|
372
|
+
in: p.in,
|
|
373
|
+
required: p.required ?? false,
|
|
374
|
+
description: p.description,
|
|
375
|
+
schema: { type: p.type ?? "string", format: p.format }
|
|
376
|
+
}));
|
|
377
|
+
const bodyParam = params.find((p) => p.in === "body");
|
|
378
|
+
let requestBody;
|
|
379
|
+
if (bodyParam?.schema) {
|
|
380
|
+
requestBody = {
|
|
381
|
+
required: bodyParam.required ?? false,
|
|
382
|
+
content: {
|
|
383
|
+
"application/json": {
|
|
384
|
+
schema: bodyParam.schema
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
const v3Responses = {};
|
|
390
|
+
for (const [status, resp] of Object.entries(op.responses ?? {})) {
|
|
391
|
+
const v2Resp = resp;
|
|
392
|
+
const v3Resp = {
|
|
393
|
+
description: v2Resp.description ?? ""
|
|
394
|
+
};
|
|
395
|
+
if (v2Resp.schema) {
|
|
396
|
+
v3Resp.content = {
|
|
397
|
+
"application/json": {
|
|
398
|
+
schema: v2Resp.schema
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
v3Responses[status] = v3Resp;
|
|
403
|
+
}
|
|
404
|
+
const result = {
|
|
405
|
+
operationId: op.operationId,
|
|
406
|
+
summary: op.summary,
|
|
407
|
+
description: op.description,
|
|
408
|
+
tags: op.tags,
|
|
409
|
+
parameters: v3Params,
|
|
410
|
+
responses: v3Responses
|
|
411
|
+
};
|
|
412
|
+
if (requestBody) {
|
|
413
|
+
result.requestBody = requestBody;
|
|
414
|
+
}
|
|
415
|
+
return result;
|
|
416
|
+
}
|
|
417
|
+
var init_openapi = () => {};
|
|
418
|
+
|
|
419
|
+
// src/lib/api-routes.ts
|
|
420
|
+
import slugify from "slugify";
|
|
421
|
+
function getSpecSlug(spec) {
|
|
422
|
+
return slugify(spec.name, { lower: true, strict: true });
|
|
423
|
+
}
|
|
424
|
+
var init_api_routes = () => {};
|
|
425
|
+
|
|
426
|
+
// src/server/build-search-index.ts
|
|
427
|
+
var exports_build_search_index = {};
|
|
428
|
+
__export(exports_build_search_index, {
|
|
429
|
+
generateSearchIndex: () => generateSearchIndex
|
|
430
|
+
});
|
|
431
|
+
import fs5 from "fs/promises";
|
|
432
|
+
import path9 from "path";
|
|
433
|
+
import matter from "gray-matter";
|
|
434
|
+
function extractHeadings(markdown) {
|
|
435
|
+
const headingRegex = /^#{1,6}\s+(.+)$/gm;
|
|
436
|
+
const headings = [];
|
|
437
|
+
let match;
|
|
438
|
+
while ((match = headingRegex.exec(markdown)) !== null) {
|
|
439
|
+
headings.push(match[1].trim());
|
|
440
|
+
}
|
|
441
|
+
return headings.join(" ");
|
|
442
|
+
}
|
|
443
|
+
async function scanContent(contentDir) {
|
|
444
|
+
const docs = [];
|
|
445
|
+
async function scan(dir, prefix = []) {
|
|
446
|
+
let entries;
|
|
447
|
+
try {
|
|
448
|
+
entries = await fs5.readdir(dir, { withFileTypes: true });
|
|
449
|
+
} catch {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
for (const entry of entries) {
|
|
453
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
454
|
+
continue;
|
|
455
|
+
const fullPath = path9.join(dir, entry.name);
|
|
456
|
+
if (entry.isDirectory()) {
|
|
457
|
+
await scan(fullPath, [...prefix, entry.name]);
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (!entry.name.endsWith(".mdx") && !entry.name.endsWith(".md"))
|
|
461
|
+
continue;
|
|
462
|
+
const raw = await fs5.readFile(fullPath, "utf-8");
|
|
463
|
+
const { data: fm, content } = matter(raw);
|
|
464
|
+
const baseName = entry.name.replace(/\.(mdx|md)$/, "");
|
|
465
|
+
const slugs = baseName === "index" ? prefix : [...prefix, baseName];
|
|
466
|
+
const url = slugs.length === 0 ? "/" : "/" + slugs.join("/");
|
|
467
|
+
docs.push({
|
|
468
|
+
id: url,
|
|
469
|
+
url,
|
|
470
|
+
title: fm.title ?? baseName,
|
|
471
|
+
content: extractHeadings(content),
|
|
472
|
+
type: "page"
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
await scan(contentDir);
|
|
477
|
+
return docs;
|
|
478
|
+
}
|
|
479
|
+
function buildApiDocs() {
|
|
480
|
+
const config = loadConfig();
|
|
481
|
+
if (!config.api?.length)
|
|
482
|
+
return [];
|
|
483
|
+
const docs = [];
|
|
484
|
+
const specs = loadApiSpecs(config.api);
|
|
485
|
+
for (const spec of specs) {
|
|
486
|
+
const specSlug = getSpecSlug(spec);
|
|
487
|
+
const paths = spec.document.paths ?? {};
|
|
488
|
+
for (const [, pathItem] of Object.entries(paths)) {
|
|
489
|
+
if (!pathItem)
|
|
490
|
+
continue;
|
|
491
|
+
for (const method of ["get", "post", "put", "delete", "patch"]) {
|
|
492
|
+
const op = pathItem[method];
|
|
493
|
+
if (!op?.operationId)
|
|
494
|
+
continue;
|
|
495
|
+
const url = `/apis/${specSlug}/${encodeURIComponent(op.operationId)}`;
|
|
496
|
+
docs.push({
|
|
497
|
+
id: url,
|
|
498
|
+
url,
|
|
499
|
+
title: `${method.toUpperCase()} ${op.summary ?? op.operationId}`,
|
|
500
|
+
content: op.description ?? "",
|
|
501
|
+
type: "api"
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return docs;
|
|
507
|
+
}
|
|
508
|
+
async function generateSearchIndex(contentDir, outDir) {
|
|
509
|
+
const [contentDocs, apiDocs] = await Promise.all([
|
|
510
|
+
scanContent(contentDir),
|
|
511
|
+
Promise.resolve(buildApiDocs())
|
|
512
|
+
]);
|
|
513
|
+
const documents = [...contentDocs, ...apiDocs];
|
|
514
|
+
const outPath = path9.join(outDir, "search-index.json");
|
|
515
|
+
await fs5.writeFile(outPath, JSON.stringify(documents));
|
|
516
|
+
return documents.length;
|
|
517
|
+
}
|
|
518
|
+
var init_build_search_index = __esm(() => {
|
|
519
|
+
init_config();
|
|
520
|
+
init_openapi();
|
|
521
|
+
init_api_routes();
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
// src/server/adapters/vercel.ts
|
|
525
|
+
var exports_vercel = {};
|
|
526
|
+
__export(exports_vercel, {
|
|
527
|
+
buildVercelOutput: () => buildVercelOutput
|
|
528
|
+
});
|
|
529
|
+
import path10 from "path";
|
|
530
|
+
import fs6 from "fs/promises";
|
|
531
|
+
import { existsSync } from "fs";
|
|
532
|
+
import chalk5 from "chalk";
|
|
533
|
+
async function buildVercelOutput(options) {
|
|
534
|
+
const { distDir, contentDir, projectRoot } = options;
|
|
535
|
+
const outputDir = path10.resolve(projectRoot, ".vercel/output");
|
|
536
|
+
console.log(chalk5.gray("Generating Vercel output..."));
|
|
537
|
+
await fs6.rm(outputDir, { recursive: true, force: true });
|
|
538
|
+
const staticDir = path10.resolve(outputDir, "static");
|
|
539
|
+
const funcDir = path10.resolve(outputDir, "functions/index.func");
|
|
540
|
+
await fs6.mkdir(staticDir, { recursive: true });
|
|
541
|
+
await fs6.mkdir(funcDir, { recursive: true });
|
|
542
|
+
const clientDir = path10.resolve(distDir, "client");
|
|
543
|
+
await copyDir(clientDir, staticDir);
|
|
544
|
+
console.log(chalk5.gray(" Copied client assets to static/"));
|
|
545
|
+
if (existsSync(contentDir)) {
|
|
546
|
+
await copyContentAssets(contentDir, staticDir);
|
|
547
|
+
console.log(chalk5.gray(" Copied content assets to static/"));
|
|
548
|
+
}
|
|
549
|
+
const serverDir = path10.resolve(distDir, "server");
|
|
550
|
+
await copyDir(serverDir, funcDir);
|
|
551
|
+
console.log(chalk5.gray(" Copied server bundle to functions/"));
|
|
552
|
+
const templateSrc = path10.resolve(clientDir, "src/server/index.html");
|
|
553
|
+
await fs6.copyFile(templateSrc, path10.resolve(funcDir, "index.html"));
|
|
554
|
+
await fs6.writeFile(path10.resolve(funcDir, "package.json"), JSON.stringify({ type: "module" }, null, 2));
|
|
555
|
+
await fs6.writeFile(path10.resolve(funcDir, ".vc-config.json"), JSON.stringify({
|
|
556
|
+
runtime: "nodejs24.x",
|
|
557
|
+
handler: "entry-vercel.js",
|
|
558
|
+
launcherType: "Nodejs"
|
|
559
|
+
}, null, 2));
|
|
560
|
+
await fs6.writeFile(path10.resolve(outputDir, "config.json"), JSON.stringify({
|
|
561
|
+
version: 3,
|
|
562
|
+
routes: [
|
|
563
|
+
{ handle: "filesystem" },
|
|
564
|
+
{ src: "/(.*)", dest: "/index" }
|
|
565
|
+
]
|
|
566
|
+
}, null, 2));
|
|
567
|
+
console.log(chalk5.green("Vercel output generated →"), outputDir);
|
|
568
|
+
}
|
|
569
|
+
async function copyDir(src, dest) {
|
|
570
|
+
await fs6.mkdir(dest, { recursive: true });
|
|
571
|
+
const entries = await fs6.readdir(src, { withFileTypes: true });
|
|
572
|
+
for (const entry of entries) {
|
|
573
|
+
const srcPath = path10.join(src, entry.name);
|
|
574
|
+
const destPath = path10.join(dest, entry.name);
|
|
575
|
+
if (entry.isDirectory()) {
|
|
576
|
+
await copyDir(srcPath, destPath);
|
|
577
|
+
} else {
|
|
578
|
+
await fs6.copyFile(srcPath, destPath);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
async function copyContentAssets(contentDir, staticDir) {
|
|
583
|
+
const entries = await fs6.readdir(contentDir, { withFileTypes: true });
|
|
584
|
+
for (const entry of entries) {
|
|
585
|
+
const srcPath = path10.join(contentDir, entry.name);
|
|
586
|
+
if (entry.isDirectory()) {
|
|
587
|
+
const destSubDir = path10.join(staticDir, entry.name);
|
|
588
|
+
await copyContentAssetsRecursive(srcPath, destSubDir);
|
|
589
|
+
} else {
|
|
590
|
+
const ext = path10.extname(entry.name).toLowerCase();
|
|
591
|
+
if (CONTENT_EXTENSIONS.has(ext)) {
|
|
592
|
+
await fs6.copyFile(srcPath, path10.join(staticDir, entry.name));
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
async function copyContentAssetsRecursive(srcDir, destDir) {
|
|
598
|
+
const entries = await fs6.readdir(srcDir, { withFileTypes: true });
|
|
599
|
+
for (const entry of entries) {
|
|
600
|
+
const srcPath = path10.join(srcDir, entry.name);
|
|
601
|
+
if (entry.isDirectory()) {
|
|
602
|
+
await copyContentAssetsRecursive(srcPath, path10.join(destDir, entry.name));
|
|
603
|
+
} else {
|
|
604
|
+
const ext = path10.extname(entry.name).toLowerCase();
|
|
605
|
+
if (CONTENT_EXTENSIONS.has(ext)) {
|
|
606
|
+
await fs6.mkdir(destDir, { recursive: true });
|
|
607
|
+
await fs6.copyFile(srcPath, path10.join(destDir, entry.name));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
var CONTENT_EXTENSIONS;
|
|
613
|
+
var init_vercel = __esm(() => {
|
|
614
|
+
CONTENT_EXTENSIONS = new Set([
|
|
615
|
+
".png",
|
|
616
|
+
".jpg",
|
|
617
|
+
".jpeg",
|
|
618
|
+
".gif",
|
|
619
|
+
".svg",
|
|
620
|
+
".webp",
|
|
621
|
+
".ico",
|
|
622
|
+
".pdf",
|
|
623
|
+
".json",
|
|
624
|
+
".yaml",
|
|
625
|
+
".yml",
|
|
626
|
+
".txt"
|
|
627
|
+
]);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
// src/server/prod.ts
|
|
631
|
+
var exports_prod = {};
|
|
632
|
+
__export(exports_prod, {
|
|
633
|
+
startProdServer: () => startProdServer
|
|
634
|
+
});
|
|
635
|
+
import path12 from "path";
|
|
636
|
+
import chalk7 from "chalk";
|
|
637
|
+
async function startProdServer(options) {
|
|
638
|
+
const { port, distDir } = options;
|
|
639
|
+
const serverEntry = path12.resolve(distDir, "server/entry-prod.js");
|
|
640
|
+
const { startServer } = await import(serverEntry);
|
|
641
|
+
console.log(chalk7.cyan("Starting production server..."));
|
|
642
|
+
return startServer({ port, distDir });
|
|
643
|
+
}
|
|
644
|
+
var init_prod = () => {};
|
|
645
|
+
|
|
646
|
+
// src/cli/index.ts
|
|
647
|
+
import { Command as Command6 } from "commander";
|
|
648
|
+
|
|
649
|
+
// src/cli/commands/init.ts
|
|
650
|
+
import { Command } from "commander";
|
|
651
|
+
import { execSync } from "child_process";
|
|
652
|
+
import fs2 from "fs";
|
|
653
|
+
import path3 from "path";
|
|
654
|
+
import chalk from "chalk";
|
|
655
|
+
import { stringify } from "yaml";
|
|
656
|
+
|
|
657
|
+
// src/cli/utils/scaffold.ts
|
|
658
|
+
import fs from "fs";
|
|
659
|
+
import path2 from "path";
|
|
660
|
+
|
|
661
|
+
// src/cli/utils/resolve.ts
|
|
662
|
+
import path from "path";
|
|
663
|
+
import { fileURLToPath } from "url";
|
|
664
|
+
var PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
665
|
+
|
|
666
|
+
// src/cli/utils/scaffold.ts
|
|
667
|
+
function detectPackageManager() {
|
|
668
|
+
if (process.env.npm_config_user_agent) {
|
|
669
|
+
return process.env.npm_config_user_agent.split("/")[0];
|
|
670
|
+
}
|
|
671
|
+
const cwd = process.cwd();
|
|
672
|
+
if (fs.existsSync(path2.join(cwd, "bun.lock")) || fs.existsSync(path2.join(cwd, "bun.lockb")))
|
|
673
|
+
return "bun";
|
|
674
|
+
if (fs.existsSync(path2.join(cwd, "pnpm-lock.yaml")))
|
|
675
|
+
return "pnpm";
|
|
676
|
+
if (fs.existsSync(path2.join(cwd, "yarn.lock")))
|
|
677
|
+
return "yarn";
|
|
678
|
+
return "npm";
|
|
679
|
+
}
|
|
680
|
+
function getChronicleVersion() {
|
|
681
|
+
const pkgPath = path2.join(PACKAGE_ROOT, "package.json");
|
|
682
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
683
|
+
return pkg.version;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/cli/commands/init.ts
|
|
687
|
+
function createConfig() {
|
|
688
|
+
return {
|
|
689
|
+
title: "My Documentation",
|
|
690
|
+
description: "Documentation powered by Chronicle",
|
|
691
|
+
theme: { name: "default" },
|
|
692
|
+
search: { enabled: true, placeholder: "Search documentation..." }
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
function createPackageJson(name) {
|
|
696
|
+
return {
|
|
697
|
+
name,
|
|
698
|
+
private: true,
|
|
699
|
+
type: "module",
|
|
700
|
+
scripts: {
|
|
701
|
+
dev: "chronicle dev",
|
|
702
|
+
build: "chronicle build",
|
|
703
|
+
start: "chronicle start"
|
|
704
|
+
},
|
|
705
|
+
dependencies: {
|
|
706
|
+
"@raystack/chronicle": `^${getChronicleVersion()}`
|
|
707
|
+
},
|
|
708
|
+
devDependencies: {
|
|
709
|
+
"@raystack/tools-config": "0.56.0",
|
|
710
|
+
"openapi-types": "^12.1.3",
|
|
711
|
+
typescript: "5.9.3",
|
|
712
|
+
"@types/react": "^19.2.10",
|
|
713
|
+
"@types/node": "^25.1.0"
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
var sampleMdx = `---
|
|
718
|
+
title: Welcome
|
|
719
|
+
description: Getting started with your documentation
|
|
720
|
+
order: 1
|
|
721
|
+
---
|
|
722
|
+
|
|
723
|
+
# Welcome
|
|
724
|
+
|
|
725
|
+
This is your documentation home page.
|
|
726
|
+
`;
|
|
727
|
+
var initCommand = new Command("init").description("Initialize a new Chronicle project").option("-c, --content <path>", "Content directory name", "content").action((options) => {
|
|
728
|
+
const projectDir = process.cwd();
|
|
729
|
+
const dirName = path3.basename(projectDir) || "docs";
|
|
730
|
+
const contentDir = path3.join(projectDir, options.content);
|
|
731
|
+
if (!fs2.existsSync(contentDir)) {
|
|
732
|
+
fs2.mkdirSync(contentDir, { recursive: true });
|
|
733
|
+
console.log(chalk.green("✓"), "Created", contentDir);
|
|
734
|
+
}
|
|
735
|
+
const packageJsonPath = path3.join(projectDir, "package.json");
|
|
736
|
+
if (!fs2.existsSync(packageJsonPath)) {
|
|
737
|
+
fs2.writeFileSync(packageJsonPath, JSON.stringify(createPackageJson(dirName), null, 2) + `
|
|
738
|
+
`);
|
|
739
|
+
console.log(chalk.green("✓"), "Created", packageJsonPath);
|
|
740
|
+
} else {
|
|
741
|
+
const existing = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
|
|
742
|
+
const template = createPackageJson(dirName);
|
|
743
|
+
let updated = false;
|
|
744
|
+
if (existing.type !== "module") {
|
|
745
|
+
existing.type = "module";
|
|
746
|
+
updated = true;
|
|
747
|
+
}
|
|
748
|
+
if (!existing.scripts)
|
|
749
|
+
existing.scripts = {};
|
|
750
|
+
for (const [key, value] of Object.entries(template.scripts)) {
|
|
751
|
+
if (!existing.scripts[key]) {
|
|
752
|
+
existing.scripts[key] = value;
|
|
753
|
+
updated = true;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (!existing.dependencies)
|
|
757
|
+
existing.dependencies = {};
|
|
758
|
+
for (const [key, value] of Object.entries(template.dependencies)) {
|
|
759
|
+
if (!existing.dependencies[key]) {
|
|
760
|
+
existing.dependencies[key] = value;
|
|
761
|
+
updated = true;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
if (!existing.devDependencies)
|
|
765
|
+
existing.devDependencies = {};
|
|
766
|
+
for (const [key, value] of Object.entries(template.devDependencies)) {
|
|
767
|
+
if (!existing.devDependencies[key]) {
|
|
768
|
+
existing.devDependencies[key] = value;
|
|
769
|
+
updated = true;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
if (updated) {
|
|
773
|
+
fs2.writeFileSync(packageJsonPath, JSON.stringify(existing, null, 2) + `
|
|
774
|
+
`);
|
|
775
|
+
console.log(chalk.green("✓"), "Updated", packageJsonPath);
|
|
776
|
+
} else {
|
|
777
|
+
console.log(chalk.yellow("⚠"), packageJsonPath, "already has all required entries");
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const configPath = path3.join(projectDir, "chronicle.yaml");
|
|
781
|
+
if (!fs2.existsSync(configPath)) {
|
|
782
|
+
fs2.writeFileSync(configPath, stringify(createConfig()));
|
|
783
|
+
console.log(chalk.green("✓"), "Created", configPath);
|
|
784
|
+
} else {
|
|
785
|
+
console.log(chalk.yellow("⚠"), configPath, "already exists");
|
|
786
|
+
}
|
|
787
|
+
const contentFiles = fs2.readdirSync(contentDir);
|
|
788
|
+
if (contentFiles.length === 0) {
|
|
789
|
+
const indexPath = path3.join(contentDir, "index.mdx");
|
|
790
|
+
fs2.writeFileSync(indexPath, sampleMdx);
|
|
791
|
+
console.log(chalk.green("✓"), "Created", indexPath);
|
|
792
|
+
}
|
|
793
|
+
const gitignorePath = path3.join(projectDir, ".gitignore");
|
|
794
|
+
const gitignoreEntries = ["node_modules", "dist"];
|
|
795
|
+
if (fs2.existsSync(gitignorePath)) {
|
|
796
|
+
const existing = fs2.readFileSync(gitignorePath, "utf-8");
|
|
797
|
+
const missing = gitignoreEntries.filter((e) => !existing.includes(e));
|
|
798
|
+
if (missing.length > 0) {
|
|
799
|
+
fs2.appendFileSync(gitignorePath, `
|
|
800
|
+
${missing.join(`
|
|
801
|
+
`)}
|
|
802
|
+
`);
|
|
803
|
+
console.log(chalk.green("✓"), "Added", missing.join(", "), "to .gitignore");
|
|
804
|
+
}
|
|
805
|
+
} else {
|
|
806
|
+
fs2.writeFileSync(gitignorePath, `${gitignoreEntries.join(`
|
|
807
|
+
`)}
|
|
808
|
+
`);
|
|
809
|
+
console.log(chalk.green("✓"), "Created .gitignore");
|
|
810
|
+
}
|
|
811
|
+
const pm = detectPackageManager();
|
|
812
|
+
console.log(chalk.cyan(`
|
|
813
|
+
Installing dependencies with ${pm}...`));
|
|
814
|
+
execSync(`${pm} install`, { cwd: projectDir, stdio: "inherit" });
|
|
815
|
+
const runCmd = pm === "npm" ? "npx" : pm === "bun" ? "bunx" : `${pm} dlx`;
|
|
816
|
+
console.log(chalk.green(`
|
|
817
|
+
✓ Chronicle initialized!`));
|
|
818
|
+
console.log(`
|
|
819
|
+
Run`, chalk.cyan(`${runCmd} chronicle dev`), "to start development server");
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
// src/cli/commands/dev.ts
|
|
823
|
+
import { Command as Command2 } from "commander";
|
|
824
|
+
import chalk4 from "chalk";
|
|
825
|
+
|
|
826
|
+
// src/cli/utils/config.ts
|
|
827
|
+
import path4 from "path";
|
|
828
|
+
import { parse } from "yaml";
|
|
829
|
+
import chalk2 from "chalk";
|
|
830
|
+
function resolveContentDir(contentFlag) {
|
|
831
|
+
if (contentFlag)
|
|
832
|
+
return path4.resolve(contentFlag);
|
|
833
|
+
if (process.env.CHRONICLE_CONTENT_DIR)
|
|
834
|
+
return path4.resolve(process.env.CHRONICLE_CONTENT_DIR);
|
|
835
|
+
return path4.resolve("content");
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// src/cli/commands/dev.ts
|
|
839
|
+
var devCommand = new Command2("dev").description("Start development server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").action(async (options) => {
|
|
840
|
+
const contentDir = resolveContentDir(options.content);
|
|
841
|
+
const port = parseInt(options.port, 10);
|
|
842
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
|
|
843
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir;
|
|
844
|
+
console.log(chalk4.cyan("Starting dev server..."));
|
|
845
|
+
const { startDevServer: startDevServer2 } = await Promise.resolve().then(() => (init_dev(), exports_dev));
|
|
846
|
+
await startDevServer2({ port, root: PACKAGE_ROOT, contentDir });
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// src/cli/commands/build.ts
|
|
850
|
+
import { Command as Command3 } from "commander";
|
|
851
|
+
import path11 from "path";
|
|
852
|
+
import chalk6 from "chalk";
|
|
853
|
+
var buildCommand = new Command3("build").description("Build for production").option("-c, --content <path>", "Content directory").option("-o, --outDir <path>", "Output directory", "dist").option("--adapter <adapter>", "Deploy adapter (vercel)").action(async (options) => {
|
|
854
|
+
const contentDir = resolveContentDir(options.content);
|
|
855
|
+
const outDir = path11.resolve(options.outDir);
|
|
856
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
|
|
857
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir;
|
|
858
|
+
console.log(chalk6.cyan("Building for production..."));
|
|
859
|
+
const { build } = await import("vite");
|
|
860
|
+
const { createViteConfig: createViteConfig2 } = await Promise.resolve().then(() => (init_vite_config(), exports_vite_config));
|
|
861
|
+
const baseConfig = await createViteConfig2({ root: PACKAGE_ROOT, contentDir });
|
|
862
|
+
console.log(chalk6.gray("Building client..."));
|
|
863
|
+
await build({
|
|
864
|
+
...baseConfig,
|
|
865
|
+
build: {
|
|
866
|
+
outDir: path11.join(outDir, "client"),
|
|
867
|
+
ssrManifest: true,
|
|
868
|
+
rolldownOptions: {
|
|
869
|
+
input: path11.resolve(PACKAGE_ROOT, "src/server/index.html")
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
const serverEntry = options.adapter === "vercel" ? path11.resolve(PACKAGE_ROOT, "src/server/entry-vercel.ts") : path11.resolve(PACKAGE_ROOT, "src/server/entry-prod.ts");
|
|
874
|
+
console.log(chalk6.gray("Building server..."));
|
|
875
|
+
await build({
|
|
876
|
+
...baseConfig,
|
|
877
|
+
ssr: {
|
|
878
|
+
noExternal: true
|
|
879
|
+
},
|
|
880
|
+
build: {
|
|
881
|
+
outDir: path11.join(outDir, "server"),
|
|
882
|
+
ssr: serverEntry,
|
|
883
|
+
target: "node22"
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
console.log(chalk6.gray("Building search index..."));
|
|
887
|
+
const { generateSearchIndex: generateSearchIndex2 } = await Promise.resolve().then(() => (init_build_search_index(), exports_build_search_index));
|
|
888
|
+
const docCount = await generateSearchIndex2(contentDir, path11.join(outDir, "server"));
|
|
889
|
+
console.log(chalk6.gray(` Indexed ${docCount} documents`));
|
|
890
|
+
console.log(chalk6.green("Build complete →"), outDir);
|
|
891
|
+
if (options.adapter === "vercel") {
|
|
892
|
+
const { buildVercelOutput: buildVercelOutput2 } = await Promise.resolve().then(() => (init_vercel(), exports_vercel));
|
|
893
|
+
await buildVercelOutput2({
|
|
894
|
+
distDir: outDir,
|
|
895
|
+
contentDir,
|
|
896
|
+
projectRoot: process.cwd()
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
// src/cli/commands/start.ts
|
|
902
|
+
import { Command as Command4 } from "commander";
|
|
903
|
+
import path13 from "path";
|
|
904
|
+
import chalk8 from "chalk";
|
|
905
|
+
var startCommand = new Command4("start").description("Start production server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").option("-d, --dist <path>", "Dist directory", "dist").action(async (options) => {
|
|
906
|
+
const contentDir = resolveContentDir(options.content);
|
|
907
|
+
const port = parseInt(options.port, 10);
|
|
908
|
+
const distDir = path13.resolve(options.dist);
|
|
909
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
|
|
910
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir;
|
|
911
|
+
console.log(chalk8.cyan("Starting production server..."));
|
|
912
|
+
const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prod(), exports_prod));
|
|
913
|
+
await startProdServer2({ port, root: PACKAGE_ROOT, distDir });
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
// src/cli/commands/serve.ts
|
|
917
|
+
import { Command as Command5 } from "commander";
|
|
918
|
+
import path14 from "path";
|
|
919
|
+
import chalk9 from "chalk";
|
|
920
|
+
var serveCommand = new Command5("serve").description("Build and start production server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").option("-o, --outDir <path>", "Output directory", "dist").action(async (options) => {
|
|
921
|
+
const contentDir = resolveContentDir(options.content);
|
|
922
|
+
const port = parseInt(options.port, 10);
|
|
923
|
+
const outDir = path14.resolve(options.outDir);
|
|
924
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
|
|
925
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir;
|
|
926
|
+
console.log(chalk9.cyan("Building for production..."));
|
|
927
|
+
const { build } = await import("vite");
|
|
928
|
+
const { createViteConfig: createViteConfig2 } = await Promise.resolve().then(() => (init_vite_config(), exports_vite_config));
|
|
929
|
+
const baseConfig = await createViteConfig2({ root: PACKAGE_ROOT, contentDir });
|
|
930
|
+
await build({
|
|
931
|
+
...baseConfig,
|
|
932
|
+
build: {
|
|
933
|
+
outDir: path14.join(outDir, "client"),
|
|
934
|
+
ssrManifest: true,
|
|
935
|
+
rolldownOptions: {
|
|
936
|
+
input: path14.resolve(PACKAGE_ROOT, "src/server/index.html")
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
await build({
|
|
941
|
+
...baseConfig,
|
|
942
|
+
ssr: {
|
|
943
|
+
noExternal: true
|
|
944
|
+
},
|
|
945
|
+
build: {
|
|
946
|
+
outDir: path14.join(outDir, "server"),
|
|
947
|
+
ssr: path14.resolve(PACKAGE_ROOT, "src/server/entry-prod.ts")
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
console.log(chalk9.cyan("Starting production server..."));
|
|
951
|
+
const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prod(), exports_prod));
|
|
952
|
+
await startProdServer2({ port, root: PACKAGE_ROOT, distDir: outDir });
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
// src/cli/index.ts
|
|
956
|
+
var program = new Command6;
|
|
957
|
+
program.name("chronicle").description("Config-driven documentation framework").version("0.1.0");
|
|
958
|
+
program.addCommand(initCommand);
|
|
959
|
+
program.addCommand(devCommand);
|
|
960
|
+
program.addCommand(buildCommand);
|
|
961
|
+
program.addCommand(startCommand);
|
|
962
|
+
program.addCommand(serveCommand);
|
|
963
|
+
program.parse();
|