@prismora/cli 0.1.2 → 0.1.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.
- package/dist/prismora.js +274 -56
- package/package.json +1 -1
package/dist/prismora.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
5
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "node:path";
|
|
5
|
+
import { basename, dirname as dirname2, join as join2, relative as relative2, resolve as resolve2 } from "node:path";
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
8
|
|
|
@@ -936,37 +936,49 @@ var noFlashScript = `(()=>{try{var s=JSON.parse(localStorage.getItem('${STORAGE_
|
|
|
936
936
|
|
|
937
937
|
// src/init.ts
|
|
938
938
|
var KINDS = {
|
|
939
|
-
next: { label: "Next.js", dep: "next", fw: "react", wrapper: "@prismora/react" },
|
|
939
|
+
next: { label: "Next.js (App or Pages Router)", dep: "next", fw: "react", wrapper: "@prismora/react" },
|
|
940
|
+
"react-router": { label: "React Router 7 / Remix", dep: "@react-router/dev", also: ["@remix-run/dev"], fw: "react", wrapper: "@prismora/react" },
|
|
941
|
+
"tanstack-start": { label: "TanStack Start", dep: "@tanstack/react-start", fw: "react", wrapper: "@prismora/react" },
|
|
940
942
|
react: { label: "React (Vite)", dep: "react", fw: "react", wrapper: "@prismora/react" },
|
|
943
|
+
preact: { label: "Preact (Vite)", dep: "preact", fw: "react", wrapper: "@prismora/react" },
|
|
941
944
|
nuxt: { label: "Nuxt", dep: "nuxt", fw: "vue", wrapper: "@prismora/vue" },
|
|
942
945
|
vue: { label: "Vue (Vite)", dep: "vue", fw: "vue", wrapper: "@prismora/vue" },
|
|
943
946
|
sveltekit: { label: "SvelteKit", dep: "@sveltejs/kit", fw: "svelte", wrapper: "@prismora/svelte" },
|
|
944
947
|
svelte: { label: "Svelte (Vite)", dep: "svelte", fw: "svelte", wrapper: "@prismora/svelte" },
|
|
948
|
+
"solid-start": { label: "SolidStart", dep: "@solidjs/start", fw: "solid", wrapper: "@prismora/solid" },
|
|
945
949
|
solid: { label: "Solid", dep: "solid-js", fw: "solid", wrapper: "@prismora/solid" },
|
|
950
|
+
qwik: { label: "Qwik", dep: "@builder.io/qwik", also: ["@qwik.dev/core"], fw: "html" },
|
|
946
951
|
astro: { label: "Astro", dep: "astro", fw: "html" },
|
|
947
952
|
angular: { label: "Angular", dep: "@angular/core", fw: "angular", wrapper: "@prismora/angular" },
|
|
953
|
+
lit: { label: "Lit (Vite)", dep: "lit", fw: "html" },
|
|
948
954
|
html: { label: "Plain HTML (no bundler)", fw: "html" }
|
|
949
|
-
}, DETECT_ORDER = ["sveltekit", "next", "nuxt", "astro", "angular", "solid", "svelte", "vue", "react"], isKind = (v) => (v in KINDS);
|
|
955
|
+
}, DETECT_ORDER = ["sveltekit", "next", "react-router", "tanstack-start", "nuxt", "astro", "angular", "qwik", "solid-start", "solid", "svelte", "vue", "preact", "react", "lit"], isKind = (v) => (v in KINDS);
|
|
950
956
|
function detectProject(cwd) {
|
|
951
|
-
let pkgPath = join(cwd, "package.json"), pkg = existsSync(pkgPath) ? JSON.parse(readFileSync(pkgPath, "utf8")) : {}, deps = { ...pkg.dependencies, ...pkg.devDependencies }, kind = DETECT_ORDER.find((k) =>
|
|
957
|
+
let pkgPath = join(cwd, "package.json"), pkg = existsSync(pkgPath) ? JSON.parse(readFileSync(pkgPath, "utf8")) : {}, deps = { ...pkg.dependencies, ...pkg.devDependencies }, kind = DETECT_ORDER.find((k) => [KINDS[k].dep, ...KINDS[k].also ?? []].some((d) => (d in deps))) ?? "html", has = (f) => existsSync(join(cwd, f)), pm = has("bun.lock") || has("bun.lockb") ? "bun" : has("pnpm-lock.yaml") ? "pnpm" : has("yarn.lock") ? "yarn" : /^(bun|pnpm|yarn)@/.test(pkg.packageManager ?? "") ? pkg.packageManager.split("@")[0] : "npm";
|
|
952
958
|
return { cwd, kind, pm, hasPkg: existsSync(pkgPath), ts: has("tsconfig.json") || "typescript" in deps, deps };
|
|
953
959
|
}
|
|
954
|
-
var installCommand = (pm) => ({ bun: "bun add", pnpm: "pnpm add", yarn: "yarn add", npm: "npm install" })[pm], first = (cwd, files) => files.find((f) => existsSync(join(cwd, f)));
|
|
960
|
+
var installCommand = (pm) => ({ bun: "bun add", pnpm: "pnpm add", yarn: "yarn add", npm: "npm install" })[pm], devInstallCommand = (pm) => ({ bun: "bun add -d", pnpm: "pnpm add -D", yarn: "yarn add -D", npm: "npm install -D" })[pm], runCommand = (pm) => ({ bun: "bunx", pnpm: "pnpm exec", yarn: "yarn", npm: "npx" })[pm], CLI_PACKAGE = "@prismora/cli", first = (cwd, files) => files.find((f) => existsSync(join(cwd, f)));
|
|
955
961
|
function nuxtBase(cwd) {
|
|
956
962
|
return existsSync(join(cwd, "app/app.vue")) || existsSync(join(cwd, "app/pages")) ? "app" : ".";
|
|
957
963
|
}
|
|
958
964
|
function nextAppDir(cwd) {
|
|
959
965
|
return first(cwd, ["src/app", "app"]);
|
|
960
966
|
}
|
|
967
|
+
function nextPagesDir(cwd) {
|
|
968
|
+
return nextAppDir(cwd) ? void 0 : first(cwd, ["src/pages", "pages"]);
|
|
969
|
+
}
|
|
970
|
+
var hasBundler = (p) => ["vite", "parcel"].some((d) => (d in p.deps));
|
|
961
971
|
function defaultCssPath(p, kind) {
|
|
962
972
|
let src = existsSync(join(p.cwd, "src")) ? "src" : ".";
|
|
963
973
|
switch (kind) {
|
|
964
974
|
case "next":
|
|
965
|
-
return join(nextAppDir(p.cwd) ?? src, "prismora.theme.css");
|
|
975
|
+
return join(nextAppDir(p.cwd) ?? (nextPagesDir(p.cwd) ? src === "src" ? "src/styles" : "styles" : src), "prismora.theme.css");
|
|
976
|
+
case "react-router":
|
|
977
|
+
return "app/prismora.theme.css";
|
|
966
978
|
case "nuxt":
|
|
967
979
|
return join(nuxtBase(p.cwd), "assets/css/prismora.theme.css");
|
|
968
980
|
case "html":
|
|
969
|
-
return "prismora.theme.css";
|
|
981
|
+
return hasBundler(p) ? join(src, "prismora.theme.css") : "prismora.theme.css";
|
|
970
982
|
default:
|
|
971
983
|
return join(src, "prismora.theme.css");
|
|
972
984
|
}
|
|
@@ -1022,7 +1034,7 @@ async function ask(p, given, prompt) {
|
|
|
1022
1034
|
}
|
|
1023
1035
|
function packagesFor(o) {
|
|
1024
1036
|
let k = KINDS[o.kind];
|
|
1025
|
-
return ["@prismora/css", "@prismora/elements", "@prismora/theme", ...k.wrapper ? [k.wrapper] : [], ...o.font !== "system" ? ["@prismora/fonts"] : []];
|
|
1037
|
+
return ["@prismora/css", "@prismora/elements", "@prismora/theme", "@prismora/icons", ...k.wrapper ? [k.wrapper] : [], ...o.font !== "system" ? ["@prismora/fonts"] : []];
|
|
1026
1038
|
}
|
|
1027
1039
|
function themeConfig(o) {
|
|
1028
1040
|
return {
|
|
@@ -1127,7 +1139,15 @@ function plan(p, o) {
|
|
|
1127
1139
|
function defaultPagesDir(p, kind) {
|
|
1128
1140
|
switch (kind) {
|
|
1129
1141
|
case "next":
|
|
1130
|
-
return nextAppDir(p.cwd) ?? "app";
|
|
1142
|
+
return nextAppDir(p.cwd) ?? nextPagesDir(p.cwd) ?? "app";
|
|
1143
|
+
case "react-router":
|
|
1144
|
+
return "app/routes";
|
|
1145
|
+
case "tanstack-start":
|
|
1146
|
+
case "solid-start":
|
|
1147
|
+
case "qwik":
|
|
1148
|
+
return "src/routes";
|
|
1149
|
+
case "lit":
|
|
1150
|
+
return ".";
|
|
1131
1151
|
case "nuxt":
|
|
1132
1152
|
return join(nuxtBase(p.cwd), "pages");
|
|
1133
1153
|
case "sveltekit":
|
|
@@ -1142,8 +1162,30 @@ function defaultPagesDir(p, kind) {
|
|
|
1142
1162
|
return existsSync(join(p.cwd, "src")) ? "src/pages" : "pages";
|
|
1143
1163
|
}
|
|
1144
1164
|
}
|
|
1165
|
+
function patchJsxDocument(src, o, opts = {}) {
|
|
1166
|
+
let head = opts.head ?? "head", html = opts.html ?? "html", tag = opts.script ?? "<script dangerouslySetInnerHTML={{ __html: noFlashScript }} />", out = src;
|
|
1167
|
+
if (!out.includes("__html: noFlashScript") && !out.includes("{noFlashScript}")) {
|
|
1168
|
+
let selfClosing = new RegExp(`^([ \\t]*)<${head}\\s*/>`, "m"), open = new RegExp(`^([ \\t]*)<${head}(\\s[^>]*)?>`, "m");
|
|
1169
|
+
if (selfClosing.test(out))
|
|
1170
|
+
out = out.replace(selfClosing, (_, ws) => `${ws}<${head}>
|
|
1171
|
+
${ws} ${tag}
|
|
1172
|
+
${ws}</${head}>`);
|
|
1173
|
+
else if (open.test(out))
|
|
1174
|
+
out = out.replace(open, (h, ws) => `${h}
|
|
1175
|
+
${ws} ${tag}`);
|
|
1176
|
+
else
|
|
1177
|
+
out = out.replace(/(\n?)(\s*)<body/, (_, nl, ws) => `${nl}${ws}<${head}>${tag}</${head}>${nl}${ws}<body`);
|
|
1178
|
+
}
|
|
1179
|
+
return out = out.replace(new RegExp(`<${html}\\b([^>]*)>`), (all, attrs) => {
|
|
1180
|
+
let add = [
|
|
1181
|
+
/suppressHydrationWarning/.test(attrs) ? "" : "suppressHydrationWarning",
|
|
1182
|
+
...htmlAttrs(o).filter((a) => !attrs.includes(a.split("=")[0])).map((a) => a === "mobile" ? 'mobile=""' : a)
|
|
1183
|
+
].filter(Boolean);
|
|
1184
|
+
return add.length ? `<${html}${attrs} ${add.join(" ")}>` : all;
|
|
1185
|
+
}), out;
|
|
1186
|
+
}
|
|
1145
1187
|
function wire(p, o, { read, edit, create, manual }) {
|
|
1146
|
-
let ext = p.ts ? "ts" : "js", fontImport = o.font !== "system" ? [`import '@prismora/fonts/pairing-${o.font}';`] : [], cssImports = (fromFile) => [`import '${MARK}/foundation.css';`, ...fontImport, `import '${rel(fromFile, o.css)}';`], viteHtml = () => {
|
|
1188
|
+
let ext = p.ts ? "ts" : "js", fontImport = o.font !== "system" ? [`import '@prismora/fonts/pairing-${o.font}.css';`] : [], cssImports = (fromFile) => [`import '${MARK}/foundation.css';`, ...fontImport, `import '${rel(fromFile, o.css)}';`], viteHtml = () => {
|
|
1147
1189
|
let f = first(p.cwd, ["index.html"]);
|
|
1148
1190
|
if (f)
|
|
1149
1191
|
edit(f, patchHtml(read(f), o), "no-flash theme script in <head>");
|
|
@@ -1178,29 +1220,104 @@ function wire(p, o, { read, edit, create, manual }) {
|
|
|
1178
1220
|
break;
|
|
1179
1221
|
}
|
|
1180
1222
|
case "next": {
|
|
1181
|
-
let dir = nextAppDir(p.cwd), layout = dir && first(p.cwd, ["tsx", "jsx", "js"].map((e) => `${dir}/layout.${e}`));
|
|
1223
|
+
let dir = nextAppDir(p.cwd), layout = dir && first(p.cwd, ["tsx", "jsx", "js"].map((e) => `${dir}/layout.${e}`)), pages = nextPagesDir(p.cwd);
|
|
1182
1224
|
if (layout) {
|
|
1183
1225
|
let src = read(layout);
|
|
1184
|
-
if (!src.includes(MARK))
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1226
|
+
if (!src.includes(MARK))
|
|
1227
|
+
edit(layout, patchJsxDocument(addImports(src, [...cssImports(layout), "import { noFlashScript } from '@prismora/theme';"]), o), "Prismora styles and no-flash script in the root layout");
|
|
1228
|
+
} else if (pages) {
|
|
1229
|
+
let app = first(p.cwd, ["tsx", "jsx", "js"].map((e) => `${pages}/_app.${e}`));
|
|
1230
|
+
if (app) {
|
|
1231
|
+
if (!read(app).includes(MARK))
|
|
1232
|
+
edit(app, addImports(read(app), cssImports(app)), "Prismora styles (Pages Router)");
|
|
1233
|
+
} else
|
|
1234
|
+
create(`${pages}/_app.${p.ts ? "tsx" : "jsx"}`, `${cssImports(`${pages}/_app.tsx`).join(`
|
|
1235
|
+
`)}
|
|
1236
|
+
${p.ts ? `import type { AppProps } from 'next/app';
|
|
1237
|
+
` : ""}
|
|
1238
|
+
export default function App({ Component, pageProps }${p.ts ? ": AppProps" : ""}) {
|
|
1239
|
+
return <Component {...pageProps} />;
|
|
1240
|
+
}
|
|
1241
|
+
`, "Pages Router app with Prismora styles");
|
|
1242
|
+
let doc = first(p.cwd, ["tsx", "jsx", "js"].map((e) => `${pages}/_document.${e}`)), imp = "import { noFlashScript } from '@prismora/theme';";
|
|
1243
|
+
if (doc) {
|
|
1244
|
+
if (!read(doc).includes("noFlashScript"))
|
|
1245
|
+
edit(doc, patchJsxDocument(addImports(read(doc), [imp]), o, { head: "Head", html: "Html" }), "no-flash theme script in _document");
|
|
1246
|
+
} else
|
|
1247
|
+
create(`${pages}/_document.${p.ts ? "tsx" : "jsx"}`, patchJsxDocument(`import { Html, Head, Main, NextScript } from 'next/document';
|
|
1248
|
+
${imp}
|
|
1249
|
+
|
|
1250
|
+
export default function Document() {
|
|
1251
|
+
return (
|
|
1252
|
+
<Html lang="en">
|
|
1253
|
+
<Head />
|
|
1254
|
+
<body>
|
|
1255
|
+
<Main />
|
|
1256
|
+
<NextScript />
|
|
1257
|
+
</body>
|
|
1258
|
+
</Html>
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
`, o, { head: "Head", html: "Html" }), "document with the no-flash theme script");
|
|
1196
1262
|
} else
|
|
1197
|
-
manual("
|
|
1263
|
+
manual("Import the styles in your root layout (app/layout.tsx) and inline noFlashScript in <head>:", [...cssImports("app/layout.tsx"), "import { noFlashScript } from '@prismora/theme';", "<script dangerouslySetInnerHTML={{ __html: noFlashScript }} />"].join(`
|
|
1198
1264
|
`));
|
|
1199
1265
|
break;
|
|
1200
1266
|
}
|
|
1267
|
+
case "react-router": {
|
|
1268
|
+
let root = first(p.cwd, ["app/root.tsx", "app/root.jsx"]);
|
|
1269
|
+
if (root) {
|
|
1270
|
+
if (!read(root).includes(MARK))
|
|
1271
|
+
edit(root, patchJsxDocument(addImports(read(root), [...cssImports(root), "import { noFlashScript } from '@prismora/theme';"]), o), "Prismora styles and no-flash script in the root layout");
|
|
1272
|
+
} else
|
|
1273
|
+
manual("Import the styles in app/root.tsx and inline noFlashScript first in <head>:", [...cssImports("app/root.tsx"), "import { noFlashScript } from '@prismora/theme';", "<script dangerouslySetInnerHTML={{ __html: noFlashScript }} />"].join(`
|
|
1274
|
+
`));
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
case "tanstack-start": {
|
|
1278
|
+
let root = first(p.cwd, ["src/routes/__root.tsx", "app/routes/__root.tsx"]);
|
|
1279
|
+
if (root) {
|
|
1280
|
+
if (!read(root).includes(MARK))
|
|
1281
|
+
edit(root, patchJsxDocument(addImports(read(root), [...cssImports(root), "import { noFlashScript } from '@prismora/theme';"]), o), "Prismora styles and no-flash script in the root route");
|
|
1282
|
+
} else
|
|
1283
|
+
manual("Import the styles in src/routes/__root.tsx and inline noFlashScript first in <head>:", [...cssImports("src/routes/__root.tsx"), "import { noFlashScript } from '@prismora/theme';"].join(`
|
|
1284
|
+
`));
|
|
1285
|
+
break;
|
|
1286
|
+
}
|
|
1287
|
+
case "solid-start": {
|
|
1288
|
+
entry(["src/app.tsx", "src/app.jsx"]);
|
|
1289
|
+
let client = first(p.cwd, ["src/entry-client.tsx", "src/entry-client.jsx"]);
|
|
1290
|
+
if (client && !read(client).includes("@prismora/elements"))
|
|
1291
|
+
edit(client, addImports(read(client), ["import '@prismora/elements/define';"]), "register the elements in the browser");
|
|
1292
|
+
let server = first(p.cwd, ["src/entry-server.tsx", "src/entry-server.jsx"]);
|
|
1293
|
+
if (server && !read(server).includes("noFlashScript"))
|
|
1294
|
+
edit(server, patchJsxDocument(addImports(read(server), ["import { noFlashScript } from '@prismora/theme';"]), o, { script: "<script innerHTML={noFlashScript} />" }).replace(/ suppressHydrationWarning/, ""), "no-flash theme script in <head>");
|
|
1295
|
+
manual("SolidStart: @prismora/elements/define registers every element; for smaller bundles import single elements (e.g. @prismora/elements/button) in entry-client.");
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
case "qwik": {
|
|
1299
|
+
let root = first(p.cwd, ["src/root.tsx"]), core = "@qwik.dev/core" in p.deps ? "@qwik.dev/core" : "@builder.io/qwik";
|
|
1300
|
+
if (root && !read(root).includes(MARK)) {
|
|
1301
|
+
let src = addImports(read(root), [...cssImports(root), "import { noFlashScript } from '@prismora/theme';", `import { useVisibleTask$ } from '${core}';`]);
|
|
1302
|
+
src = patchJsxDocument(src, o, { script: "<script dangerouslySetInnerHTML={noFlashScript} />" }).replace(/ suppressHydrationWarning/, ""), src = src.replace(/(export default component\$\(\(\) => \{\n)/, `$1 // Custom elements must register in the browser; this loads them once the document is ready.
|
|
1303
|
+
// eslint-disable-next-line qwik/no-use-visible-task
|
|
1304
|
+
useVisibleTask$(() => { import('@prismora/elements/define'); }, { strategy: 'document-ready' });
|
|
1305
|
+
`), edit(root, src, "Prismora styles, no-flash script and elements");
|
|
1306
|
+
} else if (!root)
|
|
1307
|
+
manual("Import the styles in src/root.tsx, inline noFlashScript in <head>, and import @prismora/elements/define in a useVisibleTask$.");
|
|
1308
|
+
if (htmlAttrs(o).length)
|
|
1309
|
+
manual("Qwik: add these to containerAttributes in src/entry.ssr.tsx:", htmlAttrs(o).map((a) => a === "mobile" ? "mobile: ''" : `'data-mode': '${o.mode}'`).join(", "));
|
|
1310
|
+
break;
|
|
1311
|
+
}
|
|
1312
|
+
case "preact":
|
|
1313
|
+
entry(viteEntries(["main", "index"])), viteHtml();
|
|
1314
|
+
break;
|
|
1315
|
+
case "lit":
|
|
1316
|
+
entry(viteEntries(["main", "index", "my-element"]), ["import '@prismora/elements/define';"]), viteHtml(), manual("Lit: Prismora elements bring their own styles and read the theme tokens, so they work inside your components. Utility classes (pm-stack, pm-cluster) apply in the light DOM only.");
|
|
1317
|
+
break;
|
|
1201
1318
|
case "nuxt": {
|
|
1202
1319
|
let cfg = first(p.cwd, ["nuxt.config.ts", "nuxt.config.js", "nuxt.config.mjs"]), base = nuxtBase(p.cwd), alias = `~/${relative(base, o.css).replaceAll("\\", "/")}`, block = [
|
|
1203
|
-
` css: ['${MARK}/foundation.css',${o.font !== "system" ? ` '@prismora/fonts/pairing-${o.font}',` : ""} '${alias}'],`,
|
|
1320
|
+
` css: ['${MARK}/foundation.css',${o.font !== "system" ? ` '@prismora/fonts/pairing-${o.font}.css',` : ""} '${alias}'],`,
|
|
1204
1321
|
" vue: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('pm-') } },",
|
|
1205
1322
|
` app: { head: { ${htmlAttrs(o).length ? `htmlAttrs: { ${htmlAttrs(o).map((a) => a === "mobile" ? "mobile: ''" : `'data-mode': '${o.mode}'`).join(", ")} }, ` : ""}script: [{ innerHTML: noFlashScript, tagPosition: 'head' }] } },`
|
|
1206
1323
|
], src = cfg ? read(cfg) : "";
|
|
@@ -1236,7 +1353,7 @@ ${lines.map((l) => ` ${l}`).join(`
|
|
|
1236
1353
|
break;
|
|
1237
1354
|
}
|
|
1238
1355
|
case "astro": {
|
|
1239
|
-
let layout = first(p.cwd, ["src/layouts/Layout.astro", "src/layouts/BaseLayout.astro", "src/layouts/Base.astro"]), lines = [...cssImports(layout ?? "src/layouts/Layout.astro"), "import { noFlashScript } from '@prismora/theme';"], headLines = ["<script is:inline data-prismora set:html={noFlashScript}></script>", "<script>import '@prismora/elements/define';</script>"];
|
|
1356
|
+
let page = first(p.cwd, ["src/pages/index.astro"]), layout = first(p.cwd, ["src/layouts/Layout.astro", "src/layouts/BaseLayout.astro", "src/layouts/Base.astro"]) ?? (page && /<head[\s>]/i.test(read(page)) ? page : void 0), lines = [...cssImports(layout ?? "src/layouts/Layout.astro"), "import { noFlashScript } from '@prismora/theme';"], headLines = ["<script is:inline data-prismora set:html={noFlashScript}></script>", "<script>import '@prismora/elements/define';</script>"];
|
|
1240
1357
|
if (layout && !read(layout).includes(MARK)) {
|
|
1241
1358
|
let src = read(layout);
|
|
1242
1359
|
src = /^---\n/.test(src) ? src.replace(/^---\n/, `---
|
|
@@ -1250,7 +1367,8 @@ ${src}`;
|
|
|
1250
1367
|
let next = patchHtml(src.replace(/<head[^>]*>/i, (h) => `${h}
|
|
1251
1368
|
${headLines.join(`
|
|
1252
1369
|
`)}`), o);
|
|
1253
|
-
edit(layout, next ?? src, "Prismora styles, elements and no-flash script")
|
|
1370
|
+
if (edit(layout, next ?? src, "Prismora styles, elements and no-flash script"), layout === page)
|
|
1371
|
+
manual("Added to src/pages/index.astro (there is no layout yet). When you add pages, move these lines into a shared layout.");
|
|
1254
1372
|
} else if (!layout)
|
|
1255
1373
|
manual("Add to your base layout (frontmatter, then <head>):", [...lines, "---", ...headLines].join(`
|
|
1256
1374
|
`));
|
|
@@ -1258,7 +1376,7 @@ ${src}`;
|
|
|
1258
1376
|
break;
|
|
1259
1377
|
}
|
|
1260
1378
|
case "angular": {
|
|
1261
|
-
let styles = first(p.cwd, ["src/styles.css", "src/styles.scss", "src/styles.sass", "src/styles.less"]), lines = [`@import '${MARK}/foundation.css';`, ...o.font !== "system" ? [`@import '@prismora/fonts/pairing-${o.font}';`] : [], `@import '${rel(styles ?? "src/styles.css", o.css)}';`];
|
|
1379
|
+
let styles = first(p.cwd, ["src/styles.css", "src/styles.scss", "src/styles.sass", "src/styles.less"]), lines = [`@import '${MARK}/foundation.css';`, ...o.font !== "system" ? [`@import '@prismora/fonts/pairing-${o.font}.css';`] : [], `@import '${rel(styles ?? "src/styles.css", o.css)}';`];
|
|
1262
1380
|
if (styles) {
|
|
1263
1381
|
if (!read(styles).includes(MARK))
|
|
1264
1382
|
edit(styles, `${lines.join(`
|
|
@@ -1277,6 +1395,10 @@ ${read(styles)}`, "Prismora styles");
|
|
|
1277
1395
|
break;
|
|
1278
1396
|
}
|
|
1279
1397
|
case "html": {
|
|
1398
|
+
if (hasBundler(p) && first(p.cwd, viteEntries(["main", "index"]))) {
|
|
1399
|
+
entry(viteEntries(["main", "index"]), ["import '@prismora/elements/define';"]), viteHtml(), manual("@prismora/elements/define registers every element; for smaller bundles import single elements (e.g. @prismora/elements/button).");
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1280
1402
|
let f = first(p.cwd, ["index.html", "public/index.html"]), at = f ?? "index.html", nm = (path) => rel(at, `node_modules/${path}`), head = [
|
|
1281
1403
|
`<link rel="stylesheet" href="${nm("@prismora/css/dist/prismora.css")}">`,
|
|
1282
1404
|
`<link rel="stylesheet" href="${rel(at, o.css)}">`,
|
|
@@ -1342,8 +1464,8 @@ function apply(p, changes) {
|
|
|
1342
1464
|
mkdirSync(dirname(path), { recursive: !0 }), writeFileSync(path, c.content);
|
|
1343
1465
|
}
|
|
1344
1466
|
}
|
|
1345
|
-
function install(p, packages) {
|
|
1346
|
-
let [cmd, ...args] = installCommand(p.pm).split(" ");
|
|
1467
|
+
function install(p, packages, dev = !1) {
|
|
1468
|
+
let [cmd, ...args] = (dev ? devInstallCommand(p.pm) : installCommand(p.pm)).split(" ");
|
|
1347
1469
|
return spawnSync(cmd, [...args, ...packages], { cwd: p.cwd, stdio: "inherit", shell: process.platform === "win32" }).status === 0;
|
|
1348
1470
|
}
|
|
1349
1471
|
|
|
@@ -17194,12 +17316,15 @@ for (let c of COMPONENTS) {
|
|
|
17194
17316
|
}
|
|
17195
17317
|
var moduleFor = (tag) => MODULES.get(tag), attrType = (tag, attr) => ATTR_TYPES.get(`${tag}|${attr}`);
|
|
17196
17318
|
function reactStyle(css) {
|
|
17197
|
-
|
|
17319
|
+
let parts = css.split(";").map((d) => d.trim()).filter(Boolean).map((d) => {
|
|
17198
17320
|
let i = d.indexOf(":"), prop = d.slice(0, i).trim(), val = d.slice(i + 1).trim().replace(/'/g, "\\'");
|
|
17199
17321
|
return `${prop.startsWith("--") ? `'${prop}'` : prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase())}: '${val}'`;
|
|
17200
|
-
})
|
|
17322
|
+
});
|
|
17323
|
+
if (parts.some((p) => p.startsWith("'--")))
|
|
17324
|
+
return usesCssProperties = !0, `{{ ${parts.join(", ")} } as CSSProperties}`;
|
|
17325
|
+
return `{{ ${parts.join(", ")} }}`;
|
|
17201
17326
|
}
|
|
17202
|
-
var FRAMEWORKS = ["html", "react", "vue", "svelte", "solid", "angular"], IMG = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 90'%3E%3Cdefs%3E%3ClinearGradient id='g' x2='1' y2='1'%3E%3Cstop stop-color='%237c5cff'/%3E%3Cstop offset='1' stop-color='%23ff7ab6'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='160' height='90' fill='url(%23g)'/%3E%3Ccircle cx='118' cy='30' r='14' fill='%23fff' opacity='.85'/%3E%3Cpath d='M0 90l45-48 30 30 22-18 63 36z' fill='%23fff' opacity='.35'/%3E%3C/svg%3E", ICONS = ["plus", "check", "arrow-right", "download", "trash", "settings", "star", "search"], STATUS_ICONS = ["info", "check-circle", "alert-triangle", "bell", "sparkles"], CATALOG = [
|
|
17327
|
+
var usesCssProperties = !1, FRAMEWORKS = ["html", "react", "vue", "svelte", "solid", "angular"], IMG = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 90'%3E%3Cdefs%3E%3ClinearGradient id='g' x2='1' y2='1'%3E%3Cstop stop-color='%237c5cff'/%3E%3Cstop offset='1' stop-color='%23ff7ab6'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='160' height='90' fill='url(%23g)'/%3E%3Ccircle cx='118' cy='30' r='14' fill='%23fff' opacity='.85'/%3E%3Cpath d='M0 90l45-48 30 30 22-18 63 36z' fill='%23fff' opacity='.35'/%3E%3C/svg%3E", ICONS = ["plus", "check", "arrow-right", "download", "trash", "settings", "star", "search"], STATUS_ICONS = ["info", "check-circle", "alert-triangle", "bell", "sparkles"], CATALOG = [
|
|
17203
17328
|
{
|
|
17204
17329
|
tag: "pm-button",
|
|
17205
17330
|
category: "Actions",
|
|
@@ -18186,6 +18311,10 @@ function render(nodes, fw, depth = 0) {
|
|
|
18186
18311
|
if (typeof n === "string")
|
|
18187
18312
|
return pad + text(n);
|
|
18188
18313
|
let wrap = n.tag.startsWith("pm-") && fw !== "html" && fw !== "solid" && fw !== "angular", name = wrap ? pascalName(n.tag) : n.tag, attrs = n.attrs.map(([k, v]) => {
|
|
18314
|
+
if (typeof v === "string" && wrap && !isJson(v) && attrType(n.tag, k) === "json" && v.includes(",")) {
|
|
18315
|
+
let items = v.split(",").map((x) => x.trim());
|
|
18316
|
+
v = JSON.stringify(items.every((x) => x !== "" && !Number.isNaN(Number(x))) ? items.map(Number) : items);
|
|
18317
|
+
}
|
|
18189
18318
|
if (typeof v === "string" && isJson(v) && n.tag.startsWith("pm-")) {
|
|
18190
18319
|
if (fw === "react" || fw === "svelte" && wrap)
|
|
18191
18320
|
return `${camel(k)}={${v}}`;
|
|
@@ -18193,6 +18322,8 @@ function render(nodes, fw, depth = 0) {
|
|
|
18193
18322
|
return `:${k}='${v}'`;
|
|
18194
18323
|
return `${k}='${v}'`;
|
|
18195
18324
|
}
|
|
18325
|
+
if ((fw === "react" || fw === "solid") && k === "popover" && (v === !0 || v === ""))
|
|
18326
|
+
v = "auto";
|
|
18196
18327
|
if (fw === "react") {
|
|
18197
18328
|
let key = k === "class" ? "className" : k === "for" && !wrap ? "htmlFor" : wrap ? propName(k) : k;
|
|
18198
18329
|
if (v === !0)
|
|
@@ -18249,6 +18380,20 @@ ${pad}</${name}>`;
|
|
|
18249
18380
|
}).join(`
|
|
18250
18381
|
`);
|
|
18251
18382
|
}
|
|
18383
|
+
function usedIcons(nodes, acc = /* @__PURE__ */ new Set) {
|
|
18384
|
+
for (let n of nodes) {
|
|
18385
|
+
if (typeof n === "string")
|
|
18386
|
+
continue;
|
|
18387
|
+
for (let [k, v] of n.attrs) {
|
|
18388
|
+
if (typeof v !== "string" || !/^[a-z0-9-]+$/.test(v))
|
|
18389
|
+
continue;
|
|
18390
|
+
if (n.tag === "pm-icon" && k === "name" || n.tag.startsWith("pm-") && ["icon", "icon-start", "icon-end"].includes(k))
|
|
18391
|
+
acc.add(v);
|
|
18392
|
+
}
|
|
18393
|
+
usedIcons(n.children, acc);
|
|
18394
|
+
}
|
|
18395
|
+
return acc;
|
|
18396
|
+
}
|
|
18252
18397
|
function usedTags(nodes, acc = /* @__PURE__ */ new Set) {
|
|
18253
18398
|
for (let n of nodes) {
|
|
18254
18399
|
if (typeof n === "string")
|
|
@@ -18260,19 +18405,24 @@ function usedTags(nodes, acc = /* @__PURE__ */ new Set) {
|
|
|
18260
18405
|
return acc;
|
|
18261
18406
|
}
|
|
18262
18407
|
function snippet(html, fw, name = "Demo") {
|
|
18263
|
-
let nodes = parse(html)
|
|
18408
|
+
let nodes = parse(html);
|
|
18409
|
+
usesCssProperties = !1;
|
|
18410
|
+
let body = render(nodes, fw), iconNames = [...usedIcons(nodes)].sort().map(camel), iconImports = iconNames.length ? ["import { registerIcons } from '@prismora/elements/icon';", `import { ${iconNames.join(", ")} } from '@prismora/icons';`] : [], iconCall = iconNames.length ? `registerIcons([${iconNames.join(", ")}]);` : "", iconBlock = (indent = "") => iconNames.length ? `${[...iconImports, "", iconCall].map((l) => l ? indent + l : l).join(`
|
|
18411
|
+
`)}
|
|
18412
|
+
` : "", tags = [...usedTags(nodes)], names = [...new Set(tags.map(pascalName))].sort().join(", "), imports = [...new Set(tags.map((t) => moduleFor(t) ?? "@prismora/elements/define"))].sort().map((m) => `import '${m}';`);
|
|
18264
18413
|
switch (fw) {
|
|
18265
18414
|
case "html":
|
|
18266
|
-
return `<
|
|
18267
|
-
|
|
18415
|
+
return `<script type="module">
|
|
18416
|
+
import '@prismora/css';
|
|
18268
18417
|
${imports.join(`
|
|
18269
18418
|
`)}
|
|
18270
|
-
</script>
|
|
18419
|
+
${iconBlock(" ")}</script>
|
|
18271
18420
|
|
|
18272
18421
|
${body}`;
|
|
18273
18422
|
case "react":
|
|
18274
|
-
return `import
|
|
18275
|
-
|
|
18423
|
+
return `${usesCssProperties ? `import type { CSSProperties } from 'react';
|
|
18424
|
+
` : ""}import { ${names} } from '@prismora/react';
|
|
18425
|
+
${iconBlock()}
|
|
18276
18426
|
export default function ${name}() {
|
|
18277
18427
|
return (
|
|
18278
18428
|
<>
|
|
@@ -18285,7 +18435,7 @@ ${body.split(`
|
|
|
18285
18435
|
case "vue":
|
|
18286
18436
|
return `<script setup lang="ts">
|
|
18287
18437
|
import { ${names} } from '@prismora/vue';
|
|
18288
|
-
</script>
|
|
18438
|
+
${iconBlock()}</script>
|
|
18289
18439
|
|
|
18290
18440
|
<template>
|
|
18291
18441
|
${body.split(`
|
|
@@ -18295,7 +18445,7 @@ ${body.split(`
|
|
|
18295
18445
|
case "svelte":
|
|
18296
18446
|
return `<script lang="ts">
|
|
18297
18447
|
import { ${names} } from '@prismora/svelte';
|
|
18298
|
-
</script>
|
|
18448
|
+
${iconBlock(" ")}</script>
|
|
18299
18449
|
|
|
18300
18450
|
${body}`;
|
|
18301
18451
|
case "angular": {
|
|
@@ -18305,7 +18455,7 @@ ${body}`;
|
|
|
18305
18455
|
return `import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
|
|
18306
18456
|
${imports.join(`
|
|
18307
18457
|
`)}
|
|
18308
|
-
|
|
18458
|
+
${iconBlock()}
|
|
18309
18459
|
@Component({
|
|
18310
18460
|
selector: 'app-${selector}',
|
|
18311
18461
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
@@ -18319,7 +18469,7 @@ export class ${name}Component {}`;
|
|
|
18319
18469
|
return `import type {} from '@prismora/solid'; // JSX typings
|
|
18320
18470
|
${imports.join(`
|
|
18321
18471
|
`)}
|
|
18322
|
-
|
|
18472
|
+
${iconBlock()}
|
|
18323
18473
|
export default function ${name}() {
|
|
18324
18474
|
return (
|
|
18325
18475
|
<>
|
|
@@ -19991,7 +20141,7 @@ function getComponent(name, framework = "html") {
|
|
|
19991
20141
|
docs: `${SITE}/components/${(entry?.childOf ?? c.tag).slice(3)}`,
|
|
19992
20142
|
framework,
|
|
19993
20143
|
example: demo ? snippet(demo, framework) : void 0,
|
|
19994
|
-
events: c.events.map((e) => ({ ...e, prop: framework === "react" || framework === "svelte" ? `on${e.name.split("-").map((p) => p[0].toUpperCase() + p.slice(1)).join("")}` : framework === "solid" ? `on
|
|
20144
|
+
events: c.events.map((e) => ({ ...e, prop: framework === "react" || framework === "svelte" ? `on${e.name.split("-").map((p) => p[0].toUpperCase() + p.slice(1)).join("")}` : framework === "solid" ? `on${e.name[0].toUpperCase()}${e.name.slice(1)}` : framework === "angular" ? `(${e.name})` : framework === "vue" ? `@${e.name}` : e.name }))
|
|
19995
20145
|
};
|
|
19996
20146
|
}
|
|
19997
20147
|
var CATEGORY_RULES = [
|
|
@@ -20319,8 +20469,19 @@ async function stripTypes(code, file) {
|
|
|
20319
20469
|
if (bun)
|
|
20320
20470
|
return new bun.Transpiler({ loader: "ts" }).transformSync(code);
|
|
20321
20471
|
let mod = await import("node:module");
|
|
20322
|
-
if (mod.stripTypeScriptTypes)
|
|
20323
|
-
|
|
20472
|
+
if (mod.stripTypeScriptTypes) {
|
|
20473
|
+
let emit = process.emitWarning;
|
|
20474
|
+
process.emitWarning = (w, ...rest) => {
|
|
20475
|
+
if (String(w?.message ?? w).includes("stripTypeScriptTypes"))
|
|
20476
|
+
return;
|
|
20477
|
+
emit.call(process, w, ...rest);
|
|
20478
|
+
};
|
|
20479
|
+
try {
|
|
20480
|
+
return mod.stripTypeScriptTypes(code);
|
|
20481
|
+
} finally {
|
|
20482
|
+
process.emitWarning = emit;
|
|
20483
|
+
}
|
|
20484
|
+
}
|
|
20324
20485
|
throw new CliError(`Reading ${file} needs Node 22.13+ (or Bun). Use prismora.theme.mjs or .json on older Node.`);
|
|
20325
20486
|
}
|
|
20326
20487
|
async function loadConfig(file) {
|
|
@@ -20445,9 +20606,13 @@ ${describeChanges(changes)}
|
|
|
20445
20606
|
if (apply(p, changes), o.install && p.hasPkg) {
|
|
20446
20607
|
if (info(`$ ${installCommand(p.pm)} ${packages.join(" ")}`), installed = install(p, packages), !installed)
|
|
20447
20608
|
throw new CliError(`Files are written, but the install failed. Run: ${installCommand(p.pm)} ${packages.join(" ")}`);
|
|
20609
|
+
if (!(CLI_PACKAGE in p.deps)) {
|
|
20610
|
+
if (info(`$ ${devInstallCommand(p.pm)} ${CLI_PACKAGE}`), !install(p, [CLI_PACKAGE], !0))
|
|
20611
|
+
throw new CliError(`Packages are installed, but adding the CLI failed. Run: ${devInstallCommand(p.pm)} ${CLI_PACKAGE}`);
|
|
20612
|
+
}
|
|
20448
20613
|
}
|
|
20449
20614
|
}
|
|
20450
|
-
let k = KINDS[o.kind], config = changes.find((c) => c.type === "create" && /prismora\.theme\.m?[jt]s$/.test(c.file));
|
|
20615
|
+
let k = KINDS[o.kind], run = runCommand(p.pm), config = changes.find((c) => c.type === "create" && /prismora\.theme\.m?[jt]s$/.test(c.file));
|
|
20451
20616
|
emit({
|
|
20452
20617
|
framework: o.kind,
|
|
20453
20618
|
options: o,
|
|
@@ -20459,13 +20624,14 @@ ${describeChanges(changes)}
|
|
|
20459
20624
|
}, () => [
|
|
20460
20625
|
flags["dry-run"] ? "Dry run: nothing was written." : `✓ Prismora is set up for ${k.label}.`,
|
|
20461
20626
|
installed ? "" : `
|
|
20462
|
-
Install: ${installCommand(p.pm)} ${packages.join(" ")}
|
|
20627
|
+
Install: ${installCommand(p.pm)} ${packages.join(" ")}
|
|
20628
|
+
${devInstallCommand(p.pm)} ${CLI_PACKAGE}`,
|
|
20463
20629
|
`
|
|
20464
20630
|
Next:`,
|
|
20465
|
-
` • Use components: ${k.wrapper && k.fw !== "html" ? `import { Button } from '${k.wrapper}'` : '<pm-button variant="soft">Save</pm-button>'}`,
|
|
20466
|
-
|
|
20467
|
-
` • Change the theme: edit ${config && config.type !== "manual" ? config.file : configPath()}, then prismora theme build`,
|
|
20468
|
-
` • Check the setup any time: prismora doctor · ${SITE}/docs/frameworks`
|
|
20631
|
+
` • Use components: ${k.wrapper && k.fw !== "html" && k.fw !== "solid" ? `import { Button } from '${k.wrapper}'` : '<pm-button variant="soft">Save</pm-button>'}`,
|
|
20632
|
+
` • Start from a template: ${run} prismora add dashboard --write (list: ${run} prismora list patterns)`,
|
|
20633
|
+
` • Change the theme: edit ${config && config.type !== "manual" ? config.file : configPath()}, then ${run} prismora theme build`,
|
|
20634
|
+
` • Check the setup any time: ${run} prismora doctor · ${SITE}/docs/frameworks`
|
|
20469
20635
|
].filter(Boolean).join(`
|
|
20470
20636
|
`));
|
|
20471
20637
|
} finally {
|
|
@@ -20513,6 +20679,10 @@ async function theme(sub, args) {
|
|
|
20513
20679
|
throw new CliError("Usage: prismora theme <generate|build|import|export>");
|
|
20514
20680
|
}
|
|
20515
20681
|
}
|
|
20682
|
+
var rel2 = (fromFile, toFile) => {
|
|
20683
|
+
let r = relative2(dirname2(resolve2(fromFile)), resolve2(toFile)).replaceAll("\\", "/");
|
|
20684
|
+
return r.startsWith(".") ? r : `./${r}`;
|
|
20685
|
+
}, toPascal = (s) => s.replace(/(^|-)(\w)/g, (_, __, c) => c.toUpperCase());
|
|
20516
20686
|
function addCmd(name) {
|
|
20517
20687
|
if (!name)
|
|
20518
20688
|
throw new CliError("Usage: prismora add <component|pattern>");
|
|
@@ -20524,12 +20694,17 @@ function addCmd(name) {
|
|
|
20524
20694
|
if (flags.json)
|
|
20525
20695
|
return emit(p, () => "");
|
|
20526
20696
|
info(`${p.title} (${fw}) — ${p.description}
|
|
20527
|
-
${p.setup}
|
|
20528
|
-
`);
|
|
20697
|
+
${s.framework ? "" : `${p.setup}
|
|
20698
|
+
`}`);
|
|
20529
20699
|
let file = flags.out;
|
|
20530
20700
|
if (!file && flags.write) {
|
|
20531
|
-
let pascal = name
|
|
20532
|
-
next: join2(dir, name, "page.tsx"),
|
|
20701
|
+
let pascal = toPascal(name), dir = s.pages ?? "src/pages", byKind = {
|
|
20702
|
+
next: /(^|\/)pages$/.test(dir) ? join2(dir, `${name}.tsx`) : join2(dir, name, "page.tsx"),
|
|
20703
|
+
"react-router": join2(dir, `${name}.tsx`),
|
|
20704
|
+
"tanstack-start": join2(dir, `${name}.tsx`),
|
|
20705
|
+
"solid-start": join2(dir, `${name}.tsx`),
|
|
20706
|
+
preact: join2(dir, `${pascal}.tsx`),
|
|
20707
|
+
lit: join2(dir, `${name}.html`),
|
|
20533
20708
|
sveltekit: join2(dir, name, "+page.svelte"),
|
|
20534
20709
|
nuxt: join2(dir, `${name}.vue`),
|
|
20535
20710
|
react: join2(dir, `${pascal}.tsx`),
|
|
@@ -20543,6 +20718,49 @@ ${p.setup}
|
|
|
20543
20718
|
if (file = KINDS[kind].fw === fw ? byKind[kind] : join2(dir, `${pascal}.${ext}`), file && existsSync2(file))
|
|
20544
20719
|
throw new CliError(`${file} already exists; pass -o <file> to choose another path.`);
|
|
20545
20720
|
}
|
|
20721
|
+
if (file && fw === "html" && file.endsWith(".html")) {
|
|
20722
|
+
let index = ["index.html", "public/index.html"].map((f) => resolve2(f)).find((f) => existsSync2(f)), head = index ? readFileSync2(index, "utf8").match(/<head[^>]*>[\s\S]*?<\/head>/i)?.[0] : void 0, title = `<title>${p.title}</title>`, docHead = head ? head.replace(/<title>[\s\S]*?<\/title>/i, title).replace(/\s*<script type="module" src="\/?src\/[^"]*"><\/script>/gi, "") : `<head>
|
|
20723
|
+
<meta charset="utf-8" />
|
|
20724
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
20725
|
+
${title}
|
|
20726
|
+
</head>`, themeCss = s.css && !docHead.includes(basename(s.css)) ? rel2(file, s.css) : void 0, code = themeCss ? p.code.replace(` import '@prismora/css';
|
|
20727
|
+
`, ` import '@prismora/css';
|
|
20728
|
+
import '${themeCss}';
|
|
20729
|
+
`) : p.code;
|
|
20730
|
+
return writeOrPrint(`<!doctype html>
|
|
20731
|
+
<html lang="en">
|
|
20732
|
+
${docHead}
|
|
20733
|
+
<body>
|
|
20734
|
+
${code}
|
|
20735
|
+
</body>
|
|
20736
|
+
</html>
|
|
20737
|
+
`, file);
|
|
20738
|
+
}
|
|
20739
|
+
if (file && KINDS[kind].fw === fw && kind === "next" && file.endsWith("page.tsx") && p.code.includes("registerIcons(") && !p.code.startsWith("'use client'"))
|
|
20740
|
+
return writeOrPrint(`'use client';
|
|
20741
|
+
|
|
20742
|
+
${p.code}`, file);
|
|
20743
|
+
if (file && KINDS[kind].fw === fw && kind === "tanstack-start")
|
|
20744
|
+
return writeOrPrint(`${p.code}
|
|
20745
|
+
|
|
20746
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
20747
|
+
export const Route = createFileRoute('/${name}')({ component: ${p.code.match(/export default function (\w+)/)?.[1] ?? toPascal(name)} });
|
|
20748
|
+
`, file);
|
|
20749
|
+
if (file && KINDS[kind].fw === fw && kind === "react-router") {
|
|
20750
|
+
writeOrPrint(p.code, file);
|
|
20751
|
+
let routes = ["app/routes.ts", "app/routes.js"].find((f) => existsSync2(f)), src = routes ? readFileSync2(routes, "utf8") : "", entry = `route('${name}', 'routes/${name}.tsx')`;
|
|
20752
|
+
if (routes && !src.includes(`routes/${name}.tsx`) && /\]\s*satisfies\s+RouteConfig/.test(src)) {
|
|
20753
|
+
let next = src.replace(/\n?\]\s*satisfies\s+RouteConfig/, (m) => `,
|
|
20754
|
+
${entry},${m.startsWith(`
|
|
20755
|
+
`) ? m : `
|
|
20756
|
+
${m}`}`).replace(/,\s*,/, ",");
|
|
20757
|
+
next = next.replace(/import\s*\{([^}]*)\}\s*from\s*['"]@react-router\/dev\/routes['"]/, (all, names) => /\broute\b/.test(names) ? all : all.replace(names, `${names.trimEnd()}, route `)), writeFileSync2(routes, next), info(`Registered /${name} in ${routes}.`);
|
|
20758
|
+
} else if (!src.includes(`routes/${name}.tsx`))
|
|
20759
|
+
info(`Add ${entry} to app/routes.ts.`);
|
|
20760
|
+
return;
|
|
20761
|
+
}
|
|
20762
|
+
if (file && kind === "qwik")
|
|
20763
|
+
info("Qwik: put the markup in a component$ route (src/routes/<name>/index.tsx); the elements work as plain tags there.");
|
|
20546
20764
|
return writeOrPrint(p.code, file);
|
|
20547
20765
|
}
|
|
20548
20766
|
let c = getComponent(name, fw);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismora/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Prismora CLI: interactive init for every framework, theme generate/build/import/export, add components and templates, validate, doctor. Ships as one self-contained file.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prismora",
|