@raybase/cli 0.0.2 → 0.3.4
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/LICENSE +21 -0
- package/dist/admin-assets.d.ts +22 -0
- package/dist/admin-assets.d.ts.map +1 -0
- package/dist/admin-assets.js +285 -0
- package/dist/admin-assets.js.map +1 -0
- package/dist/agent-remote-mcp-cli.d.ts +71 -0
- package/dist/agent-remote-mcp-cli.d.ts.map +1 -0
- package/dist/agent-remote-mcp-cli.js +466 -0
- package/dist/agent-remote-mcp-cli.js.map +1 -0
- package/dist/agent-skills-cli.d.ts +4 -0
- package/dist/agent-skills-cli.d.ts.map +1 -0
- package/dist/agent-skills-cli.js +144 -0
- package/dist/agent-skills-cli.js.map +1 -0
- package/dist/agent.d.ts +169 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +531 -0
- package/dist/agent.js.map +1 -0
- package/dist/app-manifest.d.ts +41 -0
- package/dist/app-manifest.d.ts.map +1 -0
- package/dist/app-manifest.js +294 -0
- package/dist/app-manifest.js.map +1 -0
- package/dist/dev-cron-backstop.d.ts +53 -0
- package/dist/dev-cron-backstop.d.ts.map +1 -0
- package/dist/dev-cron-backstop.js +364 -0
- package/dist/dev-cron-backstop.js.map +1 -0
- package/dist/dev-do-watchdog.d.ts +37 -0
- package/dist/dev-do-watchdog.d.ts.map +1 -0
- package/dist/dev-do-watchdog.js +75 -0
- package/dist/dev-do-watchdog.js.map +1 -0
- package/dist/dev-inference-tape.d.ts +35 -0
- package/dist/dev-inference-tape.d.ts.map +1 -0
- package/dist/dev-inference-tape.js +502 -0
- package/dist/dev-inference-tape.js.map +1 -0
- package/dist/dev-ports.d.ts +25 -0
- package/dist/dev-ports.d.ts.map +1 -0
- package/dist/dev-ports.js +84 -0
- package/dist/dev-ports.js.map +1 -0
- package/dist/dev-project-lock.d.ts +24 -0
- package/dist/dev-project-lock.d.ts.map +1 -0
- package/dist/dev-project-lock.js +307 -0
- package/dist/dev-project-lock.js.map +1 -0
- package/dist/env-files.d.ts +10 -0
- package/dist/env-files.d.ts.map +1 -0
- package/dist/env-files.js +108 -0
- package/dist/env-files.js.map +1 -0
- package/dist/external-json.d.ts +3 -0
- package/dist/external-json.d.ts.map +1 -0
- package/dist/external-json.js +21 -0
- package/dist/external-json.js.map +1 -0
- package/dist/frameworks.d.ts +67 -0
- package/dist/frameworks.d.ts.map +1 -0
- package/dist/frameworks.js +210 -0
- package/dist/frameworks.js.map +1 -0
- package/dist/guide-corpus-doctor.d.ts +24 -0
- package/dist/guide-corpus-doctor.d.ts.map +1 -0
- package/dist/guide-corpus-doctor.js +111 -0
- package/dist/guide-corpus-doctor.js.map +1 -0
- package/dist/hosting.d.ts +85 -0
- package/dist/hosting.d.ts.map +1 -0
- package/dist/hosting.js +136 -0
- package/dist/hosting.js.map +1 -0
- package/dist/index.d.ts +253 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11497 -0
- package/dist/index.js.map +1 -0
- package/dist/kit-doctor.d.ts +19 -0
- package/dist/kit-doctor.d.ts.map +1 -0
- package/dist/kit-doctor.js +255 -0
- package/dist/kit-doctor.js.map +1 -0
- package/dist/kit-install.d.ts +67 -0
- package/dist/kit-install.d.ts.map +1 -0
- package/dist/kit-install.js +409 -0
- package/dist/kit-install.js.map +1 -0
- package/dist/kit-manifest.d.ts +154 -0
- package/dist/kit-manifest.d.ts.map +1 -0
- package/dist/kit-manifest.js +252 -0
- package/dist/kit-manifest.js.map +1 -0
- package/dist/kit-registry.d.ts +42 -0
- package/dist/kit-registry.d.ts.map +1 -0
- package/dist/kit-registry.js +231 -0
- package/dist/kit-registry.js.map +1 -0
- package/dist/kit-spec.d.ts +37 -0
- package/dist/kit-spec.d.ts.map +1 -0
- package/dist/kit-spec.js +48 -0
- package/dist/kit-spec.js.map +1 -0
- package/dist/kit-state.d.ts +57 -0
- package/dist/kit-state.d.ts.map +1 -0
- package/dist/kit-state.js +31 -0
- package/dist/kit-state.js.map +1 -0
- package/dist/kits.d.ts +82 -0
- package/dist/kits.d.ts.map +1 -0
- package/dist/kits.js +255 -0
- package/dist/kits.js.map +1 -0
- package/dist/license-keys.d.ts +3 -0
- package/dist/license-keys.d.ts.map +1 -0
- package/dist/license-keys.js +10 -0
- package/dist/license-keys.js.map +1 -0
- package/dist/licensing.d.ts +269 -0
- package/dist/licensing.d.ts.map +1 -0
- package/dist/licensing.js +477 -0
- package/dist/licensing.js.map +1 -0
- package/dist/local-codex-relay.d.ts +19 -0
- package/dist/local-codex-relay.d.ts.map +1 -0
- package/dist/local-codex-relay.js +203 -0
- package/dist/local-codex-relay.js.map +1 -0
- package/dist/module-doctor.d.ts +35 -0
- package/dist/module-doctor.d.ts.map +1 -0
- package/dist/module-doctor.js +966 -0
- package/dist/module-doctor.js.map +1 -0
- package/dist/module-install.d.ts +71 -0
- package/dist/module-install.d.ts.map +1 -0
- package/dist/module-install.js +1133 -0
- package/dist/module-install.js.map +1 -0
- package/dist/module-manifest.d.ts +33 -0
- package/dist/module-manifest.d.ts.map +1 -0
- package/dist/module-manifest.js +301 -0
- package/dist/module-manifest.js.map +1 -0
- package/dist/module-state.d.ts +76 -0
- package/dist/module-state.d.ts.map +1 -0
- package/dist/module-state.js +162 -0
- package/dist/module-state.js.map +1 -0
- package/dist/modules.d.ts +52 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +110 -0
- package/dist/modules.js.map +1 -0
- package/dist/palette-check.d.ts +42 -0
- package/dist/palette-check.d.ts.map +1 -0
- package/dist/palette-check.js +217 -0
- package/dist/palette-check.js.map +1 -0
- package/dist/palette-compile.d.ts +30 -0
- package/dist/palette-compile.d.ts.map +1 -0
- package/dist/palette-compile.js +149 -0
- package/dist/palette-compile.js.map +1 -0
- package/dist/pm.d.ts +11 -0
- package/dist/pm.d.ts.map +1 -0
- package/dist/pm.js +30 -0
- package/dist/pm.js.map +1 -0
- package/dist/project-local-codex-relay.d.ts +11 -0
- package/dist/project-local-codex-relay.d.ts.map +1 -0
- package/dist/project-local-codex-relay.js +95 -0
- package/dist/project-local-codex-relay.js.map +1 -0
- package/dist/shared.d.ts +4 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +38 -0
- package/dist/shared.js.map +1 -0
- package/dist/shell-match.d.ts +29 -0
- package/dist/shell-match.d.ts.map +1 -0
- package/dist/shell-match.js +160 -0
- package/dist/shell-match.js.map +1 -0
- package/dist/template-doctor.d.ts +40 -0
- package/dist/template-doctor.d.ts.map +1 -0
- package/dist/template-doctor.js +722 -0
- package/dist/template-doctor.js.map +1 -0
- package/dist/template-install.d.ts +135 -0
- package/dist/template-install.d.ts.map +1 -0
- package/dist/template-install.js +1311 -0
- package/dist/template-install.js.map +1 -0
- package/dist/template-manifest.d.ts +328 -0
- package/dist/template-manifest.d.ts.map +1 -0
- package/dist/template-manifest.js +533 -0
- package/dist/template-manifest.js.map +1 -0
- package/dist/template-registry.d.ts +76 -0
- package/dist/template-registry.d.ts.map +1 -0
- package/dist/template-registry.js +365 -0
- package/dist/template-registry.js.map +1 -0
- package/dist/template-spec.d.ts +24 -0
- package/dist/template-spec.d.ts.map +1 -0
- package/dist/template-spec.js +38 -0
- package/dist/template-spec.js.map +1 -0
- package/dist/template-state.d.ts +108 -0
- package/dist/template-state.d.ts.map +1 -0
- package/dist/template-state.js +93 -0
- package/dist/template-state.js.map +1 -0
- package/dist/templates.d.ts +123 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +541 -0
- package/dist/templates.js.map +1 -0
- package/dist/theme-match.d.ts +41 -0
- package/dist/theme-match.d.ts.map +1 -0
- package/dist/theme-match.js +92 -0
- package/dist/theme-match.js.map +1 -0
- package/dist/wrangler-secrets.d.ts +15 -0
- package/dist/wrangler-secrets.d.ts.map +1 -0
- package/dist/wrangler-secrets.js +97 -0
- package/dist/wrangler-secrets.js.map +1 -0
- package/kits/datasheet-grid/file-manifest.json +65 -0
- package/kits/datasheet-grid/files/AGENTS.md +6 -0
- package/kits/datasheet-grid/files/docs/datasheet-grid.md +15 -0
- package/kits/datasheet-grid/files/files/src/kits/datasheet-grid/DatasheetGridRoute.tsx +35 -0
- package/kits/datasheet-grid/files/files/src/kits/datasheet-grid/README.md +10 -0
- package/kits/datasheet-grid/files/files/src/kits/datasheet-grid/grid-adapter.ts +30 -0
- package/kits/datasheet-grid/files/files/src/kits/datasheet-grid/grid-metadata.ts +19 -0
- package/kits/datasheet-grid/files/files/src/kits/datasheet-grid/grid-state.ts +24 -0
- package/kits/datasheet-grid/files/kit.json +119 -0
- package/kits/datasheet-grid/files/skills/datasheet-grid/SKILL.md +16 -0
- package/kits/datasheet-grid/files/tests/datasheet-grid.test.ts +15 -0
- package/kits/datasheet-grid/kit.json +146 -0
- package/kits/index.json +71 -0
- package/kits/resend-email/file-manifest.json +47 -0
- package/kits/resend-email/files/AGENTS.md +7 -0
- package/kits/resend-email/files/docs/resend-email.md +13 -0
- package/kits/resend-email/files/files/src/kits/resend-email/README.md +17 -0
- package/kits/resend-email/files/files/src/kits/resend-email/send-email.ts +44 -0
- package/kits/resend-email/files/kit.json +128 -0
- package/kits/resend-email/files/skills/resend-email/SKILL.md +20 -0
- package/kits/resend-email/files/tests/resend-email.test.ts +54 -0
- package/kits/resend-email/kit.json +159 -0
- package/modules/docs/templates/astro-emdash/content/docs/getting-started.mdx +13 -0
- package/modules/docs/templates/astro-emdash/content/docs/index.mdx +13 -0
- package/modules/docs/templates/astro-emdash/content/docs/mcp.mdx +11 -0
- package/modules/docs/templates/astro-emdash/content/docs/meta.json +4 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/getting-started.mdx +12 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/index.mdx +12 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/mcp.mdx +10 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/meta.json +4 -0
- package/modules/docs/templates/astro-emdash/site/source.config.ts +10 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/source.ts +7 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/[...slug].ts +6 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/api/markdown.ts +4 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/api/search.ts +4 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/llms.txt.ts +8 -0
- package/modules/docs/templates/astro-emdash/site/src/styles-docs.css +3 -0
- package/modules/docs/templates/astro-emdash/source.config.ts +10 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/astro-emdash/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/astro-emdash/src/docs/source.ts +7 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/$.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/api/markdown.ts +12 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/api/search.ts +12 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs.index.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/styles-docs.css +3 -0
- package/modules/docs/templates/react-router/app/components/mdx.tsx +79 -0
- package/modules/docs/templates/react-router/app/lib/layout.shared.tsx +54 -0
- package/modules/docs/templates/react-router/app/lib/source.ts +7 -0
- package/modules/docs/templates/react-router/app/routes/docs.$.tsx +49 -0
- package/modules/docs/templates/react-router/app/routes/docs.api.search.ts +10 -0
- package/modules/docs/templates/react-router/app/routes/docs.tsx +13 -0
- package/modules/docs/templates/react-router/content/docs/getting-started.mdx +8 -0
- package/modules/docs/templates/react-router/content/docs/index.mdx +8 -0
- package/modules/docs/templates/react-router/content/docs/mcp.mdx +121 -0
- package/modules/docs/templates/react-router/content/docs/meta.json +4 -0
- package/modules/docs/templates/react-router/source.config.ts +5 -0
- package/modules/docs/templates/tanstack-start/content/docs/getting-started.mdx +10 -0
- package/modules/docs/templates/tanstack-start/content/docs/index.mdx +8 -0
- package/modules/docs/templates/tanstack-start/content/docs/mcp.mdx +121 -0
- package/modules/docs/templates/tanstack-start/content/docs/meta.json +4 -0
- package/modules/docs/templates/tanstack-start/source.config.ts +10 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/tanstack-start/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/tanstack-start/src/docs/source.ts +7 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/$.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/api/markdown.ts +12 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/api/search.ts +12 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs.index.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/styles-docs.css +3 -0
- package/modules/guide/templates/astro-emdash/content/guide/capability-map.md +17 -0
- package/modules/guide/templates/astro-emdash/src/components/guide-widget.tsx +41 -0
- package/modules/guide/templates/astro-emdash/src/guide/actions.ts +8 -0
- package/modules/guide/templates/astro-emdash/src/guide/config.ts +21 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.manifest.json +72 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.ts +4 -0
- package/modules/guide/templates/astro-emdash/src/guide/resources.json +4 -0
- package/modules/guide/templates/react-router/app/components/guide-widget.tsx +29 -0
- package/modules/guide/templates/react-router/app/guide/actions.ts +3 -0
- package/modules/guide/templates/react-router/app/guide/config.ts +21 -0
- package/modules/guide/templates/react-router/app/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/react-router/app/guide/corpus.manifest.json +22 -0
- package/modules/guide/templates/react-router/app/guide/corpus.ts +4 -0
- package/modules/guide/templates/react-router/app/guide/resources.json +4 -0
- package/modules/guide/templates/react-router/content/guide/capability-map.md +13 -0
- package/modules/guide/templates/tanstack-start/content/guide/capability-map.md +17 -0
- package/modules/guide/templates/tanstack-start/src/components/guide-widget.tsx +41 -0
- package/modules/guide/templates/tanstack-start/src/guide/actions.ts +17 -0
- package/modules/guide/templates/tanstack-start/src/guide/config.ts +21 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.manifest.json +22 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.ts +4 -0
- package/modules/guide/templates/tanstack-start/src/guide/resources.json +4 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/astro-emdash/src/openai-subscription.ts +11 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/react-router/app/openai-subscription.ts +11 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/tanstack-start/src/openai-subscription.ts +11 -0
- package/package.json +34 -8
- package/README.md +0 -3
|
@@ -0,0 +1,1311 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { tsImport } from "tsx/esm/api";
|
|
5
|
+
import { assertNoSymlink, readJsonFile, resolveInside, satisfiesVersion, sha256Buffer, sha256File, sha256Integrity, stableJson } from "./template-manifest.js";
|
|
6
|
+
import { resolveTemplateSource, resolveThemeSource } from "./template-registry.js";
|
|
7
|
+
import { emptyTemplateLock, readTemplateLock, templatesLockPath, writeTemplateLock } from "./template-state.js";
|
|
8
|
+
const galleyPaletteModulePromises = new Map();
|
|
9
|
+
export async function installTemplate(projectRoot, options) {
|
|
10
|
+
if (options.framework !== "astro-emdash")
|
|
11
|
+
throw new Error("Templates are currently supported only in astro-emdash generated apps.");
|
|
12
|
+
return installTemplateSelections(projectRoot, [{ spec: options.spec, reason: "requested" }], options);
|
|
13
|
+
}
|
|
14
|
+
export async function installThemeSelection(projectRoot, options) {
|
|
15
|
+
if (options.framework !== "astro-emdash")
|
|
16
|
+
throw new Error("Template themes are currently supported only in astro-emdash generated apps.");
|
|
17
|
+
const theme = await resolveThemeSource(options.themeId, { registry: options.registry, offline: options.offline });
|
|
18
|
+
try {
|
|
19
|
+
const selected = selectPalette(theme, options.palette);
|
|
20
|
+
const pageRoutes = selectThemePageRoutes(theme.manifest, options);
|
|
21
|
+
const selections = selectThemeTemplates(theme.manifest, options, pageRoutes);
|
|
22
|
+
// Schema v3: theme add stages voice + vocabulary (palettes, sections, page
|
|
23
|
+
// starters) as drafts. Nav/footer/layout selection and activation moved to
|
|
24
|
+
// `shell add`, so a theme add never activates structure.
|
|
25
|
+
const result = await installTemplateSelections(projectRoot, [...selections.entries()].map(([spec, reasons]) => ({ spec, reason: [...reasons].join(",") || "theme" })), { ...options, spec: options.themeId }, { theme, selectedPalette: selected.name, selectedPaletteEntry: selected.palette, selections, pageRoutes, activateStructure: false });
|
|
26
|
+
return {
|
|
27
|
+
ok: true,
|
|
28
|
+
theme: theme.manifest.id,
|
|
29
|
+
version: theme.manifest.version,
|
|
30
|
+
selectedPalette: selected.name,
|
|
31
|
+
dryRun: Boolean(options.dryRun),
|
|
32
|
+
stageOnly: Boolean(options.stageOnly),
|
|
33
|
+
registry: theme.source.registry ?? null,
|
|
34
|
+
selectedTemplates: [...selections.entries()].map(([id, reasons]) => ({ id, reasons: [...reasons].sort() })),
|
|
35
|
+
install: result,
|
|
36
|
+
warnings: result.warnings,
|
|
37
|
+
nextSteps: result.nextSteps
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
theme.cleanup();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function installShellSelection(projectRoot, options) {
|
|
45
|
+
if (options.framework !== "astro-emdash")
|
|
46
|
+
throw new Error("Shells are currently supported only in astro-emdash generated apps.");
|
|
47
|
+
const resolvedLayout = await resolveTemplateSource(options.layoutId, { registry: options.registry, offline: options.offline, manifestOnly: true });
|
|
48
|
+
const manifest = resolvedLayout.manifest;
|
|
49
|
+
const registry = resolvedLayout.source.registry ?? null;
|
|
50
|
+
resolvedLayout.cleanup();
|
|
51
|
+
if (manifest.kind !== "layout") {
|
|
52
|
+
throw new Error(`${options.layoutId} is not a shell. Pass a layout template id (see raybase templates search --kind shell).`);
|
|
53
|
+
}
|
|
54
|
+
const existingLock = readTemplateLock(projectRoot);
|
|
55
|
+
const palette = resolveShellPalette(options.palette, existingLock, Boolean(options.activate));
|
|
56
|
+
const shellContext = {
|
|
57
|
+
layoutId: manifest.id,
|
|
58
|
+
nav: manifest.shell?.nav ?? null,
|
|
59
|
+
footer: manifest.shell?.footer ?? null,
|
|
60
|
+
activate: Boolean(options.activate),
|
|
61
|
+
palette,
|
|
62
|
+
provenance: {
|
|
63
|
+
shellId: manifest.id,
|
|
64
|
+
shellVersion: manifest.version,
|
|
65
|
+
registry,
|
|
66
|
+
generatedAt: new Date().toISOString()
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const install = await installTemplateSelections(projectRoot, [{ spec: options.layoutId, reason: "shell" }], { ...options, spec: options.layoutId }, undefined, shellContext);
|
|
70
|
+
// Activating a shell is the "go live" step: publish any page seeds the theme
|
|
71
|
+
// staged as drafts so the live site renders them inside the shell. apply
|
|
72
|
+
// reads each staged seed's `publish` flag, so flipping the files is enough.
|
|
73
|
+
const publishedPages = shellContext.activate && !options.dryRun ? publishStagedPageSeeds(projectRoot) : [];
|
|
74
|
+
return {
|
|
75
|
+
ok: true,
|
|
76
|
+
shell: manifest.id,
|
|
77
|
+
version: manifest.version,
|
|
78
|
+
nav: shellContext.nav,
|
|
79
|
+
footer: shellContext.footer,
|
|
80
|
+
palette,
|
|
81
|
+
activated: shellContext.activate,
|
|
82
|
+
publishedPages,
|
|
83
|
+
dryRun: Boolean(options.dryRun),
|
|
84
|
+
stageOnly: Boolean(options.stageOnly),
|
|
85
|
+
registry,
|
|
86
|
+
install,
|
|
87
|
+
warnings: install.warnings,
|
|
88
|
+
nextSteps: install.nextSteps
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function resolveShellPalette(requested, lock, activate) {
|
|
92
|
+
if (requested) {
|
|
93
|
+
const known = lock?.theme?.palettes ?? [];
|
|
94
|
+
if (known.length && !known.includes(requested)) {
|
|
95
|
+
throw new Error(`Palette ${requested} is not one of the staged theme palettes: ${known.join(", ")}.`);
|
|
96
|
+
}
|
|
97
|
+
return requested;
|
|
98
|
+
}
|
|
99
|
+
const fromTheme = lock?.theme?.selectedPalette ?? null;
|
|
100
|
+
if (fromTheme)
|
|
101
|
+
return fromTheme;
|
|
102
|
+
if (activate) {
|
|
103
|
+
throw new Error("Cannot activate a shell without a palette. Run raybase templates theme add <theme> --palette <name> first, or pass --palette <name>.");
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
function publishStagedPageSeeds(projectRoot) {
|
|
108
|
+
const lock = readTemplateLock(projectRoot);
|
|
109
|
+
if (!lock?.pages)
|
|
110
|
+
return [];
|
|
111
|
+
const published = [];
|
|
112
|
+
for (const page of Object.values(lock.pages)) {
|
|
113
|
+
if (page.publish)
|
|
114
|
+
continue;
|
|
115
|
+
const target = resolveInside(projectRoot, page.stagedArtifact);
|
|
116
|
+
if (!existsSync(target) || !statSync(target).isFile())
|
|
117
|
+
continue;
|
|
118
|
+
const seed = readJsonFile(target);
|
|
119
|
+
if (seed.publish === true)
|
|
120
|
+
continue;
|
|
121
|
+
const nextSeed = { ...seed, publish: true };
|
|
122
|
+
const serialized = stableJson(nextSeed);
|
|
123
|
+
writeProjectFile(projectRoot, page.stagedArtifact, serialized);
|
|
124
|
+
page.publish = true;
|
|
125
|
+
page.seedSha256 = sha256Buffer(serialized);
|
|
126
|
+
published.push(page.slug);
|
|
127
|
+
}
|
|
128
|
+
if (published.length)
|
|
129
|
+
writeTemplateLock(projectRoot, lock);
|
|
130
|
+
return published;
|
|
131
|
+
}
|
|
132
|
+
// Re-stages only the activation work order for the already-installed shell.
|
|
133
|
+
// `shell add --activate` restages the layout and its welded nav/footer from
|
|
134
|
+
// the registry, which resets locally edited partials — after templates:apply
|
|
135
|
+
// has consumed activation.json, re-activation must not pay that price.
|
|
136
|
+
export function activateInstalledShell(projectRoot, options) {
|
|
137
|
+
const lock = readTemplateLock(projectRoot);
|
|
138
|
+
const installed = lock?.shell ?? null;
|
|
139
|
+
if (options.layoutId && installed && options.layoutId !== installed.id) {
|
|
140
|
+
throw new Error(`The installed shell is ${installed.id}, not ${options.layoutId}. To switch shells run raybase templates shell add ${options.layoutId} --activate.`);
|
|
141
|
+
}
|
|
142
|
+
const layoutId = options.layoutId ?? installed?.id;
|
|
143
|
+
if (!layoutId)
|
|
144
|
+
throw new Error("No installed shell to activate. Run raybase templates shell add <layout-id> --activate first.");
|
|
145
|
+
const stagedDir = resolveInside(projectRoot, `site/seed/templates/${layoutId}`);
|
|
146
|
+
if (!existsSync(stagedDir)) {
|
|
147
|
+
throw new Error(`Shell ${layoutId} has no staged artifacts under site/seed/templates/. Run raybase templates shell add ${layoutId} --activate instead.`);
|
|
148
|
+
}
|
|
149
|
+
const palette = resolveShellPalette(options.palette, lock, true);
|
|
150
|
+
if (!palette)
|
|
151
|
+
throw new Error("Cannot activate a shell without a palette. Pass --palette <name>.");
|
|
152
|
+
const activationFile = `site/seed/templates/${layoutId}/activation.json`;
|
|
153
|
+
writeProjectFile(projectRoot, activationFile, stableJson({ activate: true, palette }));
|
|
154
|
+
const publishedPages = publishStagedPageSeeds(projectRoot);
|
|
155
|
+
// publishStagedPageSeeds may have rewritten the lock; reread before stamping.
|
|
156
|
+
const nextLock = readTemplateLock(projectRoot);
|
|
157
|
+
if (nextLock?.shell) {
|
|
158
|
+
nextLock.shell.activated = true;
|
|
159
|
+
nextLock.shell.palette = palette;
|
|
160
|
+
writeTemplateLock(projectRoot, nextLock);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
ok: true,
|
|
164
|
+
shell: layoutId,
|
|
165
|
+
palette,
|
|
166
|
+
activationFile,
|
|
167
|
+
publishedPages,
|
|
168
|
+
warnings: [],
|
|
169
|
+
nextSteps: [
|
|
170
|
+
"Apply with the Astro/EmDash site running: pnpm --dir site run templates:apply. It publishes staged templates, sets the layout pointer, and consumes activation.json."
|
|
171
|
+
]
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async function installTemplateSelections(projectRoot, selections, options, themeContext, shellContext) {
|
|
175
|
+
const resolved = await resolveInstallGraph(selections, options);
|
|
176
|
+
try {
|
|
177
|
+
const prepared = resolved.map((item) => prepareTemplate(item.resolved, {
|
|
178
|
+
dependency: item.dependency,
|
|
179
|
+
cliVersion: options.cliVersion,
|
|
180
|
+
framework: options.framework,
|
|
181
|
+
bindings: options.bindings ?? {},
|
|
182
|
+
reasons: item.reasons,
|
|
183
|
+
themeContext
|
|
184
|
+
}));
|
|
185
|
+
validateUnusedBindings(prepared, options.bindings ?? {});
|
|
186
|
+
if (!prepared.length)
|
|
187
|
+
throw new Error("No Templates were selected for installation.");
|
|
188
|
+
const lock = readTemplateLock(projectRoot) ?? emptyTemplateLock();
|
|
189
|
+
const plan = [];
|
|
190
|
+
const conflicts = [];
|
|
191
|
+
for (const template of prepared)
|
|
192
|
+
planStageTemplate(projectRoot, template, lock, options, plan, conflicts);
|
|
193
|
+
if (conflicts.length)
|
|
194
|
+
throw new Error(`Template install has conflicts:\n${conflicts.map((conflict) => `- ${conflict}`).join("\n")}`);
|
|
195
|
+
const activation = buildActivationIntent(prepared, themeContext, shellContext);
|
|
196
|
+
const themeGeneratedFiles = themeContext ? await buildThemeGeneratedFiles(projectRoot, themeContext) : null;
|
|
197
|
+
if (themeGeneratedFiles)
|
|
198
|
+
planThemeGeneratedFiles(projectRoot, themeGeneratedFiles, plan);
|
|
199
|
+
if (!options.dryRun) {
|
|
200
|
+
for (const template of prepared)
|
|
201
|
+
writeStagedTemplate(projectRoot, template);
|
|
202
|
+
if (themeGeneratedFiles)
|
|
203
|
+
writeThemeGeneratedFiles(projectRoot, themeGeneratedFiles);
|
|
204
|
+
if (activation) {
|
|
205
|
+
writeProjectFile(projectRoot, activationIntentRel(activation), stableJson({ activate: true, palette: activation.palette }));
|
|
206
|
+
}
|
|
207
|
+
updateLock(projectRoot, prepared, lock, options, "not-pushed", {}, themeContext, themeGeneratedFiles, shellContext);
|
|
208
|
+
if (!options.stageOnly) {
|
|
209
|
+
try {
|
|
210
|
+
const baseUrl = normalizeSiteUrl(projectRoot, options.siteUrl);
|
|
211
|
+
const pushedAt = await pushPreparedTemplates(baseUrl, prepared, activation);
|
|
212
|
+
updateLock(projectRoot, prepared, readTemplateLock(projectRoot) ?? lock, options, "pushed", { pushedAt, siteUrl: baseUrl }, themeContext, themeGeneratedFiles, shellContext);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
updateLock(projectRoot, prepared, readTemplateLock(projectRoot) ?? lock, options, "failed", { error: error instanceof Error ? error.message : String(error), siteUrl: normalizeSiteUrl(projectRoot, options.siteUrl) }, themeContext, themeGeneratedFiles, shellContext);
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const target = prepared[prepared.length - 1];
|
|
221
|
+
const stagedArtifacts = [
|
|
222
|
+
...prepared.flatMap((template) => [
|
|
223
|
+
template.stagedManifestRel,
|
|
224
|
+
template.stagedTemplateRel,
|
|
225
|
+
template.stagedSampleRel,
|
|
226
|
+
...(template.stagedPageSeedRel ? [template.stagedPageSeedRel] : []),
|
|
227
|
+
...(template.stagedBehaviorRel ? [template.stagedBehaviorRel] : []),
|
|
228
|
+
template.stagedProvenanceRel
|
|
229
|
+
]),
|
|
230
|
+
...(themeGeneratedFiles ? themeGeneratedFiles.files.map((file) => file.rel) : []),
|
|
231
|
+
...(activation ? [activationIntentRel(activation)] : [])
|
|
232
|
+
];
|
|
233
|
+
const pushed = options.dryRun || options.stageOnly
|
|
234
|
+
? []
|
|
235
|
+
: prepared.map((template) => ({ template: template.resolved.manifest.id, templateId: template.templateRecord.id, siteUrl: normalizeSiteUrl(projectRoot, options.siteUrl), status: "pushed" }));
|
|
236
|
+
return {
|
|
237
|
+
ok: true,
|
|
238
|
+
template: target.resolved.manifest.id,
|
|
239
|
+
version: target.resolved.manifest.version,
|
|
240
|
+
projectDir: projectRoot,
|
|
241
|
+
framework: options.framework,
|
|
242
|
+
dryRun: Boolean(options.dryRun),
|
|
243
|
+
stageOnly: Boolean(options.stageOnly),
|
|
244
|
+
registry: target.resolved.source.registry ?? null,
|
|
245
|
+
installedTemplates: prepared.map((template) => ({
|
|
246
|
+
id: template.resolved.manifest.id,
|
|
247
|
+
version: template.resolved.manifest.version,
|
|
248
|
+
kind: template.resolved.manifest.kind,
|
|
249
|
+
dependency: template.dependency,
|
|
250
|
+
reasons: template.reasons
|
|
251
|
+
})),
|
|
252
|
+
plan,
|
|
253
|
+
stagedArtifacts,
|
|
254
|
+
pushed,
|
|
255
|
+
warnings: themeGeneratedFiles && Object.keys(themeGeneratedFiles.fontPackages).length
|
|
256
|
+
? ["Theme font dependencies were updated in site/package.json; run pnpm install before building the site."]
|
|
257
|
+
: [],
|
|
258
|
+
nextSteps: nextStepsForPrepared(prepared, options),
|
|
259
|
+
lockFile: templatesLockPath(projectRoot)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
for (const item of resolved)
|
|
264
|
+
item.resolved.cleanup();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function nextStepsForPrepared(prepared, options) {
|
|
268
|
+
const kinds = new Set(prepared.map((template) => template.resolved.manifest.kind));
|
|
269
|
+
const steps = [
|
|
270
|
+
options.stageOnly || options.dryRun ? "Run pnpm --dir site run templates:apply with the Astro/EmDash dev server running to push staged draft templates and page seeds." : "Review the templates and staged pages in EmDash/Galley before publishing or placing them."
|
|
271
|
+
];
|
|
272
|
+
if (kinds.has("section"))
|
|
273
|
+
steps.push("Add installed section templates to pages.content deliberately; raybase templates add does not change page composition.");
|
|
274
|
+
if (kinds.has("layout"))
|
|
275
|
+
steps.push("Review installed layout templates in Galley before activating them for public site pages.");
|
|
276
|
+
if (kinds.has("page-starter"))
|
|
277
|
+
steps.push("Review staged page seed JSON under site/seed/pages before applying or publishing pages.");
|
|
278
|
+
if (options.activateStructure)
|
|
279
|
+
steps.push("Activation intent is staged as activation.json beside the selected layout under site/seed/templates; templates:apply publishes the staged templates and activates that layout.");
|
|
280
|
+
if (kinds.has("partial"))
|
|
281
|
+
steps.push("Partial templates are staged as dependencies for rendered templates and usually do not need direct page placement.");
|
|
282
|
+
steps.push(".raybase/templates.json, site/seed/templates, and site/seed/pages should be committed with this app.");
|
|
283
|
+
return steps;
|
|
284
|
+
}
|
|
285
|
+
async function buildThemeGeneratedFiles(projectRoot, context) {
|
|
286
|
+
const paletteNames = context.theme.manifest.choices.palettes;
|
|
287
|
+
const palettesRel = "site/src/styles/palettes.gen.css";
|
|
288
|
+
const paletteFontsRel = "site/src/styles/palette-fonts.gen.css";
|
|
289
|
+
const paletteModuleRel = "site/src/lib/palettes.gen.ts";
|
|
290
|
+
const packageJsonRel = "site/package.json";
|
|
291
|
+
const fontPackages = collectFontPackages(context.theme.palettes, paletteNames);
|
|
292
|
+
const { rescopePaletteCss } = await loadGalleyPaletteModule(projectRoot);
|
|
293
|
+
const palettesCss = generatedPalettesCss(context.theme.palettes, paletteNames, rescopePaletteCss);
|
|
294
|
+
const paletteFontsCss = generatedPaletteFontsCss(context.theme.palettes, paletteNames);
|
|
295
|
+
const paletteModule = generatedPaletteModule(context.theme.manifest.defaultPalette, context.theme.palettes, paletteNames);
|
|
296
|
+
const packageJson = mergedSitePackageJson(projectRoot, packageJsonRel, fontPackages);
|
|
297
|
+
const files = [
|
|
298
|
+
{ rel: palettesRel, text: palettesCss, hash: sha256Buffer(palettesCss) },
|
|
299
|
+
{ rel: paletteFontsRel, text: paletteFontsCss, hash: sha256Buffer(paletteFontsCss) },
|
|
300
|
+
{ rel: paletteModuleRel, text: paletteModule, hash: sha256Buffer(paletteModule) },
|
|
301
|
+
{ rel: packageJsonRel, text: packageJson, hash: sha256Buffer(packageJson) }
|
|
302
|
+
];
|
|
303
|
+
return { palettesRel, paletteFontsRel, paletteModuleRel, packageJsonRel, paletteNames, fontPackages, files };
|
|
304
|
+
}
|
|
305
|
+
async function loadGalleyPaletteModule(projectRoot) {
|
|
306
|
+
const parentUrl = pathToFileURL(resolveInside(projectRoot, "site/package.json")).href;
|
|
307
|
+
const cached = galleyPaletteModulePromises.get(parentUrl);
|
|
308
|
+
if (cached)
|
|
309
|
+
return cached;
|
|
310
|
+
const promise = tsImport("@raybase/galley/palette", parentUrl);
|
|
311
|
+
galleyPaletteModulePromises.set(parentUrl, promise);
|
|
312
|
+
return promise;
|
|
313
|
+
}
|
|
314
|
+
function generatedPalettesCss(palettes, names, rescopePaletteCss) {
|
|
315
|
+
const blocks = names.map((name) => {
|
|
316
|
+
const palette = palettes[name];
|
|
317
|
+
if (!palette)
|
|
318
|
+
throw new Error(`Theme palette ${name} is missing.`);
|
|
319
|
+
const colorScheme = palette.colorScheme ?? "light dark";
|
|
320
|
+
const banner = colorScheme === "light dark"
|
|
321
|
+
? `/* ${name} */`
|
|
322
|
+
: `/* ${name} — ${colorScheme}-only; do not add a light/dark mode toggle while this palette is active */`;
|
|
323
|
+
return `${banner}\n${rescopePaletteCss(palette.css, name, { colorScheme })}`;
|
|
324
|
+
});
|
|
325
|
+
return [
|
|
326
|
+
"/* Generated by raybase templates theme add.",
|
|
327
|
+
" * Agents may edit this site-owned file directly; re-run the theme install command to regenerate it from the registry. */",
|
|
328
|
+
"@layer palette {",
|
|
329
|
+
...blocks,
|
|
330
|
+
"}",
|
|
331
|
+
""
|
|
332
|
+
].join("\n");
|
|
333
|
+
}
|
|
334
|
+
function generatedPaletteModule(defaultPalette, palettes, names) {
|
|
335
|
+
const schemes = Object.fromEntries(names.map((name) => [name, palettes[name]?.colorScheme ?? "light dark"]));
|
|
336
|
+
return [
|
|
337
|
+
"// Generated by raybase templates theme add.",
|
|
338
|
+
`export const DEFAULT_PALETTE = ${JSON.stringify(defaultPalette)} as const;`,
|
|
339
|
+
'// Palettes mapped to "dark" or "light" render that scheme unconditionally;',
|
|
340
|
+
'// only offer a light/dark mode toggle while a "light dark" palette is active.',
|
|
341
|
+
`export const PALETTE_SCHEMES: Record<string, "light dark" | "dark" | "light"> = ${JSON.stringify(schemes, null, 2)};`,
|
|
342
|
+
""
|
|
343
|
+
].join("\n");
|
|
344
|
+
}
|
|
345
|
+
function generatedPaletteFontsCss(palettes, names) {
|
|
346
|
+
const imports = new Set();
|
|
347
|
+
for (const name of names) {
|
|
348
|
+
for (const font of palettes[name]?.fonts ?? []) {
|
|
349
|
+
for (const specifier of fontImportSpecifiers(font))
|
|
350
|
+
imports.add(`@import "${specifier}";`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return [
|
|
354
|
+
"/* Generated by raybase templates theme add. */",
|
|
355
|
+
...[...imports].sort(),
|
|
356
|
+
""
|
|
357
|
+
].join("\n");
|
|
358
|
+
}
|
|
359
|
+
function fontImportSpecifiers(font) {
|
|
360
|
+
return font.imports.map((importPath) => `${font.package}/${importPath}`.replace(/\/index\.css$/, "/index.css"));
|
|
361
|
+
}
|
|
362
|
+
function collectFontPackages(palettes, names) {
|
|
363
|
+
const packages = {};
|
|
364
|
+
for (const name of names) {
|
|
365
|
+
for (const font of palettes[name]?.fonts ?? []) {
|
|
366
|
+
packages[font.package] = font.version;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return Object.fromEntries(Object.entries(packages).sort(([left], [right]) => left.localeCompare(right)));
|
|
370
|
+
}
|
|
371
|
+
function mergedSitePackageJson(projectRoot, rel, fontPackages) {
|
|
372
|
+
const target = resolveInside(projectRoot, rel);
|
|
373
|
+
const parsed = existsSync(target)
|
|
374
|
+
? readJsonFile(target)
|
|
375
|
+
: { private: true, type: "module" };
|
|
376
|
+
const dependencies = {
|
|
377
|
+
...((parsed.dependencies && typeof parsed.dependencies === "object" && !Array.isArray(parsed.dependencies)) ? parsed.dependencies : {}),
|
|
378
|
+
...fontPackages
|
|
379
|
+
};
|
|
380
|
+
return stableJson({ ...parsed, dependencies });
|
|
381
|
+
}
|
|
382
|
+
function planThemeGeneratedFiles(projectRoot, generated, plan) {
|
|
383
|
+
for (const file of generated.files) {
|
|
384
|
+
const target = resolveInside(projectRoot, file.rel);
|
|
385
|
+
const status = !existsSync(target)
|
|
386
|
+
? "create"
|
|
387
|
+
: sha256File(target) === file.hash
|
|
388
|
+
? "unchanged"
|
|
389
|
+
: "update";
|
|
390
|
+
plan.push({ template: "theme", action: "stage", target: file.rel, status });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function writeThemeGeneratedFiles(projectRoot, generated) {
|
|
394
|
+
for (const file of generated.files)
|
|
395
|
+
writeProjectFile(projectRoot, file.rel, file.text);
|
|
396
|
+
}
|
|
397
|
+
function selectPalette(theme, requested) {
|
|
398
|
+
const choices = theme.manifest.choices.palettes;
|
|
399
|
+
// Colors get the same explicit-choice rule as layouts: an ambiguous palette
|
|
400
|
+
// is an error, not a silent defaultPalette fallback. Single-palette themes
|
|
401
|
+
// still resolve without a flag.
|
|
402
|
+
if (!requested && choices.length > 1) {
|
|
403
|
+
throw new Error(`Theme ${theme.manifest.id} has multiple palettes. Choose one with --palette ${choices.join("|")}.`);
|
|
404
|
+
}
|
|
405
|
+
const selected = requested ?? theme.manifest.defaultPalette;
|
|
406
|
+
if (!choices.includes(selected)) {
|
|
407
|
+
throw new Error(`Theme ${theme.manifest.id} palette must be one of: ${choices.join(", ")}.`);
|
|
408
|
+
}
|
|
409
|
+
const palette = theme.palettes[selected];
|
|
410
|
+
if (!palette?.css) {
|
|
411
|
+
throw new Error(`Theme ${theme.manifest.id} palette ${selected} is missing its palette payload.`);
|
|
412
|
+
}
|
|
413
|
+
return { name: selected, palette };
|
|
414
|
+
}
|
|
415
|
+
function selectThemeTemplates(theme, options, pageRoutes = new Map()) {
|
|
416
|
+
const selected = new Map();
|
|
417
|
+
const add = (id, reason) => {
|
|
418
|
+
if (!id || typeof id !== "string")
|
|
419
|
+
return;
|
|
420
|
+
const reasons = selected.get(id) ?? new Set();
|
|
421
|
+
reasons.add(reason);
|
|
422
|
+
selected.set(id, reasons);
|
|
423
|
+
};
|
|
424
|
+
// Schema v3: theme add stages voice + vocabulary only. Nav/footer/layout
|
|
425
|
+
// (the shell) are installed by `shell add`, not the theme.
|
|
426
|
+
for (const id of theme.dependencies.required)
|
|
427
|
+
add(id, "required");
|
|
428
|
+
for (const request of options.pageStarters ?? []) {
|
|
429
|
+
const byKey = theme.choices.pageStarters[request];
|
|
430
|
+
if (byKey) {
|
|
431
|
+
for (const id of byKey)
|
|
432
|
+
add(id, "page-starter");
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
const allPageStarters = Object.values(theme.choices.pageStarters).flat();
|
|
436
|
+
if (!allPageStarters.includes(request)) {
|
|
437
|
+
throw new Error(`Theme ${theme.id} page starter must be one of: ${[...Object.keys(theme.choices.pageStarters), ...allPageStarters].join(", ")}.`);
|
|
438
|
+
}
|
|
439
|
+
add(request, "page-starter");
|
|
440
|
+
}
|
|
441
|
+
for (const id of pageRoutes.keys())
|
|
442
|
+
add(id, "page");
|
|
443
|
+
if (options.includeSections) {
|
|
444
|
+
for (const id of theme.choices.sections)
|
|
445
|
+
add(id, "section");
|
|
446
|
+
}
|
|
447
|
+
for (const id of options.include ?? [])
|
|
448
|
+
add(id, "include");
|
|
449
|
+
if (options.allOptional) {
|
|
450
|
+
for (const id of theme.dependencies.optional)
|
|
451
|
+
add(id, "optional");
|
|
452
|
+
}
|
|
453
|
+
return selected;
|
|
454
|
+
}
|
|
455
|
+
function selectThemePageRoutes(theme, options) {
|
|
456
|
+
const routes = new Map();
|
|
457
|
+
for (const raw of options.pages ?? []) {
|
|
458
|
+
const parsed = parseThemePageSelection(raw);
|
|
459
|
+
const starters = resolveThemePageStarterIds(theme, parsed.starter);
|
|
460
|
+
if (starters.length !== 1) {
|
|
461
|
+
throw new Error(`Theme ${theme.id} page selection ${raw} resolved to ${starters.length || "no"} starters. Choose an exact page starter template id.`);
|
|
462
|
+
}
|
|
463
|
+
routes.set(starters[0], normalizePageRoute(parsed.route));
|
|
464
|
+
}
|
|
465
|
+
return routes;
|
|
466
|
+
}
|
|
467
|
+
function parseThemePageSelection(raw) {
|
|
468
|
+
const index = raw.indexOf("=");
|
|
469
|
+
if (index <= 0 || index === raw.length - 1)
|
|
470
|
+
throw new Error(`--page expects <route=starter>, for example --page /=onePage.`);
|
|
471
|
+
return { route: raw.slice(0, index).trim(), starter: raw.slice(index + 1).trim() };
|
|
472
|
+
}
|
|
473
|
+
function resolveThemePageStarterIds(theme, request) {
|
|
474
|
+
const byKey = theme.choices.pageStarters[request];
|
|
475
|
+
if (byKey)
|
|
476
|
+
return byKey;
|
|
477
|
+
const allPageStarters = Object.values(theme.choices.pageStarters).flat();
|
|
478
|
+
if (!allPageStarters.includes(request)) {
|
|
479
|
+
throw new Error(`Theme ${theme.id} page starter must be one of: ${[...Object.keys(theme.choices.pageStarters), ...allPageStarters].join(", ")}.`);
|
|
480
|
+
}
|
|
481
|
+
return [request];
|
|
482
|
+
}
|
|
483
|
+
async function resolveInstallGraph(selections, options) {
|
|
484
|
+
const visited = new Set();
|
|
485
|
+
const resolving = new Set();
|
|
486
|
+
const output = [];
|
|
487
|
+
const byId = new Map();
|
|
488
|
+
async function visit(currentSpec, dependency, reason) {
|
|
489
|
+
const resolved = await resolveTemplateSource(currentSpec, { registry: options.registry, offline: options.offline });
|
|
490
|
+
const id = resolved.manifest.id;
|
|
491
|
+
if (visited.has(id)) {
|
|
492
|
+
const existing = byId.get(id);
|
|
493
|
+
if (existing) {
|
|
494
|
+
existing.reasons.add(reason);
|
|
495
|
+
if (!dependency)
|
|
496
|
+
existing.dependency = false;
|
|
497
|
+
}
|
|
498
|
+
resolved.cleanup();
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (resolving.has(id)) {
|
|
502
|
+
resolved.cleanup();
|
|
503
|
+
throw new Error(`Template dependency cycle includes ${id}.`);
|
|
504
|
+
}
|
|
505
|
+
resolving.add(id);
|
|
506
|
+
try {
|
|
507
|
+
for (const dependencyId of resolved.manifest.relations?.requires ?? []) {
|
|
508
|
+
await visit(dependencyId, true, "dependency");
|
|
509
|
+
}
|
|
510
|
+
resolving.delete(id);
|
|
511
|
+
visited.add(id);
|
|
512
|
+
const entry = { resolved, dependency, reasons: new Set([reason]) };
|
|
513
|
+
byId.set(id, entry);
|
|
514
|
+
output.push(entry);
|
|
515
|
+
}
|
|
516
|
+
catch (error) {
|
|
517
|
+
resolving.delete(id);
|
|
518
|
+
resolved.cleanup();
|
|
519
|
+
throw error;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
for (const selection of selections)
|
|
523
|
+
await visit(selection.spec, false, selection.reason);
|
|
524
|
+
return output.map((entry) => ({ ...entry, reasons: [...entry.reasons].sort() }));
|
|
525
|
+
}
|
|
526
|
+
function prepareTemplate(resolved, options) {
|
|
527
|
+
const manifest = resolved.manifest;
|
|
528
|
+
assertInstallable(manifest, options);
|
|
529
|
+
const liquidRel = (manifest.galley.source ?? "./template.liquid").replace(/^\.\//, "");
|
|
530
|
+
const sampleRel = "sample-content.json";
|
|
531
|
+
const pageRecipeRel = "page.json";
|
|
532
|
+
const hostSeedRel = "host.json";
|
|
533
|
+
const behaviorRel = manifest.galley.behavior?.source?.replace(/^\.\//, "") ?? null;
|
|
534
|
+
const liquidPath = resolveInside(resolved.templateRoot, liquidRel);
|
|
535
|
+
const samplePath = resolveInside(resolved.templateRoot, sampleRel);
|
|
536
|
+
const pageRecipePath = resolveInside(resolved.templateRoot, pageRecipeRel);
|
|
537
|
+
const hostSeedPath = resolveInside(resolved.templateRoot, hostSeedRel);
|
|
538
|
+
const behaviorPath = behaviorRel ? resolveInside(resolved.templateRoot, behaviorRel) : null;
|
|
539
|
+
assertNoSymlink(liquidPath);
|
|
540
|
+
assertNoSymlink(samplePath);
|
|
541
|
+
if (behaviorPath)
|
|
542
|
+
assertNoSymlink(behaviorPath);
|
|
543
|
+
if (!existsSync(liquidPath) || !statSync(liquidPath).isFile())
|
|
544
|
+
throw new Error(`${manifest.id} payload is missing ${liquidRel}.`);
|
|
545
|
+
if (!existsSync(samplePath) || !statSync(samplePath).isFile())
|
|
546
|
+
throw new Error(`${manifest.id} payload is missing sample-content.json.`);
|
|
547
|
+
// Ordinary page starters seed a pages entry (page.json). Entry-hosted
|
|
548
|
+
// starters (manifest host block) are the shared detail page for a whole
|
|
549
|
+
// collection and ship host.json — the design-field staging artifact —
|
|
550
|
+
// instead; they seed no pages entry.
|
|
551
|
+
const entryHosted = manifest.kind === "page-starter" && manifest.host != null;
|
|
552
|
+
if (manifest.kind === "page-starter" && !entryHosted && (!existsSync(pageRecipePath) || !statSync(pageRecipePath).isFile())) {
|
|
553
|
+
throw new Error(`${manifest.id} page-starter payload is missing page.json.`);
|
|
554
|
+
}
|
|
555
|
+
if (entryHosted && (!existsSync(hostSeedPath) || !statSync(hostSeedPath).isFile())) {
|
|
556
|
+
throw new Error(`${manifest.id} entry-hosted page-starter payload is missing host.json.`);
|
|
557
|
+
}
|
|
558
|
+
if (behaviorPath && !statSync(behaviorPath).isFile())
|
|
559
|
+
throw new Error(`${manifest.id} payload is missing ${behaviorRel}.`);
|
|
560
|
+
const liquidSource = readFileSync(liquidPath, "utf8");
|
|
561
|
+
if (hasUnresolvedTypedTokens(liquidSource)) {
|
|
562
|
+
throw new Error(`${manifest.id} still contains unresolved typed tokens such as [[slot:]] or [[field:]].`);
|
|
563
|
+
}
|
|
564
|
+
const sampleContent = readFileSync(samplePath, "utf8");
|
|
565
|
+
const expectedTemplateIntegrity = resolved.source.templateIntegrity ?? resolved.source.sourceIntegrity;
|
|
566
|
+
if (expectedTemplateIntegrity && sha256Integrity(liquidSource) !== expectedTemplateIntegrity)
|
|
567
|
+
throw new Error(`Source integrity mismatch for Template ${manifest.id}.`);
|
|
568
|
+
if (resolved.source.sampleContentIntegrity && sha256Integrity(sampleContent) !== resolved.source.sampleContentIntegrity)
|
|
569
|
+
throw new Error(`Sample content integrity mismatch for Template ${manifest.id}.`);
|
|
570
|
+
JSON.parse(sampleContent);
|
|
571
|
+
const behaviorSource = behaviorPath ? readFileSync(behaviorPath, "utf8") : null;
|
|
572
|
+
if (behaviorSource && resolved.source.behaviorIntegrity && sha256Integrity(behaviorSource) !== resolved.source.behaviorIntegrity) {
|
|
573
|
+
throw new Error(`Behavior integrity mismatch for Template ${manifest.id}.`);
|
|
574
|
+
}
|
|
575
|
+
const bindingRecords = resolveTemplateBindings(manifest, options.bindings);
|
|
576
|
+
const dataSources = rewriteDataSources(manifest.galley.dataSources ?? {}, bindingRecords);
|
|
577
|
+
const boundContext = rewriteContext(manifest.galley.context, bindingRecords);
|
|
578
|
+
const templateRecord = {
|
|
579
|
+
id: manifest.id,
|
|
580
|
+
version: 1,
|
|
581
|
+
label: manifest.name,
|
|
582
|
+
status: "draft",
|
|
583
|
+
role: manifest.galley.role,
|
|
584
|
+
...(manifest.galley.slots ? { slots: manifest.galley.slots } : {}),
|
|
585
|
+
...(boundContext ? { context: boundContext } : {}),
|
|
586
|
+
fields: manifest.galley.fields ?? {},
|
|
587
|
+
dataSources,
|
|
588
|
+
liquidSource
|
|
589
|
+
};
|
|
590
|
+
const pageSeed = manifest.kind === "page-starter" && !entryHosted
|
|
591
|
+
? readPageSeedRecipe(pageRecipePath, manifest, templateRecord, options.themeContext)
|
|
592
|
+
: null;
|
|
593
|
+
const pageSeedHash = pageSeed ? sha256Buffer(stableJson(pageSeed.seed)) : null;
|
|
594
|
+
const hostSeed = entryHosted ? readHostSeedRecipe(hostSeedPath, manifest, bindingRecords, resolved.source.hostSeedIntegrity ?? null) : null;
|
|
595
|
+
const hostSeedHash = hostSeed ? sha256Buffer(stableJson(hostSeed)) : null;
|
|
596
|
+
const generatedHash = sha256Buffer(stableJson(templateRecord));
|
|
597
|
+
const liquidHash = sha256Buffer(liquidSource);
|
|
598
|
+
const sampleHash = sha256Buffer(sampleContent);
|
|
599
|
+
const manifestHash = sha256Buffer(stableJson(manifest));
|
|
600
|
+
const templateDirRel = `site/seed/templates/${manifest.id}`;
|
|
601
|
+
const stagedManifestRel = `${templateDirRel}/manifest.json`;
|
|
602
|
+
const stagedTemplateRel = `${templateDirRel}/template.json`;
|
|
603
|
+
const stagedSampleRel = `${templateDirRel}/sample-content.json`;
|
|
604
|
+
const stagedPageSeedRel = pageSeed ? `site/seed/pages/${pageSeed.seed.slug}.json` : null;
|
|
605
|
+
const stagedHostSeedRel = hostSeed ? `${templateDirRel}/host.json` : null;
|
|
606
|
+
const stagedBehaviorRel = behaviorRel ? `${templateDirRel}/${behaviorRel}` : null;
|
|
607
|
+
const stagedProvenanceRel = `${templateDirRel}/provenance.json`;
|
|
608
|
+
const themeSelection = options.themeContext ? themeSelectionForTemplate(options.themeContext, manifest.id) : null;
|
|
609
|
+
const provenance = {
|
|
610
|
+
schemaVersion: 1,
|
|
611
|
+
template: {
|
|
612
|
+
id: manifest.id,
|
|
613
|
+
kind: manifest.kind,
|
|
614
|
+
version: manifest.version,
|
|
615
|
+
family: manifest.family ?? null
|
|
616
|
+
},
|
|
617
|
+
source: resolved.source,
|
|
618
|
+
generated: {
|
|
619
|
+
templateId: templateRecord.id,
|
|
620
|
+
templateVersion: templateRecord.version,
|
|
621
|
+
templateHash: generatedHash,
|
|
622
|
+
liquidSourceHash: liquidHash,
|
|
623
|
+
sampleContentHash: sampleHash
|
|
624
|
+
},
|
|
625
|
+
page: pageSeed
|
|
626
|
+
? {
|
|
627
|
+
slug: pageSeed.seed.slug,
|
|
628
|
+
route: pageSeed.route,
|
|
629
|
+
stagedArtifact: stagedPageSeedRel,
|
|
630
|
+
pageSeedHash,
|
|
631
|
+
publish: pageSeed.seed.publish,
|
|
632
|
+
design: {
|
|
633
|
+
templateId: pageSeed.seed.design.templateId,
|
|
634
|
+
templateVersion: pageSeed.seed.design.templateVersion
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
: null,
|
|
638
|
+
host: hostSeed
|
|
639
|
+
? {
|
|
640
|
+
contextKey: hostSeed.host.contextKey,
|
|
641
|
+
defaultCollection: manifest.host?.collection ?? null,
|
|
642
|
+
collection: hostSeed.host.collection,
|
|
643
|
+
field: hostSeed.field.slug,
|
|
644
|
+
stagedArtifact: stagedHostSeedRel,
|
|
645
|
+
hostSeedHash,
|
|
646
|
+
integrity: resolved.source.hostSeedIntegrity ?? null
|
|
647
|
+
}
|
|
648
|
+
: null,
|
|
649
|
+
dependencies: manifest.relations?.requires ?? [],
|
|
650
|
+
compatibility: {
|
|
651
|
+
framework: options.framework,
|
|
652
|
+
raybaseCli: options.cliVersion
|
|
653
|
+
},
|
|
654
|
+
choices: themeSelection ? { theme: themeSelection } : {},
|
|
655
|
+
bindings: Object.fromEntries(bindingRecords.map((record) => [record.alias, record])),
|
|
656
|
+
...(behaviorRel
|
|
657
|
+
? {
|
|
658
|
+
behavior: {
|
|
659
|
+
source: behaviorRel,
|
|
660
|
+
stagedArtifact: stagedBehaviorRel,
|
|
661
|
+
hash: behaviorSource ? sha256Buffer(behaviorSource) : null,
|
|
662
|
+
integrity: resolved.source.behaviorIntegrity ?? null
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
: {})
|
|
666
|
+
};
|
|
667
|
+
const behaviorHash = behaviorSource ? sha256Buffer(behaviorSource) : null;
|
|
668
|
+
return {
|
|
669
|
+
resolved,
|
|
670
|
+
dependency: options.dependency,
|
|
671
|
+
liquidSource,
|
|
672
|
+
sampleContent,
|
|
673
|
+
templateRecord,
|
|
674
|
+
generatedHash,
|
|
675
|
+
liquidHash,
|
|
676
|
+
sampleHash,
|
|
677
|
+
manifestHash,
|
|
678
|
+
stagedManifestRel,
|
|
679
|
+
stagedTemplateRel,
|
|
680
|
+
stagedSampleRel,
|
|
681
|
+
stagedPageSeedRel,
|
|
682
|
+
stagedHostSeedRel,
|
|
683
|
+
stagedBehaviorRel,
|
|
684
|
+
stagedProvenanceRel,
|
|
685
|
+
behaviorSource,
|
|
686
|
+
behaviorHash,
|
|
687
|
+
pageSeed,
|
|
688
|
+
pageSeedHash,
|
|
689
|
+
hostSeed,
|
|
690
|
+
hostSeedHash,
|
|
691
|
+
provenance,
|
|
692
|
+
reasons: options.reasons
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
// Read, verify, and rebind host.json. The staged copy carries the BOUND
|
|
696
|
+
// collection so templates:apply can create the design field without knowing
|
|
697
|
+
// about bindings; provenance records both sides.
|
|
698
|
+
function readHostSeedRecipe(hostSeedPath, manifest, bindingRecords, expectedIntegrity) {
|
|
699
|
+
const raw = readFileSync(hostSeedPath, "utf8");
|
|
700
|
+
if (expectedIntegrity && sha256Integrity(raw) !== expectedIntegrity) {
|
|
701
|
+
throw new Error(`Host seed integrity mismatch for Template ${manifest.id}.`);
|
|
702
|
+
}
|
|
703
|
+
const recipe = JSON.parse(raw);
|
|
704
|
+
if (!recipe || typeof recipe !== "object")
|
|
705
|
+
throw new Error(`${manifest.id} host.json must be an object.`);
|
|
706
|
+
if (recipe.schemaVersion !== 1)
|
|
707
|
+
throw new Error(`${manifest.id} host.json schemaVersion must be 1.`);
|
|
708
|
+
const host = recipe.host;
|
|
709
|
+
if (!host || typeof host !== "object" || typeof host.collection !== "string" || typeof host.contextKey !== "string") {
|
|
710
|
+
throw new Error(`${manifest.id} host.json must declare host.collection and host.contextKey.`);
|
|
711
|
+
}
|
|
712
|
+
if (manifest.host && (host.collection !== manifest.host.collection || host.contextKey !== manifest.host.contextKey)) {
|
|
713
|
+
throw new Error(`${manifest.id} host.json host block must match the manifest host block.`);
|
|
714
|
+
}
|
|
715
|
+
const field = recipe.field;
|
|
716
|
+
if (!field || typeof field !== "object" || typeof field.slug !== "string" || typeof field.label !== "string") {
|
|
717
|
+
throw new Error(`${manifest.id} host.json must declare field.slug and field.label.`);
|
|
718
|
+
}
|
|
719
|
+
if (!isSafeCollectionSlug(field.slug))
|
|
720
|
+
throw new Error(`${manifest.id} host.json field.slug must be a safe slug.`);
|
|
721
|
+
const fieldOptions = field.options;
|
|
722
|
+
if (!fieldOptions || typeof fieldOptions !== "object" || fieldOptions.template !== manifest.id) {
|
|
723
|
+
throw new Error(`${manifest.id} host.json field.options.template must default to this starter.`);
|
|
724
|
+
}
|
|
725
|
+
const binding = bindingRecords.find((record) => record.target === "context" && record.alias === host.contextKey);
|
|
726
|
+
const boundCollection = binding?.kind === "collection" ? binding.collection : host.collection;
|
|
727
|
+
if (!isSafeCollectionSlug(boundCollection))
|
|
728
|
+
throw new Error(`${manifest.id} host collection binding must be a safe collection slug.`);
|
|
729
|
+
return {
|
|
730
|
+
schemaVersion: 1,
|
|
731
|
+
host: { collection: boundCollection, contextKey: host.contextKey },
|
|
732
|
+
field: {
|
|
733
|
+
slug: field.slug,
|
|
734
|
+
label: field.label,
|
|
735
|
+
options: {
|
|
736
|
+
template: fieldOptions.template,
|
|
737
|
+
...(Array.isArray(fieldOptions.allow) ? { allow: fieldOptions.allow.filter((item) => typeof item === "string") } : {})
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function assertInstallable(manifest, options) {
|
|
743
|
+
if (!manifest.compatibility.frameworks.includes(options.framework))
|
|
744
|
+
throw new Error(`${manifest.id} is not compatible with the ${options.framework} framework.`);
|
|
745
|
+
if (!satisfiesVersion(options.cliVersion, manifest.compatibility.raybaseCli)) {
|
|
746
|
+
throw new Error(`${manifest.id} requires raybase ${manifest.compatibility.raybaseCli}, but this CLI is ${options.cliVersion}.`);
|
|
747
|
+
}
|
|
748
|
+
if (!["partial", "section", "layout", "page-starter"].includes(manifest.kind))
|
|
749
|
+
throw new Error(`${manifest.id} has unsupported kind ${manifest.kind}.`);
|
|
750
|
+
if (manifest.kind === "partial" && manifest.galley.role !== "partial")
|
|
751
|
+
throw new Error(`${manifest.id} is a partial template but does not declare galley.role partial.`);
|
|
752
|
+
if (manifest.kind === "section" && manifest.galley.role !== "surface")
|
|
753
|
+
throw new Error(`${manifest.id} is a section template but does not declare galley.role surface.`);
|
|
754
|
+
if (manifest.kind === "layout" && manifest.galley.role !== "layout")
|
|
755
|
+
throw new Error(`${manifest.id} is a layout template but does not declare galley.role layout.`);
|
|
756
|
+
if (manifest.kind === "page-starter" && manifest.galley.role !== "surface")
|
|
757
|
+
throw new Error(`${manifest.id} is a page-starter template but does not declare galley.role surface.`);
|
|
758
|
+
}
|
|
759
|
+
function resolveTemplateBindings(manifest, explicitBindings) {
|
|
760
|
+
const records = [];
|
|
761
|
+
// Typed-context bindings first: `--bind <contextKey>=<collection>` retargets
|
|
762
|
+
// the declared entry collection (an entry-hosted starter's host collection
|
|
763
|
+
// binds through its contextKey). An explicit context bind also seeds the
|
|
764
|
+
// convention-collection propagation map below.
|
|
765
|
+
const propagation = new Map();
|
|
766
|
+
const context = manifest.galley.context ?? {};
|
|
767
|
+
for (const [key, declaration] of Object.entries(context)) {
|
|
768
|
+
if (!isSafeBindingAlias(key))
|
|
769
|
+
throw new Error(`${manifest.id} has unsafe context key ${key}.`);
|
|
770
|
+
const defaultCollection = typeof declaration.collection === "string" && declaration.collection.trim() ? declaration.collection.trim() : null;
|
|
771
|
+
const explicit = explicitBindings[key];
|
|
772
|
+
if (explicit?.kind === "menu")
|
|
773
|
+
throw new Error(`${manifest.id} context ${key} requires a collection binding, not menu:${explicit.menu}.`);
|
|
774
|
+
const collection = explicit?.collection ?? defaultCollection;
|
|
775
|
+
if (!collection) {
|
|
776
|
+
throw new Error(`${manifest.id} requires a collection binding for context ${key}. Re-run with --bind ${key}=<collection-slug>.`);
|
|
777
|
+
}
|
|
778
|
+
if (!isSafeCollectionSlug(collection))
|
|
779
|
+
throw new Error(`${manifest.id} binding ${key} must use a safe collection slug.`);
|
|
780
|
+
if (defaultCollection && !isSafeCollectionSlug(defaultCollection))
|
|
781
|
+
throw new Error(`${manifest.id} default collection for context ${key} is unsafe.`);
|
|
782
|
+
if (explicit && defaultCollection && defaultCollection !== collection)
|
|
783
|
+
propagation.set(defaultCollection, collection);
|
|
784
|
+
records.push({
|
|
785
|
+
templateId: manifest.id,
|
|
786
|
+
alias: key,
|
|
787
|
+
kind: "collection",
|
|
788
|
+
target: "context",
|
|
789
|
+
source: explicit ? "explicit" : "default",
|
|
790
|
+
defaultCollection,
|
|
791
|
+
collection
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
const dataSources = manifest.galley.dataSources ?? {};
|
|
795
|
+
for (const [alias, value] of Object.entries(dataSources)) {
|
|
796
|
+
if (!isSafeBindingAlias(alias))
|
|
797
|
+
throw new Error(`${manifest.id} has unsafe data source alias ${alias}.`);
|
|
798
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
799
|
+
throw new Error(`${manifest.id} data source ${alias} must be an object.`);
|
|
800
|
+
const source = value;
|
|
801
|
+
if (source.kind === "menu") {
|
|
802
|
+
const defaultMenu = typeof source.menu === "string" && source.menu.trim() ? source.menu.trim() : null;
|
|
803
|
+
const explicit = explicitBindings[alias];
|
|
804
|
+
if (explicit?.kind === "collection") {
|
|
805
|
+
throw new Error(`${manifest.id} data source ${alias} requires a menu binding, not collection ${explicit.collection}.`);
|
|
806
|
+
}
|
|
807
|
+
const menu = explicit?.menu ?? defaultMenu;
|
|
808
|
+
if (!menu) {
|
|
809
|
+
throw new Error(`${manifest.id} requires a menu binding for ${alias}. Re-run with --bind ${alias}=menu:<menu-name>.`);
|
|
810
|
+
}
|
|
811
|
+
if (!isSafeMenuName(menu))
|
|
812
|
+
throw new Error(`${manifest.id} binding ${alias} must use a safe menu name.`);
|
|
813
|
+
if (defaultMenu && !isSafeMenuName(defaultMenu))
|
|
814
|
+
throw new Error(`${manifest.id} default menu for ${alias} is unsafe.`);
|
|
815
|
+
records.push({
|
|
816
|
+
templateId: manifest.id,
|
|
817
|
+
alias,
|
|
818
|
+
kind: "menu",
|
|
819
|
+
target: "dataSource",
|
|
820
|
+
source: explicit ? "explicit" : "default",
|
|
821
|
+
defaultMenu,
|
|
822
|
+
menu
|
|
823
|
+
});
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
if (source.kind !== "collection")
|
|
827
|
+
throw new Error(`${manifest.id} data source ${alias} has unsupported kind ${String(source.kind)}.`);
|
|
828
|
+
const defaultCollection = typeof source.collection === "string" && source.collection.trim() ? source.collection.trim() : null;
|
|
829
|
+
const explicit = explicitBindings[alias];
|
|
830
|
+
if (explicit?.kind === "menu") {
|
|
831
|
+
throw new Error(`${manifest.id} data source ${alias} requires a collection binding, not menu:${explicit.menu}.`);
|
|
832
|
+
}
|
|
833
|
+
// A data source left unbound follows an explicit context rebinding when
|
|
834
|
+
// its declared default names the same convention collection — a rail
|
|
835
|
+
// filtered by the host entry must query the entry's bound collection, not
|
|
836
|
+
// the registry convention it was authored against.
|
|
837
|
+
const propagated = !explicit && defaultCollection ? propagation.get(defaultCollection) : undefined;
|
|
838
|
+
const collection = explicit?.collection ?? propagated ?? defaultCollection;
|
|
839
|
+
if (!collection) {
|
|
840
|
+
throw new Error(`${manifest.id} requires a collection binding for ${alias}. Re-run with --bind ${alias}=<collection-slug>.`);
|
|
841
|
+
}
|
|
842
|
+
if (!isSafeCollectionSlug(collection))
|
|
843
|
+
throw new Error(`${manifest.id} binding ${alias} must use a safe collection slug.`);
|
|
844
|
+
if (defaultCollection && !isSafeCollectionSlug(defaultCollection))
|
|
845
|
+
throw new Error(`${manifest.id} default collection for ${alias} is unsafe.`);
|
|
846
|
+
records.push({
|
|
847
|
+
templateId: manifest.id,
|
|
848
|
+
alias,
|
|
849
|
+
kind: "collection",
|
|
850
|
+
target: "dataSource",
|
|
851
|
+
source: explicit ? "explicit" : propagated ? "propagated" : "default",
|
|
852
|
+
defaultCollection,
|
|
853
|
+
collection
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
return records;
|
|
857
|
+
}
|
|
858
|
+
function rewriteDataSources(dataSources, records) {
|
|
859
|
+
const bindings = new Map(records.filter((record) => record.target === "dataSource").map((record) => [record.alias, record]));
|
|
860
|
+
return Object.fromEntries(Object.entries(dataSources).map(([alias, value]) => {
|
|
861
|
+
const record = bindings.get(alias);
|
|
862
|
+
if (!record || !value || typeof value !== "object" || Array.isArray(value))
|
|
863
|
+
return [alias, value];
|
|
864
|
+
if (record.kind === "menu")
|
|
865
|
+
return [alias, { ...value, menu: record.menu }];
|
|
866
|
+
return [alias, { ...value, collection: record.collection }];
|
|
867
|
+
}));
|
|
868
|
+
}
|
|
869
|
+
function rewriteContext(context, records) {
|
|
870
|
+
if (!context || Object.keys(context).length === 0)
|
|
871
|
+
return undefined;
|
|
872
|
+
const bindings = new Map(records.filter((record) => record.target === "context").map((record) => [record.alias, record]));
|
|
873
|
+
return Object.fromEntries(Object.entries(context).map(([key, declaration]) => {
|
|
874
|
+
const record = bindings.get(key);
|
|
875
|
+
if (!record || !declaration || typeof declaration !== "object")
|
|
876
|
+
return [key, declaration];
|
|
877
|
+
if (record.kind !== "collection")
|
|
878
|
+
return [key, declaration];
|
|
879
|
+
return [key, { ...declaration, collection: record.collection }];
|
|
880
|
+
}));
|
|
881
|
+
}
|
|
882
|
+
function validateUnusedBindings(prepared, explicitBindings) {
|
|
883
|
+
const aliases = new Set(prepared.flatMap((template) => [
|
|
884
|
+
...Object.keys(template.resolved.manifest.galley.dataSources ?? {}),
|
|
885
|
+
...Object.keys(template.resolved.manifest.galley.context ?? {})
|
|
886
|
+
]));
|
|
887
|
+
for (const [alias, binding] of Object.entries(explicitBindings)) {
|
|
888
|
+
if (!isSafeBindingAlias(alias))
|
|
889
|
+
throw new Error(`Binding alias ${alias} is unsafe.`);
|
|
890
|
+
if (binding.kind === "collection" && !isSafeCollectionSlug(binding.collection))
|
|
891
|
+
throw new Error(`Binding ${alias} must use a safe collection slug.`);
|
|
892
|
+
if (binding.kind === "menu" && !isSafeMenuName(binding.menu))
|
|
893
|
+
throw new Error(`Binding ${alias} must use a safe menu name.`);
|
|
894
|
+
if (!aliases.has(alias))
|
|
895
|
+
throw new Error(`Binding ${alias} does not match any selected Template data source or context key.`);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
function isSafeBindingAlias(value) {
|
|
899
|
+
return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value);
|
|
900
|
+
}
|
|
901
|
+
function isSafeCollectionSlug(value) {
|
|
902
|
+
return /^[a-z0-9][a-z0-9_-]*$/.test(value);
|
|
903
|
+
}
|
|
904
|
+
function isSafeMenuName(value) {
|
|
905
|
+
return /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,120}$/.test(value);
|
|
906
|
+
}
|
|
907
|
+
function themeSelectionForTemplate(context, templateId) {
|
|
908
|
+
const reasons = context.selections.get(templateId);
|
|
909
|
+
if (!reasons)
|
|
910
|
+
return null;
|
|
911
|
+
return {
|
|
912
|
+
id: context.theme.manifest.id,
|
|
913
|
+
version: context.theme.manifest.version,
|
|
914
|
+
selectedPalette: context.selectedPalette,
|
|
915
|
+
reasons: [...reasons].sort(),
|
|
916
|
+
source: context.theme.source
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
function readPageSeedRecipe(pageRecipePath, manifest, templateRecord, themeContext) {
|
|
920
|
+
const recipe = readJsonFile(pageRecipePath);
|
|
921
|
+
if (!recipe || typeof recipe !== "object")
|
|
922
|
+
throw new Error(`${manifest.id} page.json must be an object.`);
|
|
923
|
+
if (recipe.schemaVersion === 1) {
|
|
924
|
+
throw new Error(`${manifest.id} page.json uses schemaVersion 1; page.json v1 is no longer supported. Re-sync the templates registry to get metadata-only v2 page starters.`);
|
|
925
|
+
}
|
|
926
|
+
if (recipe.schemaVersion !== 2)
|
|
927
|
+
throw new Error(`${manifest.id} page.json schemaVersion must be 2.`);
|
|
928
|
+
for (const field of ["purpose", "slug", "title"]) {
|
|
929
|
+
if (typeof recipe[field] !== "string" || !recipe[field].trim())
|
|
930
|
+
throw new Error(`${manifest.id} page.json must declare ${field}.`);
|
|
931
|
+
}
|
|
932
|
+
if (recipe.description !== undefined && typeof recipe.description !== "string")
|
|
933
|
+
throw new Error(`${manifest.id} page.json description must be a string.`);
|
|
934
|
+
const requestedRoute = themeContext?.pageRoutes.get(manifest.id);
|
|
935
|
+
const route = requestedRoute ? normalizePageRoute(requestedRoute) : routeForRecipeSlug(recipe.slug, recipe.purpose);
|
|
936
|
+
const slug = slugForPageRoute(route, recipe.slug);
|
|
937
|
+
return {
|
|
938
|
+
route,
|
|
939
|
+
seed: {
|
|
940
|
+
schemaVersion: 2,
|
|
941
|
+
slug,
|
|
942
|
+
title: recipe.title,
|
|
943
|
+
...(recipe.description !== undefined ? { description: recipe.description } : {}),
|
|
944
|
+
publish: themeContext?.activateStructure === true,
|
|
945
|
+
design: {
|
|
946
|
+
templateId: templateRecord.id,
|
|
947
|
+
templateVersion: templateRecord.version,
|
|
948
|
+
data: {},
|
|
949
|
+
richText: {}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
function normalizePageRoute(value) {
|
|
955
|
+
const trimmed = value.trim();
|
|
956
|
+
if (!trimmed)
|
|
957
|
+
throw new Error("Page route must not be empty.");
|
|
958
|
+
const withSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
959
|
+
const normalized = withSlash.length > 1 ? withSlash.replace(/\/+$/, "") : "/";
|
|
960
|
+
if (!/^\/[A-Za-z0-9/_-]*$/.test(normalized))
|
|
961
|
+
throw new Error(`Page route ${value} must use safe URL path characters.`);
|
|
962
|
+
return normalized;
|
|
963
|
+
}
|
|
964
|
+
function routeForRecipeSlug(slug, purpose) {
|
|
965
|
+
const trimmed = slug.trim();
|
|
966
|
+
if (trimmed.startsWith("/"))
|
|
967
|
+
return normalizePageRoute(trimmed);
|
|
968
|
+
if (trimmed === "home" || purpose === "home")
|
|
969
|
+
return "/";
|
|
970
|
+
if (!isSafeCollectionSlug(trimmed))
|
|
971
|
+
throw new Error(`Page seed slug ${slug} must be safe.`);
|
|
972
|
+
return `/${trimmed}`;
|
|
973
|
+
}
|
|
974
|
+
function slugForPageRoute(route, fallbackSlug) {
|
|
975
|
+
if (route === "/")
|
|
976
|
+
return "home";
|
|
977
|
+
const slug = route.replace(/^\/+/, "").replace(/\/+/g, "-");
|
|
978
|
+
if (isSafeCollectionSlug(slug))
|
|
979
|
+
return slug;
|
|
980
|
+
const fallback = fallbackSlug.trim();
|
|
981
|
+
if (isSafeCollectionSlug(fallback))
|
|
982
|
+
return fallback;
|
|
983
|
+
throw new Error(`Page route ${route} cannot be converted into a safe page slug.`);
|
|
984
|
+
}
|
|
985
|
+
function planStageTemplate(projectRoot, template, lock, options, plan, conflicts) {
|
|
986
|
+
planStageFile(projectRoot, template, template.stagedManifestRel, template.manifestHash, lock, options, plan, conflicts);
|
|
987
|
+
planStageFile(projectRoot, template, template.stagedTemplateRel, template.generatedHash, lock, options, plan, conflicts);
|
|
988
|
+
planStageFile(projectRoot, template, template.stagedSampleRel, template.sampleHash, lock, options, plan, conflicts);
|
|
989
|
+
if (template.stagedPageSeedRel && template.pageSeedHash)
|
|
990
|
+
planStageFile(projectRoot, template, template.stagedPageSeedRel, template.pageSeedHash, lock, options, plan, conflicts);
|
|
991
|
+
if (template.stagedHostSeedRel && template.hostSeedHash)
|
|
992
|
+
planStageFile(projectRoot, template, template.stagedHostSeedRel, template.hostSeedHash, lock, options, plan, conflicts);
|
|
993
|
+
if (template.stagedBehaviorRel && template.behaviorHash)
|
|
994
|
+
planStageFile(projectRoot, template, template.stagedBehaviorRel, template.behaviorHash, lock, options, plan, conflicts);
|
|
995
|
+
planStageFile(projectRoot, template, template.stagedProvenanceRel, sha256Buffer(stableJson(template.provenance)), lock, options, plan, conflicts);
|
|
996
|
+
if (!options.stageOnly) {
|
|
997
|
+
plan.push({ template: template.resolved.manifest.id, action: "push", target: template.templateRecord.id, status: options.dryRun ? "skipped" : "pushed" });
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function planStageFile(projectRoot, template, rel, nextHash, lock, options, plan, conflicts) {
|
|
1001
|
+
const target = resolveInside(projectRoot, rel);
|
|
1002
|
+
const installed = lock.templates[template.resolved.manifest.id];
|
|
1003
|
+
const recordedHash = recordedArtifactHash(template, installed, rel);
|
|
1004
|
+
if (existsSync(target)) {
|
|
1005
|
+
if (!statSync(target).isFile()) {
|
|
1006
|
+
plan.push({ template: template.resolved.manifest.id, action: "stage", target: rel, status: "conflict" });
|
|
1007
|
+
conflicts.push(`${rel} already exists and is not a file.`);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
const currentHash = sha256File(target);
|
|
1011
|
+
if (recordedHash && currentHash !== recordedHash && !options.overwrite) {
|
|
1012
|
+
plan.push({ template: template.resolved.manifest.id, action: "stage", target: rel, status: "conflict" });
|
|
1013
|
+
conflicts.push(`${rel} has local edits since ${template.resolved.manifest.id} was installed. Re-run with --overwrite after review.`);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (currentHash === nextHash) {
|
|
1017
|
+
plan.push({ template: template.resolved.manifest.id, action: "stage", target: rel, status: "unchanged" });
|
|
1018
|
+
}
|
|
1019
|
+
else if (installed || options.overwrite) {
|
|
1020
|
+
plan.push({ template: template.resolved.manifest.id, action: "stage", target: rel, status: "update" });
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
plan.push({ template: template.resolved.manifest.id, action: "stage", target: rel, status: "conflict" });
|
|
1024
|
+
conflicts.push(`${rel} already exists but is not recorded as the same installed Template. Re-run with --overwrite after review.`);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
else {
|
|
1028
|
+
plan.push({ template: template.resolved.manifest.id, action: "stage", target: rel, status: "create" });
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
function recordedArtifactHash(template, installed, rel) {
|
|
1032
|
+
if (!installed)
|
|
1033
|
+
return null;
|
|
1034
|
+
if (rel === template.stagedManifestRel)
|
|
1035
|
+
return installed.hashes.manifestSha256 ?? null;
|
|
1036
|
+
if (rel === template.stagedTemplateRel)
|
|
1037
|
+
return installed.hashes.generatedTemplates[template.templateRecord.id] ?? null;
|
|
1038
|
+
if (rel === template.stagedSampleRel)
|
|
1039
|
+
return installed.hashes.sampleContentSha256 ?? null;
|
|
1040
|
+
if (rel === template.stagedPageSeedRel)
|
|
1041
|
+
return installed.hashes.pageSeedSha256 ?? null;
|
|
1042
|
+
if (rel === template.stagedHostSeedRel)
|
|
1043
|
+
return installed.hashes.hostSeedSha256 ?? null;
|
|
1044
|
+
if (rel === template.stagedBehaviorRel)
|
|
1045
|
+
return installed.hashes.behaviorSha256 ?? null;
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
function writeStagedTemplate(projectRoot, template) {
|
|
1049
|
+
writeProjectFile(projectRoot, template.stagedManifestRel, stableJson(template.resolved.manifest));
|
|
1050
|
+
writeProjectFile(projectRoot, template.stagedTemplateRel, stableJson(template.templateRecord));
|
|
1051
|
+
writeProjectFile(projectRoot, template.stagedSampleRel, template.sampleContent.endsWith("\n") ? template.sampleContent : `${template.sampleContent}\n`);
|
|
1052
|
+
if (template.stagedPageSeedRel && template.pageSeed) {
|
|
1053
|
+
writeProjectFile(projectRoot, template.stagedPageSeedRel, stableJson(template.pageSeed.seed));
|
|
1054
|
+
}
|
|
1055
|
+
if (template.stagedHostSeedRel && template.hostSeed) {
|
|
1056
|
+
writeProjectFile(projectRoot, template.stagedHostSeedRel, stableJson(template.hostSeed));
|
|
1057
|
+
}
|
|
1058
|
+
if (template.stagedBehaviorRel && template.behaviorSource !== null) {
|
|
1059
|
+
writeProjectFile(projectRoot, template.stagedBehaviorRel, template.behaviorSource);
|
|
1060
|
+
}
|
|
1061
|
+
writeProjectFile(projectRoot, template.stagedProvenanceRel, stableJson(template.provenance));
|
|
1062
|
+
}
|
|
1063
|
+
function writeProjectFile(projectRoot, rel, text) {
|
|
1064
|
+
const target = resolveInside(projectRoot, rel);
|
|
1065
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
1066
|
+
writeFileSync(target, text);
|
|
1067
|
+
}
|
|
1068
|
+
function activationIntentRel(activation) {
|
|
1069
|
+
return `site/seed/templates/${activation.layout.resolved.manifest.id}/activation.json`;
|
|
1070
|
+
}
|
|
1071
|
+
function buildActivationIntent(prepared, themeContext, shellContext) {
|
|
1072
|
+
// Schema v3: `shell add --activate` is the activation path.
|
|
1073
|
+
if (shellContext?.activate) {
|
|
1074
|
+
const layout = prepared.find((template) => template.resolved.manifest.id === shellContext.layoutId)
|
|
1075
|
+
?? prepared.find((template) => template.resolved.manifest.kind === "layout");
|
|
1076
|
+
if (!layout)
|
|
1077
|
+
throw new Error("Cannot activate a shell without the selected layout template.");
|
|
1078
|
+
return { layout, palette: shellContext.palette, provenance: shellContext.provenance };
|
|
1079
|
+
}
|
|
1080
|
+
// Retained theme-activation branch for the v2 window (theme add no longer
|
|
1081
|
+
// sets activateStructure, so this is inert for v3 flows).
|
|
1082
|
+
if (!themeContext?.activateStructure)
|
|
1083
|
+
return null;
|
|
1084
|
+
const byReason = (reason) => prepared.find((template) => themeContext.selections.get(template.resolved.manifest.id)?.has(reason));
|
|
1085
|
+
const layout = byReason("layout") ?? prepared.find((template) => template.resolved.manifest.kind === "layout");
|
|
1086
|
+
if (!layout)
|
|
1087
|
+
throw new Error("Cannot activate Template structure without a selected layout template.");
|
|
1088
|
+
return {
|
|
1089
|
+
layout,
|
|
1090
|
+
palette: themeContext.selectedPalette ?? null,
|
|
1091
|
+
provenance: {
|
|
1092
|
+
themeId: themeContext.theme.manifest.id,
|
|
1093
|
+
themeVersion: themeContext.theme.manifest.version,
|
|
1094
|
+
registry: themeContext.theme.source.registry,
|
|
1095
|
+
generatedAt: new Date().toISOString()
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function updateLock(projectRoot, prepared, lock, options, pushStatus, pushDetails = {}, themeContext, themeGeneratedFiles, shellContext) {
|
|
1100
|
+
const now = new Date().toISOString();
|
|
1101
|
+
lock.updatedAt = now;
|
|
1102
|
+
lock.pages = lock.pages ?? {};
|
|
1103
|
+
for (const template of prepared) {
|
|
1104
|
+
const manifest = template.resolved.manifest;
|
|
1105
|
+
const existing = lock.templates[manifest.id];
|
|
1106
|
+
lock.templates[manifest.id] = {
|
|
1107
|
+
id: manifest.id,
|
|
1108
|
+
kind: manifest.kind,
|
|
1109
|
+
version: manifest.version,
|
|
1110
|
+
family: manifest.family ?? null,
|
|
1111
|
+
installedAt: existing?.installedAt ?? now,
|
|
1112
|
+
updatedAt: now,
|
|
1113
|
+
spec: manifest.id === prepared[prepared.length - 1].resolved.manifest.id ? options.spec : manifest.id,
|
|
1114
|
+
source: {
|
|
1115
|
+
type: template.resolved.source.type,
|
|
1116
|
+
registry: template.resolved.source.registry ?? null,
|
|
1117
|
+
registryLabel: template.resolved.source.registryLabel ?? null,
|
|
1118
|
+
manifestUrl: template.resolved.source.manifestUrl ?? null,
|
|
1119
|
+
templateUrl: template.resolved.source.templateUrl ?? null,
|
|
1120
|
+
sampleContentUrl: template.resolved.source.sampleContentUrl ?? null,
|
|
1121
|
+
pageSeedUrl: template.resolved.source.pageSeedUrl ?? null,
|
|
1122
|
+
hostSeedUrl: template.resolved.source.hostSeedUrl ?? null,
|
|
1123
|
+
behaviorUrl: template.resolved.source.behaviorUrl ?? null,
|
|
1124
|
+
manifestIntegrity: template.resolved.source.manifestIntegrity ?? null,
|
|
1125
|
+
templateIntegrity: template.resolved.source.templateIntegrity ?? null,
|
|
1126
|
+
sourceIntegrity: template.resolved.source.sourceIntegrity ?? null,
|
|
1127
|
+
sampleContentIntegrity: template.resolved.source.sampleContentIntegrity ?? null,
|
|
1128
|
+
pageSeedIntegrity: template.resolved.source.pageSeedIntegrity ?? null,
|
|
1129
|
+
hostSeedIntegrity: template.resolved.source.hostSeedIntegrity ?? null,
|
|
1130
|
+
behaviorIntegrity: template.resolved.source.behaviorIntegrity ?? null
|
|
1131
|
+
},
|
|
1132
|
+
compatibility: {
|
|
1133
|
+
framework: options.framework,
|
|
1134
|
+
raybaseCli: options.cliVersion
|
|
1135
|
+
},
|
|
1136
|
+
hashes: {
|
|
1137
|
+
liquidSourceSha256: template.liquidHash,
|
|
1138
|
+
sampleContentSha256: template.sampleHash,
|
|
1139
|
+
manifestSha256: template.manifestHash,
|
|
1140
|
+
pageSeedSha256: template.pageSeedHash ?? null,
|
|
1141
|
+
hostSeedSha256: template.hostSeedHash ?? null,
|
|
1142
|
+
behaviorSha256: template.behaviorHash ?? null,
|
|
1143
|
+
generatedTemplates: { [template.templateRecord.id]: template.generatedHash }
|
|
1144
|
+
},
|
|
1145
|
+
templateIds: [template.templateRecord.id],
|
|
1146
|
+
dependencies: manifest.relations?.requires ?? [],
|
|
1147
|
+
stagedArtifacts: {
|
|
1148
|
+
manifest: template.stagedManifestRel,
|
|
1149
|
+
template: template.stagedTemplateRel,
|
|
1150
|
+
sampleContent: template.stagedSampleRel,
|
|
1151
|
+
pageSeed: template.stagedPageSeedRel,
|
|
1152
|
+
hostSeed: template.stagedHostSeedRel,
|
|
1153
|
+
behavior: template.stagedBehaviorRel,
|
|
1154
|
+
provenance: template.stagedProvenanceRel
|
|
1155
|
+
},
|
|
1156
|
+
push: {
|
|
1157
|
+
status: pushStatus,
|
|
1158
|
+
pushedAt: pushStatus === "pushed" ? pushDetails.pushedAt ?? now : null,
|
|
1159
|
+
siteUrl: pushDetails.siteUrl ?? null,
|
|
1160
|
+
error: pushStatus === "failed" ? pushDetails.error ?? "Unknown push failure" : null
|
|
1161
|
+
},
|
|
1162
|
+
choices: template.provenance.choices ?? {},
|
|
1163
|
+
bindings: template.provenance.bindings ?? {}
|
|
1164
|
+
};
|
|
1165
|
+
if (template.pageSeed && template.stagedPageSeedRel && template.pageSeedHash) {
|
|
1166
|
+
lock.pages[template.pageSeed.seed.slug] = {
|
|
1167
|
+
templateId: manifest.id,
|
|
1168
|
+
slug: template.pageSeed.seed.slug,
|
|
1169
|
+
route: template.pageSeed.route,
|
|
1170
|
+
title: template.pageSeed.seed.title ?? null,
|
|
1171
|
+
stagedArtifact: template.stagedPageSeedRel,
|
|
1172
|
+
seedSha256: template.pageSeedHash,
|
|
1173
|
+
publish: template.pageSeed.seed.publish,
|
|
1174
|
+
design: {
|
|
1175
|
+
templateId: template.pageSeed.seed.design.templateId,
|
|
1176
|
+
templateVersion: template.pageSeed.seed.design.templateVersion
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (themeContext && themeGeneratedFiles) {
|
|
1182
|
+
lock.theme = {
|
|
1183
|
+
id: themeContext.theme.manifest.id,
|
|
1184
|
+
version: themeContext.theme.manifest.version,
|
|
1185
|
+
defaultPalette: themeContext.theme.manifest.defaultPalette,
|
|
1186
|
+
selectedPalette: themeContext.selectedPalette,
|
|
1187
|
+
palettes: themeGeneratedFiles.paletteNames,
|
|
1188
|
+
fontPackages: themeGeneratedFiles.fontPackages,
|
|
1189
|
+
generatedArtifacts: {
|
|
1190
|
+
palettes: themeGeneratedFiles.palettesRel,
|
|
1191
|
+
paletteFonts: themeGeneratedFiles.paletteFontsRel,
|
|
1192
|
+
paletteModule: themeGeneratedFiles.paletteModuleRel,
|
|
1193
|
+
packageJson: themeGeneratedFiles.packageJsonRel
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
if (shellContext) {
|
|
1198
|
+
const layout = prepared.find((template) => template.resolved.manifest.id === shellContext.layoutId);
|
|
1199
|
+
lock.shell = {
|
|
1200
|
+
id: shellContext.layoutId,
|
|
1201
|
+
version: layout?.resolved.manifest.version ?? "0.0.0",
|
|
1202
|
+
nav: shellContext.nav ?? "",
|
|
1203
|
+
footer: shellContext.footer ?? "",
|
|
1204
|
+
palette: shellContext.palette,
|
|
1205
|
+
activated: shellContext.activate
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
writeTemplateLock(projectRoot, lock);
|
|
1209
|
+
}
|
|
1210
|
+
async function pushPreparedTemplates(baseUrl, prepared, activation = null) {
|
|
1211
|
+
const behaviorTemplate = prepared.find((template) => template.behaviorSource !== null);
|
|
1212
|
+
if (behaviorTemplate) {
|
|
1213
|
+
throw new Error(`${behaviorTemplate.resolved.manifest.id} declares a behavior sidecar. The current Galley save endpoint does not expose a verified behavior-code contract; the template has been staged, but push is gated. Re-run with --stage-only and apply after extending Galley behavior support.`);
|
|
1214
|
+
}
|
|
1215
|
+
const cookie = await activateDevBypass(baseUrl);
|
|
1216
|
+
const installedAt = new Date().toISOString();
|
|
1217
|
+
const templates = prepared.map((template) => ({
|
|
1218
|
+
...template.templateRecord,
|
|
1219
|
+
provenance: {
|
|
1220
|
+
packId: template.resolved.manifest.id,
|
|
1221
|
+
packVersion: template.resolved.manifest.version,
|
|
1222
|
+
registry: template.resolved.source.registry ?? template.resolved.source.registryLabel ?? null,
|
|
1223
|
+
liquidSourceSha256: template.liquidHash,
|
|
1224
|
+
installedAt
|
|
1225
|
+
}
|
|
1226
|
+
}));
|
|
1227
|
+
if (activation) {
|
|
1228
|
+
await postJson(baseUrl, cookie, "/_emdash/api/plugins/galley/templates/publish-batch", {
|
|
1229
|
+
templates,
|
|
1230
|
+
activateLayout: {
|
|
1231
|
+
templateId: activation.layout.templateRecord.id,
|
|
1232
|
+
templateVersion: activation.layout.templateRecord.version,
|
|
1233
|
+
palette: activation.palette,
|
|
1234
|
+
provenance: activation.provenance
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
else if (templates.length > 1) {
|
|
1239
|
+
await postJson(baseUrl, cookie, "/_emdash/api/plugins/galley/templates/save-batch", { templates });
|
|
1240
|
+
}
|
|
1241
|
+
else {
|
|
1242
|
+
await postJson(baseUrl, cookie, "/_emdash/api/plugins/galley/templates/save", { template: templates[0] });
|
|
1243
|
+
}
|
|
1244
|
+
return new Date().toISOString();
|
|
1245
|
+
}
|
|
1246
|
+
async function activateDevBypass(baseUrl) {
|
|
1247
|
+
const response = await fetch(`${baseUrl}/_emdash/api/setup/dev-bypass?redirect=/`, { redirect: "manual" });
|
|
1248
|
+
const cookie = readCookie(response);
|
|
1249
|
+
if (!cookie)
|
|
1250
|
+
throw new Error("Could not activate EmDash dev bypass. Is the Astro site dev server running?");
|
|
1251
|
+
return cookie;
|
|
1252
|
+
}
|
|
1253
|
+
async function postJson(baseUrl, cookie, path, body) {
|
|
1254
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
1255
|
+
method: "POST",
|
|
1256
|
+
headers: { "content-type": "application/json", "x-emdash-request": "1", cookie },
|
|
1257
|
+
body: JSON.stringify(body)
|
|
1258
|
+
});
|
|
1259
|
+
if (response.status !== 200) {
|
|
1260
|
+
const text = await response.text();
|
|
1261
|
+
throw new Error(`POST ${path} failed: ${response.status} ${response.statusText}\n${text}`);
|
|
1262
|
+
}
|
|
1263
|
+
return unwrapApiPayload(await response.json());
|
|
1264
|
+
}
|
|
1265
|
+
function readCookie(response) {
|
|
1266
|
+
const headers = response.headers;
|
|
1267
|
+
const setCookies = headers.getSetCookie?.() ?? [];
|
|
1268
|
+
const parts = setCookies.length ? setCookies : response.headers.get("set-cookie")?.split(",") ?? [];
|
|
1269
|
+
return parts
|
|
1270
|
+
.map((part) => part.trim().split(";")[0])
|
|
1271
|
+
.filter(Boolean)
|
|
1272
|
+
.join("; ");
|
|
1273
|
+
}
|
|
1274
|
+
function unwrapApiPayload(payload) {
|
|
1275
|
+
return payload && typeof payload === "object" && "data" in payload ? payload.data : payload;
|
|
1276
|
+
}
|
|
1277
|
+
function normalizeSiteUrl(projectRoot, value) {
|
|
1278
|
+
const configured = value ?? process.env.EMDASH_URL ?? process.env.RAYBASE_SITE_ORIGIN ?? devVarsSiteOrigin(projectRoot);
|
|
1279
|
+
return (configured ?? "http://127.0.0.1:4321").replace(/\/$/, "");
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* `raybase dev` may move the content site off its default port and persists
|
|
1283
|
+
* the resolved origin to `.dev.vars`; read it so template pushes reach the
|
|
1284
|
+
* running site without an explicit --site-url.
|
|
1285
|
+
*/
|
|
1286
|
+
function devVarsSiteOrigin(projectRoot) {
|
|
1287
|
+
const file = join(projectRoot, ".dev.vars");
|
|
1288
|
+
if (!existsSync(file))
|
|
1289
|
+
return undefined;
|
|
1290
|
+
for (const line of readFileSync(file, "utf8").split(/\r?\n/)) {
|
|
1291
|
+
const trimmed = line.trim();
|
|
1292
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
1293
|
+
continue;
|
|
1294
|
+
const index = trimmed.indexOf("=");
|
|
1295
|
+
if (index === -1)
|
|
1296
|
+
continue;
|
|
1297
|
+
if (trimmed.slice(0, index).trim() !== "RAYBASE_SITE_ORIGIN")
|
|
1298
|
+
continue;
|
|
1299
|
+
const value = trimmed.slice(index + 1).trim();
|
|
1300
|
+
if (value)
|
|
1301
|
+
return value;
|
|
1302
|
+
}
|
|
1303
|
+
return undefined;
|
|
1304
|
+
}
|
|
1305
|
+
function hasUnresolvedTypedTokens(source) {
|
|
1306
|
+
return /\[\[\s*(?:slot|field|dataSlot|data-slot|collection|dataSource|data-source)\s*:/i.test(source);
|
|
1307
|
+
}
|
|
1308
|
+
export function readStagedTemplate(path) {
|
|
1309
|
+
return readJsonFile(path);
|
|
1310
|
+
}
|
|
1311
|
+
//# sourceMappingURL=template-install.js.map
|