@panomc/theme-core 1.0.0-dev.44 → 1.0.0-dev.46
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/check.js +13 -3
- package/bin/new.js +168 -38
- package/bin/package-zip.js +5 -2
- package/bin/sync.js +2 -1
- package/bin/theme-core.js +155 -24
- package/bin/ui.js +66 -0
- package/package.json +3 -1
- package/src/kit/vite-config.js +13 -1
package/bin/check.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
20
20
|
import { join, dirname } from "node:path";
|
|
21
21
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
22
|
+
import { pc } from "./ui.js";
|
|
22
23
|
|
|
23
24
|
const pkgDir = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
24
25
|
const themeDir = process.cwd();
|
|
@@ -245,9 +246,18 @@ if (existsSync(viewsDir) && existsSync(mergedLangPath)) {
|
|
|
245
246
|
scan(viewsDir);
|
|
246
247
|
}
|
|
247
248
|
|
|
248
|
-
|
|
249
|
+
console.log(pc.dim(`theme-core check — validating against core ${corePkg.version}`));
|
|
250
|
+
|
|
251
|
+
for (const w of warnings) console.log(` ${pc.yellow("▲")} ${w}`);
|
|
249
252
|
if (problems.length) {
|
|
250
|
-
for (const p of problems) console.error(`
|
|
253
|
+
for (const p of problems) console.error(` ${pc.red("✗")} ${p}`);
|
|
254
|
+
console.error(
|
|
255
|
+
pc.red(
|
|
256
|
+
`\n${problems.length} problem${problems.length === 1 ? "" : "s"} must be fixed before this theme ships.`,
|
|
257
|
+
),
|
|
258
|
+
);
|
|
251
259
|
process.exit(1);
|
|
252
260
|
}
|
|
253
|
-
console.log(
|
|
261
|
+
console.log(
|
|
262
|
+
` ${pc.green("✓")} ${pc.bold("OK")} — ${registered.length} view override${registered.length === 1 ? "" : "s"} validated against core ${corePkg.version}`,
|
|
263
|
+
);
|
package/bin/new.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* theme-core new — scaffold a working Pano theme.
|
|
4
4
|
*
|
|
5
|
+
* bunx @panomc/theme-core new interactive wizard (TTY only)
|
|
5
6
|
* bunx @panomc/theme-core new my-theme npm-published core (default)
|
|
6
7
|
* bunx @panomc/theme-core new my-theme --local file: links into a local theme-core
|
|
7
8
|
* checkout (this workspace)
|
|
@@ -12,9 +13,22 @@
|
|
|
12
13
|
* theme and it carries repo-specific baggage — this scaffolder is the entry.
|
|
13
14
|
*/
|
|
14
15
|
import { existsSync, mkdirSync, writeFileSync, readFileSync, copyFileSync } from "node:fs";
|
|
15
|
-
import {
|
|
16
|
+
import { spawnSync } from "node:child_process";
|
|
17
|
+
import { join, dirname, resolve, basename } from "node:path";
|
|
16
18
|
import { fileURLToPath } from "node:url";
|
|
17
19
|
import { createRequire } from "node:module";
|
|
20
|
+
import {
|
|
21
|
+
pc,
|
|
22
|
+
isInteractive,
|
|
23
|
+
cancelGuard,
|
|
24
|
+
brandIntro,
|
|
25
|
+
text,
|
|
26
|
+
confirm,
|
|
27
|
+
spinner,
|
|
28
|
+
outro,
|
|
29
|
+
note,
|
|
30
|
+
DOCS_URL,
|
|
31
|
+
} from "./ui.js";
|
|
18
32
|
|
|
19
33
|
const binDir = dirname(fileURLToPath(import.meta.url));
|
|
20
34
|
const corePkgDir = join(binDir, "..");
|
|
@@ -22,26 +36,93 @@ const corePkg = JSON.parse(readFileSync(join(corePkgDir, "package.json"), "utf-8
|
|
|
22
36
|
const require = createRequire(import.meta.url);
|
|
23
37
|
|
|
24
38
|
const args = process.argv.slice(2);
|
|
25
|
-
const
|
|
39
|
+
const nameArg = args.find((a) => !a.startsWith("-"));
|
|
26
40
|
const local = args.includes("--local") || corePkg.version === "0.0.0-development";
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
const KEBAB = /^[a-z][a-z0-9-]*$/;
|
|
43
|
+
const titleFrom = (name) =>
|
|
44
|
+
name
|
|
45
|
+
.split("-")
|
|
46
|
+
.map((w) => w[0].toUpperCase() + w.slice(1))
|
|
47
|
+
.join(" ");
|
|
48
|
+
|
|
49
|
+
// ---- resolve inputs ---------------------------------------------------------
|
|
50
|
+
// Prompt for EVERYTHING before a single file is written, so a Ctrl+C never
|
|
51
|
+
// leaves a half-created theme on disk.
|
|
52
|
+
let name, dir, title, author, doInstall;
|
|
53
|
+
const interactive = isInteractive() && !nameArg;
|
|
54
|
+
|
|
55
|
+
if (interactive) {
|
|
56
|
+
brandIntro();
|
|
57
|
+
|
|
58
|
+
const where = cancelGuard(
|
|
59
|
+
await text({
|
|
60
|
+
message: "Where should we create your theme?",
|
|
61
|
+
placeholder: "./my-theme",
|
|
62
|
+
defaultValue: "./my-theme",
|
|
63
|
+
validate(value) {
|
|
64
|
+
const v = (value || "./my-theme").trim();
|
|
65
|
+
const base = basename(resolve(process.cwd(), v));
|
|
66
|
+
if (!KEBAB.test(base))
|
|
67
|
+
return "The folder name must be kebab-case (a-z, 0-9, dashes).";
|
|
68
|
+
if (existsSync(resolve(process.cwd(), v)))
|
|
69
|
+
return `${v} already exists — pick a path that doesn't exist yet.`;
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
const rel = (where || "./my-theme").trim();
|
|
74
|
+
dir = resolve(process.cwd(), rel);
|
|
75
|
+
name = basename(dir);
|
|
76
|
+
|
|
77
|
+
title = cancelGuard(
|
|
78
|
+
await text({
|
|
79
|
+
message: "Theme title?",
|
|
80
|
+
placeholder: titleFrom(name),
|
|
81
|
+
defaultValue: titleFrom(name),
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
title = (title || titleFrom(name)).trim();
|
|
85
|
+
|
|
86
|
+
author = cancelGuard(
|
|
87
|
+
await text({
|
|
88
|
+
message: "Author?",
|
|
89
|
+
placeholder: "CHANGE-ME",
|
|
90
|
+
defaultValue: "CHANGE-ME",
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
author = (author || "CHANGE-ME").trim() || "CHANGE-ME";
|
|
94
|
+
|
|
95
|
+
doInstall = cancelGuard(
|
|
96
|
+
await confirm({
|
|
97
|
+
message: "Install dependencies with bun now?",
|
|
98
|
+
initialValue: true,
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
// Non-interactive: a name argument is mandatory. No prompts, no install.
|
|
103
|
+
if (!nameArg || !KEBAB.test(nameArg)) {
|
|
104
|
+
if (!nameArg && !process.stdout.isTTY) {
|
|
105
|
+
console.error(
|
|
106
|
+
`${pc.red("✗")} a theme name is required in non-interactive mode\n usage: ${pc.cyan("bunx @panomc/theme-core new <kebab-case-name> [--local]")}\n ${pc.dim("(run it in a terminal with no name for the interactive wizard)")}`,
|
|
107
|
+
);
|
|
108
|
+
} else {
|
|
109
|
+
console.error(
|
|
110
|
+
`${pc.red("✗")} usage: ${pc.cyan("bunx @panomc/theme-core new <kebab-case-name> [--local]")}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
name = nameArg;
|
|
116
|
+
dir = resolve(process.cwd(), name);
|
|
117
|
+
if (existsSync(dir)) {
|
|
118
|
+
console.error(`${pc.red("✗")} ${dir} already exists — refusing to overwrite`);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
title = titleFrom(name);
|
|
122
|
+
author = "CHANGE-ME";
|
|
123
|
+
doInstall = false;
|
|
37
124
|
}
|
|
38
125
|
|
|
39
|
-
const title = name
|
|
40
|
-
.split("-")
|
|
41
|
-
.map((w) => w[0].toUpperCase() + w.slice(1))
|
|
42
|
-
.join(" ");
|
|
43
|
-
|
|
44
|
-
|
|
45
126
|
// ---- dependency sources -----------------------------------------------------
|
|
46
127
|
// Local mode links straight into the workspace checkout so the scaffold works
|
|
47
128
|
// before the packages exist on npm; published mode uses semver ranges.
|
|
@@ -90,7 +171,7 @@ const FILES = {
|
|
|
90
171
|
id: name,
|
|
91
172
|
title,
|
|
92
173
|
version: "1.0.0",
|
|
93
|
-
author
|
|
174
|
+
author,
|
|
94
175
|
description: `${title} theme for Pano`,
|
|
95
176
|
panoVersion: "1.0.0",
|
|
96
177
|
screenshots: [],
|
|
@@ -247,9 +328,8 @@ ${collectTokens()}`,
|
|
|
247
328
|
A Pano theme built on [@panomc/theme-core](https://github.com/PanoMC/sdk).
|
|
248
329
|
|
|
249
330
|
\`\`\`sh
|
|
250
|
-
bun install
|
|
251
|
-
bun run
|
|
252
|
-
bun run dev # against a local Pano backend (VITE_API_URL in .env)
|
|
331
|
+
bun install # also generates routes / lang / lib bridges
|
|
332
|
+
bun run dev:ui # against a local Pano backend (VITE_API_URL in .env)
|
|
253
333
|
bun run check # contract lint
|
|
254
334
|
bun run build && bun run package
|
|
255
335
|
\`\`\`
|
|
@@ -259,23 +339,73 @@ bun run build && bun run package
|
|
|
259
339
|
`,
|
|
260
340
|
};
|
|
261
341
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
342
|
+
// ---- scaffold ---------------------------------------------------------------
|
|
343
|
+
function scaffold() {
|
|
344
|
+
for (const [rel, content] of Object.entries(FILES)) {
|
|
345
|
+
const target = join(dir, rel);
|
|
346
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
347
|
+
writeFileSync(target, content);
|
|
348
|
+
}
|
|
349
|
+
copyFileSync(join(binDir, "templates", "app.html"), join(dir, "src", "app.html"));
|
|
350
|
+
return Object.keys(FILES).length + 1;
|
|
267
351
|
}
|
|
268
|
-
copyFileSync(join(binDir, "templates", "app.html"), join(dir, "src", "app.html"));
|
|
269
|
-
|
|
270
|
-
console.log(`[theme-core] scaffolded ${name}/ (${Object.keys(FILES).length + 1} files, ${local ? "local workspace links" : `core ^${corePkg.version}`})
|
|
271
352
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
353
|
+
const depLabel = local ? "local workspace links" : `core ^${corePkg.version}`;
|
|
354
|
+
|
|
355
|
+
if (interactive) {
|
|
356
|
+
const s = spinner();
|
|
357
|
+
s.start(`Scaffolding ${name}…`);
|
|
358
|
+
const count = scaffold();
|
|
359
|
+
s.stop(`Scaffolded ${count} files ${pc.dim(`(${depLabel})`)}`);
|
|
360
|
+
|
|
361
|
+
if (doInstall) {
|
|
362
|
+
const s2 = spinner();
|
|
363
|
+
s2.start("Installing dependencies (bun install)…");
|
|
364
|
+
const r = spawnSync("bun", ["install", "--backend=copyfile"], {
|
|
365
|
+
cwd: dir,
|
|
366
|
+
stdio: "ignore",
|
|
367
|
+
});
|
|
368
|
+
if (r.status === 0) {
|
|
369
|
+
s2.stop("Installed dependencies");
|
|
370
|
+
} else {
|
|
371
|
+
s2.stop(`${pc.yellow("▲")} bun install did not complete — run it yourself`);
|
|
372
|
+
note(
|
|
373
|
+
`${pc.dim("cd")} ${name}\n${pc.dim("run")} ${pc.cyan("bun install --backend=copyfile")}`,
|
|
374
|
+
"Finish setup manually",
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
277
378
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
379
|
+
outro(
|
|
380
|
+
[
|
|
381
|
+
pc.bold("Your theme is ready!"),
|
|
382
|
+
"",
|
|
383
|
+
"Next steps:",
|
|
384
|
+
` ${pc.cyan(`cd ${name}`)}`,
|
|
385
|
+
doInstall ? null : ` ${pc.cyan("bun install --backend=copyfile")}`,
|
|
386
|
+
` ${pc.cyan("bun run dev:ui")}`,
|
|
387
|
+
"",
|
|
388
|
+
`Then browse through your Pano's address ${pc.dim("(e.g. http://localhost:8088)")}.`,
|
|
389
|
+
`Docs: ${pc.cyan(DOCS_URL)}`,
|
|
390
|
+
]
|
|
391
|
+
.filter((l) => l !== null)
|
|
392
|
+
.join("\n"),
|
|
393
|
+
);
|
|
394
|
+
} else {
|
|
395
|
+
const count = scaffold();
|
|
396
|
+
console.log(
|
|
397
|
+
[
|
|
398
|
+
`${pc.green("✓")} scaffolded ${pc.bold(`${name}/`)} ${pc.dim(`(${count} files, ${depLabel})`)}`,
|
|
399
|
+
"",
|
|
400
|
+
pc.bold("Next steps:"),
|
|
401
|
+
` ${pc.cyan(`cd ${name}`)}`,
|
|
402
|
+
` ${pc.cyan("bun install")} ${pc.dim('# also generates routes/lang/bridges; if it hangs: bun install --backend=copyfile')}`,
|
|
403
|
+
` ${pc.cyan("bun run dev:ui")} ${pc.dim("# needs a Pano backend (VITE_API_URL in .env)")}`,
|
|
404
|
+
"",
|
|
405
|
+
pc.bold("Make it yours:"),
|
|
406
|
+
` ${pc.cyan("src/styles/tokens.scss")} ${pc.dim("colors / fonts / radius (Tier 1)")}`,
|
|
407
|
+
` ${pc.cyan("bunx @panomc/theme-core list-views")} ${pc.dim("what you can override")}`,
|
|
408
|
+
` ${pc.cyan("bunx @panomc/theme-core eject-view HomeView")} ${pc.dim("own a page's markup (Tier 2)")}`,
|
|
409
|
+
].join("\n"),
|
|
410
|
+
);
|
|
411
|
+
}
|
package/bin/package-zip.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { execFileSync } from "node:child_process";
|
|
14
14
|
import { existsSync, readFileSync, rmSync, utimesSync, readdirSync, statSync } from "node:fs";
|
|
15
15
|
import { join, resolve } from "node:path";
|
|
16
|
+
import { pc } from "./ui.js";
|
|
16
17
|
|
|
17
18
|
const ROOT = process.cwd();
|
|
18
19
|
|
|
@@ -53,5 +54,7 @@ execFileSync("zip", ["-X", "-q", out, "-@"], {
|
|
|
53
54
|
});
|
|
54
55
|
|
|
55
56
|
const hash = execFileSync("sha256sum", [out]).toString().split(" ")[0];
|
|
56
|
-
console.log(
|
|
57
|
-
console.log(
|
|
57
|
+
console.log(`${pc.green("✓")} ${pc.bold("packaged")} ${pc.cyan(out)}`);
|
|
58
|
+
console.log(
|
|
59
|
+
` ${pc.dim(`${files.length} entries, sha256`)} ${hash}\n ${pc.dim("(this hash is the premium license identity)")}`,
|
|
60
|
+
);
|
package/bin/sync.js
CHANGED
|
@@ -17,6 +17,7 @@ import { mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, statSy
|
|
|
17
17
|
import { join, dirname } from "node:path";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import { createRequire } from "node:module";
|
|
20
|
+
import { pc } from "./ui.js";
|
|
20
21
|
|
|
21
22
|
const EJECT_MARKER = "@theme-core-eject";
|
|
22
23
|
const HEADER_JS = "// AUTO-GENERATED by theme-core sync — do not edit.\n// To take ownership of this file, add an eject comment (see theme-core docs).\n";
|
|
@@ -386,5 +387,5 @@ const langMerged = syncLang();
|
|
|
386
387
|
backfillTokens();
|
|
387
388
|
|
|
388
389
|
console.log(
|
|
389
|
-
|
|
390
|
+
`${pc.green("✓")} ${pc.bold("theme-core sync")} — ${written} shims written, ${ejected} ejected (kept), ${removed} stale removed, ${langMerged} lang files merged`,
|
|
390
391
|
);
|
package/bin/theme-core.js
CHANGED
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* theme-core CLI — the theme author's single entry point.
|
|
4
4
|
*
|
|
5
|
+
* bunx @panomc/theme-core new [name] scaffold a working Pano theme
|
|
5
6
|
* bunx @panomc/theme-core sync regenerate route shims + host-provides stubs
|
|
7
|
+
* bunx @panomc/theme-core check contract lint (view registry, svelte pin, …)
|
|
8
|
+
* bunx @panomc/theme-core list-views list the overridable core views
|
|
6
9
|
* bunx @panomc/theme-core eject-view <ViewName>
|
|
7
10
|
* copy a core default view into src/views/ and
|
|
8
11
|
* register it in theme.config.js
|
|
9
|
-
* bunx @panomc/theme-core check contract lint (view registry, svelte pin,
|
|
10
|
-
* settings keys, mandatory slots)
|
|
11
12
|
* bunx @panomc/theme-core package reproducible zip of build/ (the zip sha256
|
|
12
13
|
* is the premium license identity)
|
|
13
|
-
*
|
|
14
14
|
*/
|
|
15
15
|
import { spawnSync } from "node:child_process";
|
|
16
16
|
import { existsSync, readFileSync, writeFileSync, copyFileSync, mkdirSync } from "node:fs";
|
|
17
17
|
import { join, dirname } from "node:path";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { pc, version, DOCS_URL, brandIntro, outro, note } from "./ui.js";
|
|
19
20
|
|
|
20
21
|
const binDir = dirname(fileURLToPath(import.meta.url));
|
|
21
22
|
const [cmd, ...args] = process.argv.slice(2);
|
|
@@ -28,51 +29,160 @@ function run(script, extra = []) {
|
|
|
28
29
|
process.exit(r.status ?? 0);
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
/** name → one-line description, in help-display order. */
|
|
33
|
+
const COMMANDS = {
|
|
34
|
+
new: "scaffold a working Pano theme (interactive when run with no name)",
|
|
35
|
+
sync: "regenerate route shims + host-provides stubs + merged lang",
|
|
36
|
+
check: "contract lint — view registry, svelte pin, slots, settings",
|
|
37
|
+
"list-views": "list the core views you can override",
|
|
38
|
+
"eject-view": "copy a default view into src/views/ and register it",
|
|
39
|
+
package: "reproducible zip of build/ (its sha256 is the license identity)",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function printHelp() {
|
|
43
|
+
const pad = Math.max(...Object.keys(COMMANDS).map((k) => k.length));
|
|
44
|
+
const lines = [
|
|
45
|
+
`${pc.bgCyan(pc.black(" pano "))} ${pc.bold("theme-core")} ${pc.dim(`v${version}`)}`,
|
|
46
|
+
"",
|
|
47
|
+
pc.dim("The Pano theme engine CLI."),
|
|
48
|
+
"",
|
|
49
|
+
pc.bold("Usage"),
|
|
50
|
+
` ${pc.cyan("bunx @panomc/theme-core")} ${pc.yellow("<command>")} ${pc.dim("[options]")}`,
|
|
51
|
+
"",
|
|
52
|
+
pc.bold("Commands"),
|
|
53
|
+
];
|
|
54
|
+
for (const [name, desc] of Object.entries(COMMANDS)) {
|
|
55
|
+
const arg = name === "eject-view" ? pc.dim(" <View>") : "";
|
|
56
|
+
lines.push(` ${pc.yellow(name.padEnd(pad))}${arg} ${pc.dim(desc)}`);
|
|
57
|
+
}
|
|
58
|
+
lines.push(
|
|
59
|
+
"",
|
|
60
|
+
pc.bold("Examples"),
|
|
61
|
+
` ${pc.cyan("bunx @panomc/theme-core new")} ${pc.dim("interactive scaffolder")}`,
|
|
62
|
+
` ${pc.cyan("bunx @panomc/theme-core new my-theme")} ${pc.dim("scaffold immediately")}`,
|
|
63
|
+
` ${pc.cyan("bunx @panomc/theme-core eject-view LoginView")}`,
|
|
64
|
+
"",
|
|
65
|
+
`${pc.bold("Docs")} ${pc.cyan(DOCS_URL)}`,
|
|
66
|
+
"",
|
|
67
|
+
);
|
|
68
|
+
console.log(lines.join("\n"));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Cheap edit distance for the "did you mean" hint on an unknown command. */
|
|
72
|
+
function levenshtein(a, b) {
|
|
73
|
+
const dp = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
74
|
+
for (let j = 0; j <= b.length; j++) dp[0][j] = j;
|
|
75
|
+
for (let i = 1; i <= a.length; i++) {
|
|
76
|
+
for (let j = 1; j <= b.length; j++) {
|
|
77
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
78
|
+
dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return dp[a.length][b.length];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function suggest(input) {
|
|
85
|
+
const names = Object.keys(COMMANDS);
|
|
86
|
+
// Prefix match first, then closest edit distance within a small threshold.
|
|
87
|
+
const prefix = names.find((n) => n.startsWith(input));
|
|
88
|
+
if (prefix) return prefix;
|
|
89
|
+
let best = null;
|
|
90
|
+
let bestD = Infinity;
|
|
91
|
+
for (const n of names) {
|
|
92
|
+
const d = levenshtein(input, n);
|
|
93
|
+
if (d < bestD) {
|
|
94
|
+
bestD = d;
|
|
95
|
+
best = n;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return bestD <= 3 ? best : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
31
101
|
switch (cmd) {
|
|
102
|
+
case undefined:
|
|
103
|
+
case "help":
|
|
104
|
+
case "--help":
|
|
105
|
+
case "-h":
|
|
106
|
+
printHelp();
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
case "--version":
|
|
110
|
+
case "-v":
|
|
111
|
+
console.log(version);
|
|
112
|
+
break;
|
|
113
|
+
|
|
32
114
|
case "new":
|
|
33
115
|
run("new.js", args);
|
|
34
116
|
break;
|
|
35
117
|
case "sync":
|
|
36
118
|
run("sync.js");
|
|
37
119
|
break;
|
|
120
|
+
case "check":
|
|
121
|
+
run("check.js", args);
|
|
122
|
+
break;
|
|
123
|
+
case "package":
|
|
124
|
+
run("package-zip.js", args);
|
|
125
|
+
break;
|
|
126
|
+
|
|
38
127
|
case "list-views": {
|
|
39
128
|
const contract = JSON.parse(
|
|
40
129
|
readFileSync(join(binDir, "..", "skin-contract.json"), "utf-8"),
|
|
41
130
|
);
|
|
42
|
-
console.log(
|
|
131
|
+
console.log(
|
|
132
|
+
`\n${pc.bgCyan(pc.black(" pano "))} ${pc.bold("theme-core")} ${pc.dim(`v${version}`)}`,
|
|
133
|
+
);
|
|
134
|
+
// Wrap the (sometimes long) props list under an indented tree so the
|
|
135
|
+
// output stays readable instead of running one giant line per view.
|
|
136
|
+
const width = Math.min(process.stdout.columns || 80, 100);
|
|
137
|
+
const indent = " ";
|
|
138
|
+
const wrap = (items) => {
|
|
139
|
+
const lines = [];
|
|
140
|
+
let line = "";
|
|
141
|
+
for (const item of items) {
|
|
142
|
+
const chunk = line ? `${line}, ${item}` : item;
|
|
143
|
+
if (indent.length + chunk.length > width && line) {
|
|
144
|
+
lines.push(indent + line + ",");
|
|
145
|
+
line = item;
|
|
146
|
+
} else {
|
|
147
|
+
line = chunk;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (line) lines.push(indent + line);
|
|
151
|
+
return lines;
|
|
152
|
+
};
|
|
153
|
+
console.log(pc.bold("\n Overridable views ") + pc.dim("(theme.config.js → views)\n"));
|
|
43
154
|
for (const [name, def] of Object.entries(contract.views)) {
|
|
44
155
|
const props = Object.keys(def.props ?? {});
|
|
45
|
-
console.log(` ${
|
|
156
|
+
console.log(` ${pc.cyan("●")} ${pc.bold(name)}`);
|
|
157
|
+
if (props.length) for (const l of wrap(props)) console.log(pc.dim(l));
|
|
158
|
+
else console.log(indent + pc.dim("(no props)"));
|
|
46
159
|
}
|
|
160
|
+
console.log(pc.bold("\n Registry components ") + pc.dim("(chrome + plugin-facing)"));
|
|
161
|
+
for (const l of wrap(contract.registry_components)) console.log(pc.dim(l));
|
|
47
162
|
console.log(
|
|
48
|
-
`\
|
|
49
|
-
|
|
50
|
-
console.log(
|
|
51
|
-
"\nEject one with: bunx @panomc/theme-core eject-view <ViewName>\n(the file's header documents every prop in detail)",
|
|
163
|
+
`\n Eject one with ${pc.cyan("bunx @panomc/theme-core eject-view <ViewName>")}` +
|
|
164
|
+
`\n ${pc.dim("(the file's header documents every prop in detail)")}\n`,
|
|
52
165
|
);
|
|
53
166
|
break;
|
|
54
167
|
}
|
|
55
|
-
|
|
56
|
-
run("check.js", args);
|
|
57
|
-
break;
|
|
58
|
-
case "package":
|
|
59
|
-
run("package-zip.js", args);
|
|
60
|
-
break;
|
|
168
|
+
|
|
61
169
|
case "eject-view": {
|
|
62
170
|
const name = args[0];
|
|
63
171
|
if (!name || !/^[A-Z][A-Za-z0-9]*View$/.test(name)) {
|
|
64
|
-
console.error(
|
|
172
|
+
console.error(
|
|
173
|
+
`${pc.red("✗")} usage: ${pc.cyan("bunx @panomc/theme-core eject-view <ViewName>")} ${pc.dim("(e.g. LoginView)")}`,
|
|
174
|
+
);
|
|
65
175
|
process.exit(1);
|
|
66
176
|
}
|
|
67
177
|
const source = join(binDir, "..", "src", "lib", "views", `${name}.svelte`);
|
|
68
178
|
if (!existsSync(source)) {
|
|
69
|
-
console.error(
|
|
179
|
+
console.error(`${pc.red("✗")} no default view named ${pc.bold(name)} in this core version`);
|
|
70
180
|
process.exit(1);
|
|
71
181
|
}
|
|
72
182
|
const targetDir = join(process.cwd(), "src", "views");
|
|
73
183
|
const target = join(targetDir, `${name}.svelte`);
|
|
74
184
|
if (existsSync(target)) {
|
|
75
|
-
console.error(
|
|
185
|
+
console.error(`${pc.red("✗")} ${target} already exists — refusing to overwrite`);
|
|
76
186
|
process.exit(1);
|
|
77
187
|
}
|
|
78
188
|
mkdirSync(targetDir, { recursive: true });
|
|
@@ -80,6 +190,7 @@ switch (cmd) {
|
|
|
80
190
|
|
|
81
191
|
// Register in theme.config.js (idempotent, text-level).
|
|
82
192
|
const configPath = join(process.cwd(), "theme.config.js");
|
|
193
|
+
let registered = false;
|
|
83
194
|
if (existsSync(configPath)) {
|
|
84
195
|
let cfg = readFileSync(configPath, "utf-8");
|
|
85
196
|
if (!cfg.includes(`${name}:`)) {
|
|
@@ -89,14 +200,34 @@ switch (cmd) {
|
|
|
89
200
|
);
|
|
90
201
|
writeFileSync(configPath, cfg);
|
|
91
202
|
}
|
|
92
|
-
|
|
93
|
-
console.warn("[theme-core] no theme.config.js found — register the view manually");
|
|
203
|
+
registered = true;
|
|
94
204
|
}
|
|
95
|
-
|
|
96
|
-
|
|
205
|
+
|
|
206
|
+
brandIntro();
|
|
207
|
+
note(
|
|
208
|
+
[
|
|
209
|
+
`${pc.green("✓")} copied to ${pc.cyan(`src/views/${name}.svelte`)}`,
|
|
210
|
+
registered
|
|
211
|
+
? `${pc.green("✓")} registered in ${pc.cyan("theme.config.js")}`
|
|
212
|
+
: `${pc.yellow("▲")} no theme.config.js found — register the view manually`,
|
|
213
|
+
].join("\n"),
|
|
214
|
+
`Ejected ${name}`,
|
|
215
|
+
);
|
|
216
|
+
outro(
|
|
217
|
+
[
|
|
218
|
+
"Next steps:",
|
|
219
|
+
` ${pc.dim("edit")} ${pc.cyan(`src/views/${name}.svelte`)} ${pc.dim("(props are documented in its header)")}`,
|
|
220
|
+
` ${pc.dim("run")} ${pc.cyan("bun run check")} ${pc.dim("to validate the override contract")}`,
|
|
221
|
+
].join("\n"),
|
|
222
|
+
);
|
|
97
223
|
break;
|
|
98
224
|
}
|
|
99
|
-
|
|
100
|
-
|
|
225
|
+
|
|
226
|
+
default: {
|
|
227
|
+
const hint = suggest(cmd);
|
|
228
|
+
console.error(`${pc.red("✗")} unknown command ${pc.bold(cmd)}`);
|
|
229
|
+
if (hint) console.error(` did you mean ${pc.cyan(hint)}?`);
|
|
230
|
+
console.error(` run ${pc.cyan("theme-core help")} to see all commands`);
|
|
101
231
|
process.exit(1);
|
|
232
|
+
}
|
|
102
233
|
}
|
package/bin/ui.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ui.js — shared CLI presentation layer for the theme-core commands.
|
|
3
|
+
*
|
|
4
|
+
* Wraps @clack/prompts + picocolors so every command speaks the same visual
|
|
5
|
+
* language (styled intro/outro, spinners, prompts) and shares the TTY/CI
|
|
6
|
+
* detection that keeps sync/check/package safe to run non-interactively.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { join, dirname } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import * as clack from "@clack/prompts";
|
|
12
|
+
import pc from "picocolors";
|
|
13
|
+
|
|
14
|
+
export { clack, pc };
|
|
15
|
+
|
|
16
|
+
// Re-export the clack primitives the commands reach for, so callers import
|
|
17
|
+
// from one place instead of poking at the namespace.
|
|
18
|
+
export const {
|
|
19
|
+
intro,
|
|
20
|
+
outro,
|
|
21
|
+
text,
|
|
22
|
+
confirm,
|
|
23
|
+
select,
|
|
24
|
+
spinner,
|
|
25
|
+
cancel,
|
|
26
|
+
isCancel,
|
|
27
|
+
note,
|
|
28
|
+
log,
|
|
29
|
+
} = clack;
|
|
30
|
+
|
|
31
|
+
const binDir = dirname(fileURLToPath(import.meta.url));
|
|
32
|
+
export const corePkg = JSON.parse(
|
|
33
|
+
readFileSync(join(binDir, "..", "package.json"), "utf-8"),
|
|
34
|
+
);
|
|
35
|
+
export const version = corePkg.version;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Interactive when we own a real TTY and are not inside CI. Every command that
|
|
39
|
+
* might prompt gates on this — a non-interactive invocation (scripts, CI,
|
|
40
|
+
* postinstall, piped stdin) must never block waiting for input.
|
|
41
|
+
*/
|
|
42
|
+
export function isInteractive() {
|
|
43
|
+
return Boolean(process.stdout.isTTY) && !process.env.CI;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Unwrap a clack prompt result, honoring Ctrl+C: on cancel we print the
|
|
48
|
+
* standard cancel line and exit non-zero so nothing half-completes.
|
|
49
|
+
*/
|
|
50
|
+
export function cancelGuard(value) {
|
|
51
|
+
if (isCancel(value)) {
|
|
52
|
+
cancel("Operation cancelled.");
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Styled brand header: "pano theme-core vX.Y.Z". */
|
|
59
|
+
export function brandIntro() {
|
|
60
|
+
intro(
|
|
61
|
+
`${pc.bgCyan(pc.black(" pano "))} ${pc.bold("theme-core")} ${pc.dim(`v${version}`)}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Docs entry point, referenced by help/new/eject next-steps. */
|
|
66
|
+
export const DOCS_URL = "https://panocms.com/docs/theme/getting-started/";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panomc/theme-core",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.46",
|
|
4
4
|
"description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
|
|
5
5
|
"author": "PanoMC",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
+
"@clack/prompts": "^0.11.0",
|
|
51
|
+
"picocolors": "^1.1.0",
|
|
50
52
|
"svelte": "5.55.4",
|
|
51
53
|
"mime-types": "^3.0.2",
|
|
52
54
|
"date-fns": "^4.1.0",
|
package/src/kit/vite-config.js
CHANGED
|
@@ -166,7 +166,6 @@ export function createViteConfig(opts = {}) {
|
|
|
166
166
|
],
|
|
167
167
|
quietDeps: true,
|
|
168
168
|
silenceDeprecations: [
|
|
169
|
-
"mixed-decls",
|
|
170
169
|
"color-functions",
|
|
171
170
|
"global-builtin",
|
|
172
171
|
"import",
|
|
@@ -182,6 +181,19 @@ export function createViteConfig(opts = {}) {
|
|
|
182
181
|
"svelte",
|
|
183
182
|
...(opts.extraOptimizeExclude ?? []),
|
|
184
183
|
],
|
|
184
|
+
// When the engine is a real node_modules install (registry, not a
|
|
185
|
+
// file:/workspace link), vite's dependency scanner cannot resolve the
|
|
186
|
+
// engine's .svelte glob imports and aborts with a scary "Failed to run
|
|
187
|
+
// dependency scan" wall of errors. The scan is only a warm-up — skip
|
|
188
|
+
// it there; the `include` list above is still pre-bundled.
|
|
189
|
+
...(function () {
|
|
190
|
+
try {
|
|
191
|
+
const p = path.join(process.cwd(), "node_modules", "@panomc", "theme-core");
|
|
192
|
+
return fs.existsSync(p) && !fs.lstatSync(p).isSymbolicLink() ? { entries: [] } : {};
|
|
193
|
+
} catch {
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
})(),
|
|
185
197
|
},
|
|
186
198
|
server: {
|
|
187
199
|
proxy: {
|