@raystack/chronicle 0.1.0-canary.5a730d4 → 0.1.0-canary.67113f8

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.
Files changed (85) hide show
  1. package/dist/cli/index.js +217 -412
  2. package/package.json +13 -10
  3. package/src/cli/commands/build.ts +30 -48
  4. package/src/cli/commands/dev.ts +24 -13
  5. package/src/cli/commands/init.ts +38 -123
  6. package/src/cli/commands/serve.ts +35 -50
  7. package/src/cli/commands/start.ts +20 -16
  8. package/src/cli/index.ts +14 -14
  9. package/src/cli/utils/config.ts +25 -26
  10. package/src/cli/utils/index.ts +3 -2
  11. package/src/cli/utils/resolve.ts +7 -3
  12. package/src/cli/utils/scaffold.ts +14 -16
  13. package/src/components/mdx/details.module.css +0 -2
  14. package/src/components/mdx/image.tsx +5 -20
  15. package/src/components/mdx/index.tsx +18 -4
  16. package/src/components/mdx/link.tsx +24 -20
  17. package/src/components/ui/breadcrumbs.tsx +8 -42
  18. package/src/components/ui/footer.tsx +2 -3
  19. package/src/components/ui/search.tsx +116 -72
  20. package/src/lib/api-routes.ts +6 -8
  21. package/src/lib/config.ts +31 -29
  22. package/src/lib/get-llm-text.ts +10 -0
  23. package/src/lib/head.tsx +26 -22
  24. package/src/lib/mdx-loader.ts +21 -0
  25. package/src/lib/openapi.ts +8 -8
  26. package/src/lib/page-context.tsx +74 -58
  27. package/src/lib/source.ts +136 -114
  28. package/src/pages/ApiLayout.tsx +22 -18
  29. package/src/pages/ApiPage.tsx +32 -27
  30. package/src/pages/DocsLayout.tsx +7 -7
  31. package/src/pages/DocsPage.tsx +11 -11
  32. package/src/pages/NotFound.tsx +11 -4
  33. package/src/server/App.tsx +35 -27
  34. package/src/server/api/apis-proxy.ts +69 -0
  35. package/src/server/api/health.ts +5 -0
  36. package/src/server/api/page/[...slug].ts +17 -0
  37. package/src/server/api/search.ts +170 -0
  38. package/src/server/api/specs.ts +9 -0
  39. package/src/server/build-search-index.ts +117 -0
  40. package/src/server/entry-client.tsx +47 -55
  41. package/src/server/entry-server.tsx +100 -35
  42. package/src/server/routes/llms.txt.ts +61 -0
  43. package/src/server/routes/og.tsx +75 -0
  44. package/src/server/routes/robots.txt.ts +11 -0
  45. package/src/server/routes/sitemap.xml.ts +40 -0
  46. package/src/server/utils/safe-path.ts +17 -0
  47. package/src/server/vite-config.ts +90 -44
  48. package/src/themes/default/Layout.tsx +78 -47
  49. package/src/themes/default/Page.module.css +0 -12
  50. package/src/themes/default/Page.tsx +9 -11
  51. package/src/themes/default/Toc.tsx +25 -39
  52. package/src/themes/default/index.ts +7 -9
  53. package/src/themes/paper/ChapterNav.tsx +63 -43
  54. package/src/themes/paper/Layout.module.css +1 -1
  55. package/src/themes/paper/Layout.tsx +24 -12
  56. package/src/themes/paper/Page.module.css +16 -4
  57. package/src/themes/paper/Page.tsx +56 -62
  58. package/src/themes/paper/ReadingProgress.tsx +160 -139
  59. package/src/themes/paper/index.ts +5 -5
  60. package/src/themes/registry.ts +7 -7
  61. package/src/types/content.ts +5 -21
  62. package/src/types/globals.d.ts +3 -0
  63. package/src/types/theme.ts +4 -3
  64. package/src/cli/__tests__/config.test.ts +0 -25
  65. package/src/cli/__tests__/scaffold.test.ts +0 -10
  66. package/src/pages/__tests__/head.test.tsx +0 -57
  67. package/src/server/__tests__/entry-server.test.tsx +0 -35
  68. package/src/server/__tests__/handlers.test.ts +0 -77
  69. package/src/server/__tests__/og.test.ts +0 -23
  70. package/src/server/__tests__/router.test.ts +0 -72
  71. package/src/server/__tests__/vite-config.test.ts +0 -25
  72. package/src/server/dev.ts +0 -156
  73. package/src/server/entry-prod.ts +0 -127
  74. package/src/server/handlers/apis-proxy.ts +0 -52
  75. package/src/server/handlers/health.ts +0 -3
  76. package/src/server/handlers/llms.ts +0 -58
  77. package/src/server/handlers/og.ts +0 -87
  78. package/src/server/handlers/robots.ts +0 -11
  79. package/src/server/handlers/search.ts +0 -140
  80. package/src/server/handlers/sitemap.ts +0 -39
  81. package/src/server/handlers/specs.ts +0 -9
  82. package/src/server/index.html +0 -12
  83. package/src/server/prod.ts +0 -18
  84. package/src/server/router.ts +0 -42
  85. package/src/themes/default/font.ts +0 -4
package/dist/cli/index.js CHANGED
@@ -16,49 +16,109 @@ var __export = (target, all) => {
16
16
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
17
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
18
18
 
19
+ // src/lib/remark-unused-directives.ts
20
+ import { visit } from "unist-util-visit";
21
+ var remarkUnusedDirectives = () => {
22
+ return (tree) => {
23
+ visit(tree, ["textDirective"], (node) => {
24
+ const directive = node;
25
+ if (!directive.data) {
26
+ const hasAttributes = directive.attributes && Object.keys(directive.attributes).length > 0;
27
+ const hasChildren = directive.children && directive.children.length > 0;
28
+ if (!hasAttributes && !hasChildren) {
29
+ const name = directive.name;
30
+ if (!name)
31
+ return;
32
+ Object.keys(directive).forEach((key) => delete directive[key]);
33
+ directive.type = "text";
34
+ directive.value = `:${name}`;
35
+ }
36
+ }
37
+ });
38
+ };
39
+ }, remark_unused_directives_default;
40
+ var init_remark_unused_directives = __esm(() => {
41
+ remark_unused_directives_default = remarkUnusedDirectives;
42
+ });
43
+
19
44
  // src/server/vite-config.ts
20
45
  var exports_vite_config = {};
21
46
  __export(exports_vite_config, {
22
47
  createViteConfig: () => createViteConfig
23
48
  });
24
- import path5 from "path";
25
49
  import react from "@vitejs/plugin-react";
26
- import mdx from "@mdx-js/rollup";
50
+ import { remarkDirectiveAdmonition, remarkMdxMermaid } from "fumadocs-core/mdx-plugins";
51
+ import { defineConfig as defineFumadocsConfig } from "fumadocs-mdx/config";
52
+ import mdx from "fumadocs-mdx/vite";
53
+ import { nitro } from "nitro/vite";
54
+ import path4 from "node:path";
27
55
  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";
56
+ function resolveOutputDir(projectRoot, preset) {
57
+ if (preset === "vercel" || preset === "vercel-static")
58
+ return path4.resolve(projectRoot, ".vercel/output");
59
+ return path4.resolve(projectRoot, ".output");
60
+ }
32
61
  async function createViteConfig(options) {
33
- const { root, contentDir, isDev = false } = options;
62
+ const { packageRoot, projectRoot, contentDir, preset } = options;
34
63
  return {
35
- root,
64
+ root: packageRoot,
36
65
  configFile: false,
37
- resolve: {
38
- alias: {
39
- "@": path5.resolve(root, "src"),
40
- "@content": contentDir
41
- }
42
- },
43
66
  plugins: [
44
- mdx({
45
- remarkPlugins: [
46
- remarkFrontmatter,
47
- remarkMdxFrontmatter,
48
- remarkGfm,
49
- remarkDirective
50
- ],
51
- rehypePlugins: [
52
- [rehypeShiki, { themes: { light: "github-light", dark: "github-dark" } }]
53
- ],
54
- mdExtensions: [".md"],
55
- mdxExtensions: [".mdx"]
67
+ nitro({
68
+ serverDir: path4.resolve(packageRoot, "src/server"),
69
+ ...preset && { preset }
56
70
  }),
71
+ mdx({
72
+ default: defineFumadocsConfig({
73
+ mdxOptions: {
74
+ remarkPlugins: [
75
+ remarkDirective,
76
+ [remarkDirectiveAdmonition, {
77
+ tags: {
78
+ CalloutContainer: "Callout",
79
+ CalloutTitle: "CalloutTitle",
80
+ CalloutDescription: "CalloutDescription"
81
+ },
82
+ types: {
83
+ note: "accent",
84
+ tip: "accent",
85
+ info: "accent",
86
+ warn: "attention",
87
+ warning: "attention",
88
+ danger: "alert",
89
+ caution: "alert",
90
+ success: "success"
91
+ }
92
+ }],
93
+ remark_unused_directives_default,
94
+ remarkMdxMermaid
95
+ ]
96
+ }
97
+ })
98
+ }, { index: false }),
57
99
  react()
58
100
  ],
101
+ resolve: {
102
+ alias: {
103
+ "@": path4.resolve(packageRoot, "src")
104
+ },
105
+ conditions: ["module-sync", "import", "node"],
106
+ dedupe: [
107
+ "react",
108
+ "react-dom",
109
+ "react/jsx-runtime",
110
+ "react/jsx-dev-runtime",
111
+ "react-router"
112
+ ]
113
+ },
114
+ server: {
115
+ fs: {
116
+ allow: [packageRoot, projectRoot, contentDir]
117
+ }
118
+ },
59
119
  define: {
60
- "process.env.CHRONICLE_CONTENT_DIR": JSON.stringify(contentDir),
61
- "process.env.CHRONICLE_PROJECT_ROOT": JSON.stringify(root)
120
+ __CHRONICLE_CONTENT_DIR__: JSON.stringify(contentDir),
121
+ __CHRONICLE_PROJECT_ROOT__: JSON.stringify(projectRoot)
62
122
  },
63
123
  css: {
64
124
  modules: {
@@ -66,242 +126,114 @@ async function createViteConfig(options) {
66
126
  }
67
127
  },
68
128
  ssr: {
69
- noExternal: ["@raystack/apsara"]
129
+ noExternal: ["@raystack/apsara", "dayjs", "fumadocs-core"]
70
130
  },
71
- build: {
72
- rolldownOptions: {
73
- input: isDev ? undefined : {
74
- client: path5.resolve(root, "src/server/index.html")
75
- }
76
- }
77
- }
78
- };
79
- }
80
- var init_vite_config = () => {};
81
-
82
- // src/server/dev.ts
83
- var exports_dev = {};
84
- __export(exports_dev, {
85
- startDevServer: () => startDevServer
86
- });
87
- import { createServer as createViteServer } from "vite";
88
- import { createServer } from "http";
89
- import fsPromises from "fs/promises";
90
- import { createReadStream } from "fs";
91
- import path6 from "path";
92
- import chalk3 from "chalk";
93
- async function startDevServer(options) {
94
- const { port, root, contentDir } = options;
95
- const viteConfig = await createViteConfig({ root, contentDir, isDev: true });
96
- const vite = await createViteServer({
97
- ...viteConfig,
98
- server: { middlewareMode: true },
99
- appType: "custom"
100
- });
101
- const templatePath = path6.resolve(root, "src/server/index.html");
102
- const server = createServer(async (req, res) => {
103
- const url = req.url || "/";
104
- try {
105
- if (url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/node_modules/")) {
106
- vite.middlewares(req, res, () => {
107
- res.statusCode = 404;
108
- res.end();
109
- });
110
- return;
111
- }
112
- const contentFile = path6.join(contentDir, decodeURIComponent(url.split("?")[0]));
113
- if (!url.endsWith(".md") && !url.endsWith(".mdx")) {
114
- try {
115
- const stat = await fsPromises.stat(contentFile);
116
- if (stat.isFile()) {
117
- const ext = path6.extname(contentFile).toLowerCase();
118
- const mimeTypes = {
119
- ".png": "image/png",
120
- ".jpg": "image/jpeg",
121
- ".jpeg": "image/jpeg",
122
- ".gif": "image/gif",
123
- ".svg": "image/svg+xml",
124
- ".webp": "image/webp",
125
- ".ico": "image/x-icon",
126
- ".pdf": "application/pdf",
127
- ".json": "application/json",
128
- ".yaml": "text/yaml",
129
- ".yml": "text/yaml",
130
- ".txt": "text/plain"
131
- };
132
- res.setHeader("Content-Type", mimeTypes[ext] || "application/octet-stream");
133
- createReadStream(contentFile).pipe(res);
134
- return;
131
+ environments: {
132
+ client: {
133
+ build: {
134
+ rollupOptions: {
135
+ input: path4.resolve(packageRoot, "src/server/entry-client.tsx")
135
136
  }
136
- } catch {}
137
- }
138
- if (/\.(js|ts|tsx|css|map)(\?|$)/.test(url)) {
139
- vite.middlewares(req, res, () => {
140
- res.statusCode = 404;
141
- res.end();
142
- });
143
- return;
144
- }
145
- const { matchRoute } = await vite.ssrLoadModule(path6.resolve(root, "src/server/router.ts"));
146
- const routeHandler = matchRoute(new URL(url, `http://localhost:${port}`).href);
147
- if (routeHandler) {
148
- const request = new Request(new URL(url, `http://localhost:${port}`));
149
- const response = await routeHandler(request);
150
- res.statusCode = response.status;
151
- response.headers.forEach((value, key) => res.setHeader(key, value));
152
- const body = await response.text();
153
- res.end(body);
154
- return;
137
+ }
155
138
  }
156
- const pathname = new URL(url, `http://localhost:${port}`).pathname;
157
- const slug = pathname === "/" ? [] : pathname.slice(1).split("/").filter(Boolean);
158
- const source = await vite.ssrLoadModule(path6.resolve(root, "src/lib/source.ts"));
159
- const { mdxComponents } = await vite.ssrLoadModule(path6.resolve(root, "src/components/mdx/index.tsx"));
160
- const { loadConfig } = await vite.ssrLoadModule(path6.resolve(root, "src/lib/config.ts"));
161
- const config = loadConfig();
162
- const { loadApiSpecs } = await vite.ssrLoadModule(path6.resolve(root, "src/lib/openapi.ts"));
163
- const apiSpecs = config.api?.length ? loadApiSpecs(config.api) : [];
164
- const [tree, sourcePage] = await Promise.all([
165
- source.buildPageTree(),
166
- source.getPage(slug)
167
- ]);
168
- let pageData = null;
169
- let embeddedData = { config, tree, slug, frontmatter: null, filePath: null };
170
- if (sourcePage) {
171
- const component = await source.loadPageComponent(sourcePage);
172
- const React = await import("react");
173
- const MDXBody = component;
174
- pageData = {
175
- slug,
176
- frontmatter: sourcePage.frontmatter,
177
- content: MDXBody ? React.createElement(MDXBody, { components: mdxComponents }) : null
178
- };
179
- embeddedData.frontmatter = sourcePage.frontmatter;
180
- embeddedData.filePath = sourcePage.filePath;
139
+ },
140
+ nitro: {
141
+ output: {
142
+ dir: resolveOutputDir(projectRoot, preset)
181
143
  }
182
- let template = await fsPromises.readFile(templatePath, "utf-8");
183
- template = await vite.transformIndexHtml(url, template);
184
- const dataScript = `<script>window.__PAGE_DATA__ = ${JSON.stringify(embeddedData)}</script>`;
185
- template = template.replace("<!--head-outlet-->", `<!--head-outlet-->${dataScript}`);
186
- const { render } = await vite.ssrLoadModule(path6.resolve(root, "src/server/entry-server.tsx"));
187
- const html = render(url, { config, tree, page: pageData, apiSpecs });
188
- const finalHtml = template.replace("<!--ssr-outlet-->", html);
189
- res.setHeader("Content-Type", "text/html");
190
- res.statusCode = 200;
191
- res.end(finalHtml);
192
- } catch (e) {
193
- vite.ssrFixStacktrace(e);
194
- console.error(e);
195
- res.statusCode = 500;
196
- res.end(e.message);
197
144
  }
198
- });
199
- server.listen(port, () => {
200
- console.log(chalk3.cyan(`
201
- Chronicle dev server running at:`));
202
- console.log(chalk3.green(` http://localhost:${port}
203
- `));
204
- });
205
- const shutdown = () => {
206
- vite.close();
207
- server.close();
208
- process.exit(0);
209
145
  };
210
- process.on("SIGINT", shutdown);
211
- process.on("SIGTERM", shutdown);
212
- return { server, vite };
213
146
  }
214
- var init_dev = __esm(() => {
215
- init_vite_config();
147
+ var init_vite_config = __esm(() => {
148
+ init_remark_unused_directives();
216
149
  });
217
150
 
218
- // src/server/prod.ts
219
- var exports_prod = {};
220
- __export(exports_prod, {
221
- startProdServer: () => startProdServer
222
- });
223
- import path8 from "path";
224
- import chalk6 from "chalk";
225
- async function startProdServer(options) {
226
- const { port, distDir } = options;
227
- const serverEntry = path8.resolve(distDir, "server/entry-prod.js");
228
- const { startServer } = await import(serverEntry);
229
- console.log(chalk6.cyan("Starting production server..."));
230
- return startServer({ port, distDir });
231
- }
232
- var init_prod = () => {};
233
-
234
151
  // src/cli/index.ts
235
152
  import { Command as Command6 } from "commander";
236
153
 
237
- // src/cli/commands/init.ts
154
+ // src/cli/commands/build.ts
155
+ import chalk2 from "chalk";
238
156
  import { Command } from "commander";
239
- import { execSync } from "child_process";
240
- import fs2 from "fs";
241
- import path3 from "path";
242
- import chalk from "chalk";
243
- import { stringify } from "yaml";
244
157
 
245
- // src/cli/utils/scaffold.ts
246
- import fs from "fs";
247
- import path2 from "path";
158
+ // src/cli/utils/config.ts
159
+ import path from "node:path";
160
+ import chalk from "chalk";
161
+ import { parse } from "yaml";
162
+ function resolveContentDir(contentFlag) {
163
+ if (contentFlag)
164
+ return path.resolve(contentFlag);
165
+ return path.resolve("content");
166
+ }
248
167
 
249
168
  // src/cli/utils/resolve.ts
250
- import path from "path";
169
+ import path2 from "path";
251
170
  import { fileURLToPath } from "url";
252
- var PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
171
+ var PACKAGE_ROOT = path2.resolve(path2.dirname(fileURLToPath(import.meta.url)), "..", "..");
253
172
 
254
173
  // src/cli/utils/scaffold.ts
255
- function detectPackageManager() {
256
- if (process.env.npm_config_user_agent) {
257
- return process.env.npm_config_user_agent.split("/")[0];
258
- }
259
- const cwd = process.cwd();
260
- if (fs.existsSync(path2.join(cwd, "bun.lock")) || fs.existsSync(path2.join(cwd, "bun.lockb")))
261
- return "bun";
262
- if (fs.existsSync(path2.join(cwd, "pnpm-lock.yaml")))
263
- return "pnpm";
264
- if (fs.existsSync(path2.join(cwd, "yarn.lock")))
265
- return "yarn";
266
- return "npm";
267
- }
268
- function getChronicleVersion() {
269
- const pkgPath = path2.join(PACKAGE_ROOT, "package.json");
270
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
271
- return pkg.version;
174
+ import fs from "node:fs/promises";
175
+ import path3 from "node:path";
176
+ async function linkContent(contentDir) {
177
+ const linkPath = path3.join(PACKAGE_ROOT, ".content");
178
+ const target = path3.resolve(contentDir);
179
+ try {
180
+ const existing = await fs.readlink(linkPath);
181
+ if (existing === target)
182
+ return;
183
+ await fs.unlink(linkPath);
184
+ } catch {}
185
+ await fs.symlink(target, linkPath);
272
186
  }
273
187
 
188
+ // src/cli/commands/build.ts
189
+ var buildCommand = new Command("build").description("Build for production").option("-c, --content <path>", "Content directory").option("--preset <preset>", "Deploy preset (vercel, cloudflare, node-server)").action(async (options) => {
190
+ const contentDir = resolveContentDir(options.content);
191
+ await linkContent(contentDir);
192
+ console.log(chalk2.cyan("Building for production..."));
193
+ const { createBuilder } = await import("vite");
194
+ const { createViteConfig: createViteConfig2 } = await Promise.resolve().then(() => (init_vite_config(), exports_vite_config));
195
+ const config = await createViteConfig2({
196
+ packageRoot: PACKAGE_ROOT,
197
+ projectRoot: process.cwd(),
198
+ contentDir,
199
+ preset: options.preset
200
+ });
201
+ const builder = await createBuilder({ ...config, builder: {} });
202
+ await builder.buildApp();
203
+ console.log(chalk2.green("Build complete"));
204
+ });
205
+
206
+ // src/cli/commands/dev.ts
207
+ import chalk3 from "chalk";
208
+ import { Command as Command2 } from "commander";
209
+ 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) => {
210
+ const contentDir = resolveContentDir(options.content);
211
+ const port = parseInt(options.port, 10);
212
+ await linkContent(contentDir);
213
+ console.log(chalk3.cyan("Starting dev server..."));
214
+ const { createServer } = await import("vite");
215
+ const { createViteConfig: createViteConfig2 } = await Promise.resolve().then(() => (init_vite_config(), exports_vite_config));
216
+ const config = await createViteConfig2({ packageRoot: PACKAGE_ROOT, projectRoot: process.cwd(), contentDir });
217
+ const server = await createServer({
218
+ ...config,
219
+ server: { ...config.server, port }
220
+ });
221
+ await server.listen();
222
+ server.printUrls();
223
+ });
224
+
274
225
  // src/cli/commands/init.ts
275
- function createConfig() {
276
- return {
277
- title: "My Documentation",
278
- description: "Documentation powered by Chronicle",
279
- theme: { name: "default" },
280
- search: { enabled: true, placeholder: "Search documentation..." }
281
- };
282
- }
283
- function createPackageJson(name) {
284
- return {
285
- name,
286
- private: true,
287
- type: "module",
288
- scripts: {
289
- dev: "chronicle dev",
290
- build: "chronicle build",
291
- start: "chronicle start"
292
- },
293
- dependencies: {
294
- "@raystack/chronicle": `^${getChronicleVersion()}`
295
- },
296
- devDependencies: {
297
- "@raystack/tools-config": "0.56.0",
298
- "openapi-types": "^12.1.3",
299
- typescript: "5.9.3",
300
- "@types/react": "^19.2.10",
301
- "@types/node": "^25.1.0"
302
- }
303
- };
304
- }
226
+ import fs2 from "node:fs";
227
+ import path5 from "node:path";
228
+ import chalk4 from "chalk";
229
+ import { Command as Command3 } from "commander";
230
+ import { stringify } from "yaml";
231
+ var defaultConfig = {
232
+ title: "My Documentation",
233
+ description: "Documentation powered by Chronicle",
234
+ theme: { name: "default" },
235
+ search: { enabled: true, placeholder: "Search documentation..." }
236
+ };
305
237
  var sampleMdx = `---
306
238
  title: Welcome
307
239
  description: Getting started with your documentation
@@ -312,74 +244,28 @@ order: 1
312
244
 
313
245
  This is your documentation home page.
314
246
  `;
315
- var initCommand = new Command("init").description("Initialize a new Chronicle project").option("-c, --content <path>", "Content directory name", "content").action((options) => {
247
+ var initCommand = new Command3("init").description("Initialize a new Chronicle project").option("-c, --content <path>", "Content directory name", "content").action((options) => {
316
248
  const projectDir = process.cwd();
317
- const dirName = path3.basename(projectDir) || "docs";
318
- const contentDir = path3.join(projectDir, options.content);
249
+ const contentDir = path5.join(projectDir, options.content);
319
250
  if (!fs2.existsSync(contentDir)) {
320
251
  fs2.mkdirSync(contentDir, { recursive: true });
321
- console.log(chalk.green("✓"), "Created", contentDir);
322
- }
323
- const packageJsonPath = path3.join(projectDir, "package.json");
324
- if (!fs2.existsSync(packageJsonPath)) {
325
- fs2.writeFileSync(packageJsonPath, JSON.stringify(createPackageJson(dirName), null, 2) + `
326
- `);
327
- console.log(chalk.green("✓"), "Created", packageJsonPath);
328
- } else {
329
- const existing = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
330
- const template = createPackageJson(dirName);
331
- let updated = false;
332
- if (existing.type !== "module") {
333
- existing.type = "module";
334
- updated = true;
335
- }
336
- if (!existing.scripts)
337
- existing.scripts = {};
338
- for (const [key, value] of Object.entries(template.scripts)) {
339
- if (!existing.scripts[key]) {
340
- existing.scripts[key] = value;
341
- updated = true;
342
- }
343
- }
344
- if (!existing.dependencies)
345
- existing.dependencies = {};
346
- for (const [key, value] of Object.entries(template.dependencies)) {
347
- if (!existing.dependencies[key]) {
348
- existing.dependencies[key] = value;
349
- updated = true;
350
- }
351
- }
352
- if (!existing.devDependencies)
353
- existing.devDependencies = {};
354
- for (const [key, value] of Object.entries(template.devDependencies)) {
355
- if (!existing.devDependencies[key]) {
356
- existing.devDependencies[key] = value;
357
- updated = true;
358
- }
359
- }
360
- if (updated) {
361
- fs2.writeFileSync(packageJsonPath, JSON.stringify(existing, null, 2) + `
362
- `);
363
- console.log(chalk.green("✓"), "Updated", packageJsonPath);
364
- } else {
365
- console.log(chalk.yellow("⚠"), packageJsonPath, "already has all required entries");
366
- }
252
+ console.log(chalk4.green("✓"), "Created", contentDir);
367
253
  }
368
- const configPath = path3.join(projectDir, "chronicle.yaml");
254
+ const configPath = path5.join(projectDir, "chronicle.yaml");
369
255
  if (!fs2.existsSync(configPath)) {
370
- fs2.writeFileSync(configPath, stringify(createConfig()));
371
- console.log(chalk.green("✓"), "Created", configPath);
256
+ fs2.writeFileSync(configPath, stringify(defaultConfig));
257
+ console.log(chalk4.green("✓"), "Created", configPath);
372
258
  } else {
373
- console.log(chalk.yellow("⚠"), configPath, "already exists");
259
+ console.log(chalk4.yellow("⚠"), configPath, "already exists");
374
260
  }
375
261
  const contentFiles = fs2.readdirSync(contentDir);
376
262
  if (contentFiles.length === 0) {
377
- const indexPath = path3.join(contentDir, "index.mdx");
263
+ const indexPath = path5.join(contentDir, "index.mdx");
378
264
  fs2.writeFileSync(indexPath, sampleMdx);
379
- console.log(chalk.green("✓"), "Created", indexPath);
265
+ console.log(chalk4.green("✓"), "Created", indexPath);
380
266
  }
381
- const gitignorePath = path3.join(projectDir, ".gitignore");
382
- const gitignoreEntries = ["node_modules", "dist"];
267
+ const gitignorePath = path5.join(projectDir, ".gitignore");
268
+ const gitignoreEntries = ["node_modules", "dist", ".output"];
383
269
  if (fs2.existsSync(gitignorePath)) {
384
270
  const existing = fs2.readFileSync(gitignorePath, "utf-8");
385
271
  const missing = gitignoreEntries.filter((e) => !existing.includes(e));
@@ -388,142 +274,61 @@ var initCommand = new Command("init").description("Initialize a new Chronicle pr
388
274
  ${missing.join(`
389
275
  `)}
390
276
  `);
391
- console.log(chalk.green("✓"), "Added", missing.join(", "), "to .gitignore");
277
+ console.log(chalk4.green("✓"), "Added", missing.join(", "), "to .gitignore");
392
278
  }
393
279
  } else {
394
280
  fs2.writeFileSync(gitignorePath, `${gitignoreEntries.join(`
395
281
  `)}
396
282
  `);
397
- console.log(chalk.green("✓"), "Created .gitignore");
283
+ console.log(chalk4.green("✓"), "Created .gitignore");
398
284
  }
399
- const pm = detectPackageManager();
400
- console.log(chalk.cyan(`
401
- Installing dependencies with ${pm}...`));
402
- execSync(`${pm} install`, { cwd: projectDir, stdio: "inherit" });
403
- const runCmd = pm === "npm" ? "npx" : pm === "bun" ? "bunx" : `${pm} dlx`;
404
- console.log(chalk.green(`
285
+ console.log(chalk4.green(`
405
286
  ✓ Chronicle initialized!`));
406
287
  console.log(`
407
- Run`, chalk.cyan(`${runCmd} chronicle dev`), "to start development server");
288
+ Run`, chalk4.cyan("chronicle dev"), "to start development server");
408
289
  });
409
290
 
410
- // src/cli/commands/dev.ts
411
- import { Command as Command2 } from "commander";
412
- import chalk4 from "chalk";
413
-
414
- // src/cli/utils/config.ts
415
- import path4 from "path";
416
- import { parse } from "yaml";
417
- import chalk2 from "chalk";
418
- function resolveContentDir(contentFlag) {
419
- if (contentFlag)
420
- return path4.resolve(contentFlag);
421
- if (process.env.CHRONICLE_CONTENT_DIR)
422
- return path4.resolve(process.env.CHRONICLE_CONTENT_DIR);
423
- return path4.resolve("content");
424
- }
425
-
426
- // src/cli/commands/dev.ts
427
- 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) => {
428
- const contentDir = resolveContentDir(options.content);
429
- const port = parseInt(options.port, 10);
430
- process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
431
- process.env.CHRONICLE_CONTENT_DIR = contentDir;
432
- console.log(chalk4.cyan("Starting dev server..."));
433
- const { startDevServer: startDevServer2 } = await Promise.resolve().then(() => (init_dev(), exports_dev));
434
- await startDevServer2({ port, root: PACKAGE_ROOT, contentDir });
435
- });
436
-
437
- // src/cli/commands/build.ts
438
- import { Command as Command3 } from "commander";
439
- import path7 from "path";
291
+ // src/cli/commands/serve.ts
440
292
  import chalk5 from "chalk";
441
- var buildCommand = new Command3("build").description("Build for production").option("-c, --content <path>", "Content directory").option("-o, --outDir <path>", "Output directory", "dist").action(async (options) => {
293
+ import { Command as Command4 } from "commander";
294
+ var serveCommand = new Command4("serve").description("Build and start production server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").option("--preset <preset>", "Deploy preset (vercel, cloudflare, node-server)").action(async (options) => {
442
295
  const contentDir = resolveContentDir(options.content);
443
- const outDir = path7.resolve(options.outDir);
444
- process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
445
- process.env.CHRONICLE_CONTENT_DIR = contentDir;
446
- console.log(chalk5.cyan("Building for production..."));
447
- const { build } = await import("vite");
296
+ const port = parseInt(options.port, 10);
297
+ await linkContent(contentDir);
298
+ const { build, preview } = await import("vite");
448
299
  const { createViteConfig: createViteConfig2 } = await Promise.resolve().then(() => (init_vite_config(), exports_vite_config));
449
- const baseConfig = await createViteConfig2({ root: PACKAGE_ROOT, contentDir });
450
- console.log(chalk5.gray("Building client..."));
451
- await build({
452
- ...baseConfig,
453
- build: {
454
- outDir: path7.join(outDir, "client"),
455
- ssrManifest: true,
456
- rolldownOptions: {
457
- input: path7.resolve(PACKAGE_ROOT, "src/server/index.html")
458
- }
459
- }
300
+ const config = await createViteConfig2({
301
+ packageRoot: PACKAGE_ROOT,
302
+ projectRoot: process.cwd(),
303
+ contentDir,
304
+ preset: options.preset
460
305
  });
461
- console.log(chalk5.gray("Building server..."));
462
- await build({
463
- ...baseConfig,
464
- ssr: {
465
- noExternal: true
466
- },
467
- build: {
468
- outDir: path7.join(outDir, "server"),
469
- ssr: path7.resolve(PACKAGE_ROOT, "src/server/entry-prod.ts")
470
- }
306
+ console.log(chalk5.cyan("Building for production..."));
307
+ await build(config);
308
+ console.log(chalk5.cyan("Starting production server..."));
309
+ const server = await preview({
310
+ ...config,
311
+ preview: { port }
471
312
  });
472
- console.log(chalk5.green("Build complete →"), outDir);
313
+ server.printUrls();
473
314
  });
474
315
 
475
316
  // src/cli/commands/start.ts
476
- import { Command as Command4 } from "commander";
477
- import path9 from "path";
478
- import chalk7 from "chalk";
479
- 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) => {
480
- const contentDir = resolveContentDir(options.content);
481
- const port = parseInt(options.port, 10);
482
- const distDir = path9.resolve(options.dist);
483
- process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
484
- process.env.CHRONICLE_CONTENT_DIR = contentDir;
485
- console.log(chalk7.cyan("Starting production server..."));
486
- const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prod(), exports_prod));
487
- await startProdServer2({ port, root: PACKAGE_ROOT, distDir });
488
- });
489
-
490
- // src/cli/commands/serve.ts
317
+ import chalk6 from "chalk";
491
318
  import { Command as Command5 } from "commander";
492
- import path10 from "path";
493
- import chalk8 from "chalk";
494
- 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) => {
319
+ var startCommand = new Command5("start").description("Start production server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").action(async (options) => {
495
320
  const contentDir = resolveContentDir(options.content);
496
321
  const port = parseInt(options.port, 10);
497
- const outDir = path10.resolve(options.outDir);
498
- process.env.CHRONICLE_PROJECT_ROOT = process.cwd();
499
- process.env.CHRONICLE_CONTENT_DIR = contentDir;
500
- console.log(chalk8.cyan("Building for production..."));
501
- const { build } = await import("vite");
322
+ await linkContent(contentDir);
323
+ console.log(chalk6.cyan("Starting production server..."));
324
+ const { preview } = await import("vite");
502
325
  const { createViteConfig: createViteConfig2 } = await Promise.resolve().then(() => (init_vite_config(), exports_vite_config));
503
- const baseConfig = await createViteConfig2({ root: PACKAGE_ROOT, contentDir });
504
- await build({
505
- ...baseConfig,
506
- build: {
507
- outDir: path10.join(outDir, "client"),
508
- ssrManifest: true,
509
- rolldownOptions: {
510
- input: path10.resolve(PACKAGE_ROOT, "src/server/index.html")
511
- }
512
- }
513
- });
514
- await build({
515
- ...baseConfig,
516
- ssr: {
517
- noExternal: true
518
- },
519
- build: {
520
- outDir: path10.join(outDir, "server"),
521
- ssr: path10.resolve(PACKAGE_ROOT, "src/server/entry-prod.ts")
522
- }
326
+ const config = await createViteConfig2({ packageRoot: PACKAGE_ROOT, projectRoot: process.cwd(), contentDir });
327
+ const server = await preview({
328
+ ...config,
329
+ preview: { port }
523
330
  });
524
- console.log(chalk8.cyan("Starting production server..."));
525
- const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prod(), exports_prod));
526
- await startProdServer2({ port, root: PACKAGE_ROOT, distDir: outDir });
331
+ server.printUrls();
527
332
  });
528
333
 
529
334
  // src/cli/index.ts