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