okno 1.0.0-beta.47 → 1.0.0-beta.48

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.
@@ -1,4 +1,4 @@
1
- import { o as e } from "../plugin-DNXklUmq.js";
1
+ import { o as e } from "../plugin-BAurTuo8.js";
2
2
  function r(o = {}) {
3
3
  return {
4
4
  name: "okno",
@@ -0,0 +1,96 @@
1
+ import { readFileSync as y, statSync as d, readdirSync as b } from "node:fs";
2
+ import { join as h, relative as A } from "node:path";
3
+ const w = /* @__PURE__ */ new Set(["exists", "value", "name", "length", "src", "alt", "width", "height", "href", "slug", "draft"]), S = /\.(astro|svelte|vue|jsx|tsx)$/, R = /\.(astro|svelte|vue|jsx|tsx|ts|js|mjs)$/, v = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".astro", ".svelte-kit", ".nuxt", ".output", ".next", ".git", "public", "static", "okno"]);
4
+ function E(t) {
5
+ return t.replace(/\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->|(^|[^:"'`\\])\/\/[^\n]*/gm, (s, e = "") => e + s.slice(e.length).replace(/[^\n]/g, " "));
6
+ }
7
+ const $ = (t) => t.replace(/[$]/g, "\\$"), k = (t) => `(?<![\\w$.])${$(t)}(?:\\??\\.[A-Za-z_$][\\w$]*|\\[[^\\]\\n]*\\])+`;
8
+ function z(t) {
9
+ const s = /* @__PURE__ */ new Set(), e = /* @__PURE__ */ new Set();
10
+ for (const n of t.matchAll(/import\s+(type\s+)?\{([^}]*)\}\s*from\s*["']okno\/(pages|collections|globals|content|strings|blocks)["']/g))
11
+ for (const c of n[2].split(",")) {
12
+ const f = c.trim();
13
+ if (!f) continue;
14
+ const p = !!n[1] || f.startsWith("type ") || n[3] === "blocks", o = f.replace(/^type\s+/, "").split(/\s+as\s+/).pop().trim();
15
+ (p ? e : s).add(o);
16
+ }
17
+ for (const n of t.matchAll(/import\s+\*\s+as\s+([\w$]+)\s+from\s*["']okno\/(pages|collections|globals|content|strings)["']/g)) s.add(n[1]);
18
+ const l = (n) => /import\(["']okno\//.test(n) || [...e].some((c) => new RegExp(`(?<![\\w$])${$(c)}(?![\\w$])`).test(n)) || [...s].some((c) => new RegExp(`typeof\\s+${$(c)}(?![\\w$])`).test(n));
19
+ for (const n of t.matchAll(/([A-Za-z_$][\w$]*)\??\s*:\s*([^;,\n}]+)/g)) l(n[2]) && s.add(n[1]);
20
+ for (let n = -1; n !== s.size; ) {
21
+ n = s.size;
22
+ for (const c of [...s]) {
23
+ const f = k(c), p = `(?:${f}|(?<![\\w$.])${$(c)})`, o = "\\.(map|filter|find|findLast|forEach|some|every|flatMap|sort|toSorted)\\(\\s*\\(?\\s*([A-Za-z_$][\\w$]*)(?:\\s*,\\s*([A-Za-z_$][\\w$]*))?";
24
+ for (const r of [p, `\\[\\s*\\.\\.\\.${$(c)}[^\\]]*\\]`])
25
+ for (const i of t.matchAll(new RegExp(r + o, "g")))
26
+ s.add(i[2]), i[3] && /sort/i.test(i[1]) && s.add(i[3]);
27
+ for (const r of t.matchAll(new RegExp(`(?:const|let|var)\\s+([A-Za-z_$][\\w$]*)\\s*=\\s*(${f})\\s*[;\\n]`, "g")))
28
+ w.has(r[2].split(/\??\./).pop()) || s.add(r[1]);
29
+ for (const r of t.matchAll(new RegExp(`(?:const|let|var)\\s*\\{([^}]*)\\}\\s*=\\s*${$(c)}(?:\\.locale\\([^)]*\\))?\\s*[;\\n]`, "g")))
30
+ for (const i of r[1].split(",")) {
31
+ const g = i.split(":").pop().split("=")[0].trim();
32
+ /^[A-Za-z_$][\w$]*$/.test(g) && s.add(g);
33
+ }
34
+ }
35
+ }
36
+ return s;
37
+ }
38
+ function _(t, s) {
39
+ const e = E(s), l = [], n = (o) => {
40
+ const r = e.slice(0, o);
41
+ return { line: r.split(`
42
+ `).length, column: o - r.lastIndexOf(`
43
+ `) };
44
+ }, c = (o, r, i) => l.push({ ...n(o), rule: r, message: i });
45
+ for (const o of e.matchAll(/import\s+(?!type\b)\{([^}]*)\}\s*from\s*["']okno\/blocks["']/g))
46
+ o[1].split(",").some((r) => r.trim() && !r.trim().startsWith("type ")) && c(o.index, "blocks-import", "okno/blocks has no runtime module; use `import type`.");
47
+ for (const o of e.matchAll(/from\s*["']okno:(pages|collections|globals|blocks|strings|locales|content)["']/g))
48
+ c(o.index, "legacy-import", `Use the current "okno/${o[1]}" import instead of "okno:${o[1]}".`);
49
+ if (S.test(t))
50
+ for (const o of e.matchAll(/\sdata-okno(-item|-locale)?\s*=(?!\s*\{[^}]*\[\s*["']data-okno)/g))
51
+ c(o.index + 1, "hook", `Remove the manual data-okno${o[1] ?? ""} attribute; spread the field or block onto the element instead.`);
52
+ const f = z(e), p = /* @__PURE__ */ new Set();
53
+ for (const o of f) {
54
+ const r = k(o), i = (a) => w.has(a.split(/\??\.|\[/).pop().replace(/\]$/, "")), g = [
55
+ new RegExp(`(${r})(?!\\s*\\()(?=\\s*(?:&&|\\|\\||\\?(?![.?])))`, "g"),
56
+ new RegExp(`(?<![!=])!\\s*(${r})(?![\\w$.\\[(])`, "g"),
57
+ new RegExp(`\\bif\\s*\\(\\s*(${r})\\s*\\)`, "g")
58
+ ];
59
+ for (const a of g)
60
+ for (const m of e.matchAll(a)) {
61
+ const u = m.index + m[0].indexOf(m[1]);
62
+ i(m[1]) || p.has(u) || (p.add(u), c(u, "truthy", `\`${m[1]}\` is a wrapper and always truthy; test \`${m[1]}.exists\` (or \`.length\` for a list).`));
63
+ }
64
+ for (const a of e.matchAll(new RegExp(`\\{\\s*String\\(\\s*(${r})\\s*\\)\\s*\\}`, "g")))
65
+ i(a[1]) || c(a.index + a[0].indexOf("String"), "string", `Drop String(): \`${a[1]}\` already renders its stored value; use \`${a[1]}.value\` for a raw string.`);
66
+ }
67
+ return l.sort((o, r) => o.line - r.line || o.column - r.column);
68
+ }
69
+ function x(t, s = []) {
70
+ for (const e of b(t)) {
71
+ if (v.has(e)) continue;
72
+ const l = h(t, e);
73
+ d(l).isDirectory() ? x(l, s) : R.test(e) && !e.endsWith(".d.ts") && s.push(l);
74
+ }
75
+ return s;
76
+ }
77
+ function C(t = process.cwd()) {
78
+ const s = O(h(t, "src")) ? h(t, "src") : t, e = x(s);
79
+ let l = 0;
80
+ for (const n of e)
81
+ for (const c of _(n, y(n, "utf8")))
82
+ l++, console.log(`${A(t, n)}:${c.line}:${c.column} ${c.rule} ${c.message}`);
83
+ console.log(l ? `
84
+ ✗ ${l} Okno contract ${l === 1 ? "problem" : "problems"} in ${e.length} files` : `✓ Okno content contract: ${e.length} files checked`), l && (process.exitCode = 1);
85
+ }
86
+ function O(t) {
87
+ try {
88
+ return d(t).isDirectory();
89
+ } catch {
90
+ return !1;
91
+ }
92
+ }
93
+ export {
94
+ _ as checkSource,
95
+ C as runCheck
96
+ };
@@ -0,0 +1,11 @@
1
+ export interface Problem {
2
+ line: number;
3
+ column: number;
4
+ rule: "hook" | "blocks-import" | "legacy-import" | "truthy" | "string";
5
+ message: string;
6
+ }
7
+ /** Problems in one source file. `file` selects markup-only rules by extension. */
8
+ export declare function checkSource(file: string, text: string): Problem[];
9
+ /** Check the project's source (`src/` when present). Exits 1 when anything is reported. */
10
+ export declare function runCheck(cwd?: string): void;
11
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/cli/check.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,eAAe,GAAG,QAAQ,GAAG,QAAQ,CAAA;IACtE,OAAO,EAAE,MAAM,CAAA;CACf;AAgED,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,CAkDjE;AAaD,2FAA2F;AAC3F,wBAAgB,QAAQ,CAAC,GAAG,SAAgB,GAAG,IAAI,CAYlD"}
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * `okno` CLI. The canonical command is BARE `npx okno` — the context-aware
4
4
  * installer (adds the plugin, scaffolds, offers MCP). `okno mcp` runs the MCP
5
- * server. Each path lazy-imports its deps so neither pays for the other's.
5
+ * server, `okno check` lints templates against the content contract. Each path lazy-imports its deps so neither pays for the other's.
6
6
  */
7
7
  declare function main(): Promise<void>;
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAIH,iBAAe,IAAI,kBAuBlB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAIH,iBAAe,IAAI,kBA4BlB"}
package/dist/cli.js CHANGED
@@ -1,24 +1,29 @@
1
1
  #!/usr/bin/env node
2
2
  async function c() {
3
- const [n] = process.argv.slice(2);
4
- switch (n) {
3
+ const [o] = process.argv.slice(2);
4
+ switch (o) {
5
5
  case "mcp": {
6
- const { runMcp: o } = await import("./mcp.js");
7
- await o();
6
+ const { runMcp: n } = await import("./mcp.js");
7
+ await n();
8
+ break;
9
+ }
10
+ case "check": {
11
+ const { runCheck: n } = await import("./check-Dv8k-HKR.js");
12
+ n();
8
13
  break;
9
14
  }
10
15
  case "help":
11
16
  case "--help":
12
17
  case "-h": {
13
18
  console.log(
14
- ["", " npx okno Add okno to this project", " npx okno mcp Run the okno MCP server (for your AI client)", ""].join(`
19
+ ["", " npx okno Add okno to this project", " npx okno mcp Run the okno MCP server (for your AI client)", " npx okno check Check templates against the Okno content contract", ""].join(`
15
20
  `)
16
21
  );
17
22
  break;
18
23
  }
19
24
  default: {
20
- const { runInit: o } = await import("./init.js");
21
- await o();
25
+ const { runInit: n } = await import("./init.js");
26
+ await n();
22
27
  }
23
28
  }
24
29
  }