@kurajs/cli 0.0.2 → 0.0.3

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 (2) hide show
  1. package/dist/cli.js +36 -22
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -53,28 +53,39 @@ async function cmdIndex() {
53
53
  if (e.locale === locale)
54
54
  variants.push(e);
55
55
  const allEntries = [...DOCS, ...variants];
56
- // Content hash — skip the (slow) embed when nothing changed, so `kura index` is cheap to run
57
- // before every dev/build. Covers locale + slug + body of every entry, plus the model id.
58
- const hashInput = JSON.stringify([model, allEntries.map((e) => [e.locale ?? "", e.slug, e.body])]);
56
+ // --no-embed: skip the search index entirely (build MDX only). Use it when the site runs
57
+ // WITHOUT a runtime embedder search degrades to a lexical scan, so no model/index is needed
58
+ // (e.g. a Cloudflare Workers deploy without Workers AI).
59
+ const noEmbed = process.argv.includes("--no-embed");
60
+ // Content hash — skip rebuilds when nothing changed, so `kura index` is cheap to run before
61
+ // every dev/build. Covers the mode + model + locale/slug/body of every entry.
62
+ const hashInput = JSON.stringify([model, noEmbed, allEntries.map((e) => [e.locale ?? "", e.slug, e.body])]);
59
63
  const contentHash = crypto.createHash("sha256").update(hashInput).digest("hex").slice(0, 16);
60
- if (fs.existsSync(mdxTs) && fs.existsSync(indexTs)) {
61
- const prev = fs.readFileSync(indexTs, "utf8").match(/CONTENT_HASH = "([^"]+)"/)?.[1];
62
- if (prev === contentHash) {
63
- console.log(`kura index: up to date (${allEntries.length} docs, hash ${contentHash}) — skipped`);
64
- return;
65
- }
64
+ const stamp = `// content-hash: ${contentHash}\n`;
65
+ const hashOf = (f) => (fs.existsSync(f) ? fs.readFileSync(f, "utf8").match(/content-hash: (\S+)/)?.[1] : undefined);
66
+ const upToDate = noEmbed ? hashOf(mdxTs) === contentHash : hashOf(indexTs) === contentHash && fs.existsSync(mdxTs);
67
+ if (upToDate) {
68
+ console.log(`kura index: up to date (${allEntries.length} docs, hash ${contentHash}) — skipped`);
69
+ return;
70
+ }
71
+ fs.mkdirSync(path.dirname(mdxTs), { recursive: true });
72
+ if (!noEmbed) {
73
+ const localeTag = locales.size ? ` (+${variants.length} variants across ${locales.size} locales)` : "";
74
+ console.log(`kura index: embedding ${DOCS.length} docs${localeTag} (model ${model})…`);
75
+ const t0 = Date.now();
76
+ const bytes = await buildIndex({ entries: allEntries, embedder: transformers({ model }) });
77
+ const b64 = Buffer.from(bytes).toString("base64");
78
+ fs.writeFileSync(indexTs, stamp +
79
+ "// AUTO-GENERATED by `kura index` — do not edit. Frozen search index (base64) so the worker\n" +
80
+ "// bundle imports it instead of reading the filesystem (Workers-safe).\n" +
81
+ `export const INDEX_B64 = ${JSON.stringify(b64)};\n`);
82
+ console.log(`kura index: wrote app/_index.ts (${(bytes.length / 1024).toFixed(0)}KB index) in ${((Date.now() - t0) / 1000).toFixed(1)}s`);
83
+ }
84
+ else {
85
+ if (fs.existsSync(indexTs))
86
+ fs.rmSync(indexTs);
87
+ console.log("kura index: --no-embed — MDX only, no search index (runtime search is lexical)");
66
88
  }
67
- const localeTag = locales.size ? ` (+${variants.length} variants across ${locales.size} locales)` : "";
68
- console.log(`kura index: embedding ${DOCS.length} docs${localeTag} (model ${model})…`);
69
- const t0 = Date.now();
70
- const bytes = await buildIndex({ entries: allEntries, embedder: transformers({ model }) });
71
- const b64 = Buffer.from(bytes).toString("base64");
72
- fs.mkdirSync(path.dirname(indexTs), { recursive: true });
73
- fs.writeFileSync(indexTs, "// AUTO-GENERATED by `kura index` — do not edit. Frozen search index (base64) so the worker\n" +
74
- "// bundle imports it instead of reading the filesystem (Workers-safe).\n" +
75
- `export const CONTENT_HASH = ${JSON.stringify(contentHash)};\n` +
76
- `export const INDEX_B64 = ${JSON.stringify(b64)};\n`);
77
- console.log(`kura index: wrote app/_index.ts (${(bytes.length / 1024).toFixed(0)}KB index) in ${((Date.now() - t0) / 1000).toFixed(1)}s`);
78
89
  // Precompile MDX -> static HTML with curated components (build-time; Workers-safe at runtime).
79
90
  // Bucketed by locale: "default" for the flat (default-locale) files, plus one per variant locale.
80
91
  const { mdxToHtml } = await import("@kurajs/docs/mdx");
@@ -93,7 +104,8 @@ async function cmdIndex() {
93
104
  await render("default", d);
94
105
  for (const e of variants)
95
106
  await render(e.locale, e);
96
- fs.writeFileSync(mdxTs, "// AUTO-GENERATED by `kura index` — do not edit. Frozen precompiled MDX (locale → slug → html).\n" +
107
+ fs.writeFileSync(mdxTs, stamp +
108
+ "// AUTO-GENERATED by `kura index` — do not edit. Frozen precompiled MDX (locale → slug → html).\n" +
97
109
  `export const MDX: Record<string, Record<string, string>> = ${JSON.stringify(map)};\n`);
98
110
  const total = Object.values(map).reduce((n, b) => n + Object.keys(b).length, 0);
99
111
  const tag = locales.size ? ` across ${locales.size + 1} locales` : "";
@@ -104,6 +116,8 @@ if (cmd === "index") {
104
116
  await cmdIndex();
105
117
  }
106
118
  else {
107
- console.log("Kura CLI\n kura index [--model <hf-model>] build & freeze the docs search index + MDX");
119
+ console.log("Kura CLI\n" +
120
+ " kura index [--model <hf-model>] build & freeze the docs search index + MDX\n" +
121
+ " kura index --no-embed MDX only, no search index (runtime search is lexical)");
108
122
  process.exit(cmd ? 1 : 0);
109
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurajs/cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "Kura CLI — build the docs search index (kura index).",
6
6
  "bin": {
@@ -15,7 +15,7 @@
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
17
  "@kurajs/core": "^0.0.1",
18
- "@kurajs/docs": "^0.0.2",
18
+ "@kurajs/docs": "^0.0.3",
19
19
  "@kurajs/transformers": "^0.0.1"
20
20
  },
21
21
  "peerDependencies": {