@fluid-app/fluid-cli-portal 0.1.51 → 0.1.53

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/README.md CHANGED
@@ -71,6 +71,9 @@ fluid portal push
71
71
 
72
72
  - Shows a diff and asks for confirmation (add `--yes` to skip).
73
73
  - **Push does NOT publish** — it updates the definition's working/draft state. End users keep seeing the currently-active published version.
74
+ - For a verified non-interactive release, `fluid portal push --yes --activate`
75
+ pushes the draft and creates/activates a live version only when every push
76
+ phase succeeds. Partial pushes exit non-zero and are never activated.
74
77
 
75
78
  ## Publish portal versions (only when you want manifest changes live)
76
79
 
@@ -0,0 +1,91 @@
1
+ //#region src/vite-plugin/build-manifest.d.ts
2
+ interface RawNavigationItem {
3
+ id: number;
4
+ label: string;
5
+ slug?: string;
6
+ icon?: string;
7
+ screen_id?: number;
8
+ parent_id?: number;
9
+ source?: string;
10
+ position: number;
11
+ children: RawNavigationItem[];
12
+ }
13
+ interface RawNavigation {
14
+ id: number;
15
+ name?: string;
16
+ definition_id: number;
17
+ navigation_items?: RawNavigationItem[];
18
+ }
19
+ interface RawTheme {
20
+ id: number;
21
+ config?: Record<string, unknown> | null;
22
+ active?: boolean | null;
23
+ name?: string | null;
24
+ }
25
+ interface RawScreen {
26
+ id: number;
27
+ definition_id?: number;
28
+ name?: string | null;
29
+ slug?: string | null;
30
+ component_tree?: unknown;
31
+ }
32
+ interface RawManifestProfile {
33
+ name?: string;
34
+ definition_id: number;
35
+ themes?: RawTheme[];
36
+ navigation?: RawNavigation;
37
+ mobile_navigation?: RawNavigation;
38
+ }
39
+ interface RawManifestResponse {
40
+ manifest: {
41
+ definition_id: number;
42
+ published_version?: number;
43
+ screens?: RawScreen[];
44
+ profile?: RawManifestProfile;
45
+ };
46
+ }
47
+ interface BuildManifestOptions {
48
+ /**
49
+ * Slug (filename stem) of the profile to assemble. Defaults to the profile
50
+ * flagged `default`, else the first one found — the historical behaviour.
51
+ *
52
+ * A definition can hold several profiles, each with its own navigation and
53
+ * themes, and hosts that let a user preview a profile other than their own
54
+ * (the fluid-admin builder, Mist's in-process preview) need to pick which
55
+ * one lands in the manifest. Unknown slugs fall back to the default rather
56
+ * than producing an empty profile, so a stale persisted selection can't
57
+ * blank a preview.
58
+ */
59
+ readonly profileSlug?: string;
60
+ }
61
+ /** A profile discovered on disk, for hosts that offer a profile switcher. */
62
+ interface LocalProfileSummary {
63
+ readonly slug: string;
64
+ readonly name: string;
65
+ /** Stable synthetic id, derived from the slug — not a server id. */
66
+ readonly id: number;
67
+ readonly isDefault: boolean;
68
+ }
69
+ /**
70
+ * List the profiles a portal directory defines, without building a manifest.
71
+ *
72
+ * Deliberately separate from `buildManifestFromLocalFiles` rather than widening
73
+ * its return type: `portal-dev-plugin` serialises that function's result
74
+ * directly as the `/api/app/manifest` response body, so any extra key would
75
+ * leak into the wire payload.
76
+ *
77
+ * When `portal/profiles/` is absent or empty, reports the single synthetic
78
+ * "Default" profile the builder falls back to, so a switcher never renders an
79
+ * empty list for a scratch portal.
80
+ */
81
+ declare function listLocalProfiles(portalDir: string): Promise<LocalProfileSummary[]>;
82
+ /**
83
+ * Build a `RawManifestResponse` from local portal/ files.
84
+ *
85
+ * The returned object matches the shape from `/api/fluid_os/definitions/active`
86
+ * so the SDK's `transformManifestToRepAppData()` works without modification.
87
+ */
88
+ declare function buildManifestFromLocalFiles(portalDir: string, options?: BuildManifestOptions): Promise<RawManifestResponse>;
89
+ //#endregion
90
+ export { BuildManifestOptions, LocalProfileSummary, buildManifestFromLocalFiles, listLocalProfiles };
91
+ //# sourceMappingURL=build-manifest.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-manifest.d.mts","names":[],"sources":["../src/vite-plugin/build-manifest.ts"],"mappings":";UA2BU,iBAAA;EACR,EAAA;EACA,KAAA;EACA,IAAA;EACA,IAAA;EACA,SAAA;EACA,SAAA;EACA,MAAA;EACA,QAAA;EACA,QAAA,EAAU,iBAAA;AAAA;AAAA,UAGF,aAAA;EACR,EAAA;EACA,IAAA;EACA,aAAA;EACA,gBAAA,GAAmB,iBAAA;AAAA;AAAA,UAGX,QAAA;EACR,EAAA;EACA,MAAA,GAAS,MAAA;EACT,MAAA;EACA,IAAA;AAAA;AAAA,UAGQ,SAAA;EACR,EAAA;EACA,aAAA;EACA,IAAA;EACA,IAAA;EACA,cAAA;AAAA;AAAA,UAGQ,kBAAA;EACR,IAAA;EACA,aAAA;EACA,MAAA,GAAS,QAAA;EACT,UAAA,GAAa,aAAA;EACb,iBAAA,GAAoB,aAAA;AAAA;AAAA,UAGZ,mBAAA;EACR,QAAA;IACE,aAAA;IACA,iBAAA;IACA,OAAA,GAAU,SAAA;IACV,OAAA,GAAU,kBAAA;EAAA;AAAA;AAAA,UAsHG,oBAAA;;;;;AAtIf;;;;;;;WAkJS,WAAA;AAAA;;UAIM,mBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;;WAEA,EAAA;EAAA,SACA,SAAA;AAAA;;AAnJW;;;;;;;;;;;iBAkKA,iBAAA,CACpB,SAAA,WACC,OAAA,CAAQ,mBAAA;;AAtCX;;;;;iBAgFsB,2BAAA,CACpB,SAAA,UACA,OAAA,GAAS,oBAAA,GACR,OAAA,CAAQ,mBAAA"}
@@ -0,0 +1,180 @@
1
+ import { basename, extname, join } from "node:path";
2
+ import { existsSync } from "node:fs";
3
+ import { readFile, readdir } from "node:fs/promises";
4
+ import { createHash } from "node:crypto";
5
+ //#region src/vite-plugin/build-manifest.ts
6
+ /**
7
+ * Build a RawManifestResponse from local portal/ files.
8
+ *
9
+ * Reads the portal directory structure produced by `fluid portal pull` and
10
+ * assembles it into the same shape the SDK expects from the
11
+ * `/api/fluid_os/definitions/active` endpoint, so the existing
12
+ * `transformManifestToRepAppData()` pipeline works unchanged.
13
+ */
14
+ /**
15
+ * Generate a deterministic synthetic numeric ID from a string key.
16
+ * Uses a CRC32-like hash so the same slug always produces the same ID
17
+ * within a dev session, while avoiding collisions in practice.
18
+ */
19
+ function syntheticId(key) {
20
+ return createHash("md5").update(key).digest().readUInt32BE(0);
21
+ }
22
+ /**
23
+ * Slug reported for the profile this builder synthesises when a portal has no
24
+ * `portal/profiles/` files. Not a real filename — it exists so a host offering
25
+ * a profile switcher has something stable to key a selection on.
26
+ */
27
+ const SYNTHETIC_PROFILE_SLUG = "default";
28
+ /**
29
+ * Read and parse a JSON file, returning null on failure.
30
+ */
31
+ async function readJsonFile(filePath) {
32
+ try {
33
+ const content = await readFile(filePath, "utf-8");
34
+ return JSON.parse(content);
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+ /**
40
+ * Read all JSON files in a directory, returning an array of [slug, data] tuples.
41
+ * Slug is the filename without extension.
42
+ */
43
+ async function readJsonDir(dirPath) {
44
+ if (!existsSync(dirPath)) return [];
45
+ const entries = await readdir(dirPath, { withFileTypes: true });
46
+ const results = [];
47
+ for (const entry of entries) {
48
+ if (!entry.isFile() || extname(entry.name) !== ".json") continue;
49
+ const slug = basename(entry.name, ".json");
50
+ const data = await readJsonFile(join(dirPath, entry.name));
51
+ if (data != null) results.push([slug, data]);
52
+ }
53
+ return results;
54
+ }
55
+ /**
56
+ * Convert local navigation items (which reference screens by slug)
57
+ * back to the raw API format (which uses screen_id).
58
+ */
59
+ function toRawNavigationItems(items, screenSlugToId, navigationSlug, parentPath = []) {
60
+ return items.map((item, index) => {
61
+ const itemPath = [...parentPath, index];
62
+ const rawItem = {
63
+ id: item.id ?? syntheticId(`navigation-item:${navigationSlug}:${itemPath.join(".")}`),
64
+ label: item.label ?? "Untitled",
65
+ position: item.position ?? 0,
66
+ children: toRawNavigationItems(item.children ?? [], screenSlugToId, navigationSlug, itemPath)
67
+ };
68
+ if (item.slug != null) rawItem.slug = item.slug;
69
+ if (item.icon != null) rawItem.icon = item.icon;
70
+ if (item.source != null) rawItem.source = item.source;
71
+ if (item.parent_id != null) rawItem.parent_id = item.parent_id;
72
+ if (item.screen != null) {
73
+ const screenId = screenSlugToId.get(item.screen);
74
+ if (screenId != null) rawItem.screen_id = screenId;
75
+ }
76
+ return rawItem;
77
+ });
78
+ }
79
+ /**
80
+ * List the profiles a portal directory defines, without building a manifest.
81
+ *
82
+ * Deliberately separate from `buildManifestFromLocalFiles` rather than widening
83
+ * its return type: `portal-dev-plugin` serialises that function's result
84
+ * directly as the `/api/app/manifest` response body, so any extra key would
85
+ * leak into the wire payload.
86
+ *
87
+ * When `portal/profiles/` is absent or empty, reports the single synthetic
88
+ * "Default" profile the builder falls back to, so a switcher never renders an
89
+ * empty list for a scratch portal.
90
+ */
91
+ async function listLocalProfiles(portalDir) {
92
+ const profileEntries = await readJsonDir(join(portalDir, "profiles"));
93
+ if (profileEntries.length === 0) return [{
94
+ slug: SYNTHETIC_PROFILE_SLUG,
95
+ name: "Default",
96
+ id: syntheticId(`profile:${SYNTHETIC_PROFILE_SLUG}`),
97
+ isDefault: true
98
+ }];
99
+ const defaultIndex = Math.max(profileEntries.findIndex(([, profile]) => profile.default === true), 0);
100
+ return profileEntries.map(([slug, profile], index) => ({
101
+ slug,
102
+ name: profile.name ?? slug,
103
+ id: syntheticId(`profile:${slug}`),
104
+ isDefault: index === defaultIndex
105
+ }));
106
+ }
107
+ /**
108
+ * Build a `RawManifestResponse` from local portal/ files.
109
+ *
110
+ * The returned object matches the shape from `/api/fluid_os/definitions/active`
111
+ * so the SDK's `transformManifestToRepAppData()` works without modification.
112
+ */
113
+ async function buildManifestFromLocalFiles(portalDir, options = {}) {
114
+ const definitionId = syntheticId(`definition:${(await readJsonFile(join(portalDir, "definition.json")))?.name ?? "Local Dev"}`);
115
+ const [screenEntries, themeEntries, navEntries, profileEntries] = await Promise.all([
116
+ readJsonDir(join(portalDir, "screens")),
117
+ readJsonDir(join(portalDir, "themes")),
118
+ readJsonDir(join(portalDir, "navigations")),
119
+ readJsonDir(join(portalDir, "profiles"))
120
+ ]);
121
+ const screenSlugToId = /* @__PURE__ */ new Map();
122
+ for (const [slug] of screenEntries) screenSlugToId.set(slug, syntheticId(`screen:${slug}`));
123
+ const rawScreens = screenEntries.map(([slug, screen]) => ({
124
+ id: screenSlugToId.get(slug),
125
+ definition_id: definitionId,
126
+ name: screen.name,
127
+ slug,
128
+ component_tree: screen.component_tree
129
+ }));
130
+ const themeSlugToRaw = /* @__PURE__ */ new Map();
131
+ for (const [slug, theme] of themeEntries) themeSlugToRaw.set(slug, {
132
+ id: syntheticId(`theme:${slug}`),
133
+ name: theme.name,
134
+ config: theme.config,
135
+ active: theme.active
136
+ });
137
+ const rawThemes = Array.from(themeSlugToRaw.values());
138
+ const navSlugToId = /* @__PURE__ */ new Map();
139
+ for (const [slug] of navEntries) navSlugToId.set(slug, syntheticId(`navigation:${slug}`));
140
+ const rawNavigations = /* @__PURE__ */ new Map();
141
+ for (const [slug, nav] of navEntries) rawNavigations.set(slug, {
142
+ id: navSlugToId.get(slug),
143
+ name: nav.name,
144
+ definition_id: definitionId,
145
+ navigation_items: toRawNavigationItems(nav.navigation_items ?? [], screenSlugToId, slug)
146
+ });
147
+ const defaultProfile = (options.profileSlug != null ? profileEntries.find(([slug]) => slug === options.profileSlug)?.[1] ?? null : null) ?? profileEntries.find(([, p]) => p.default)?.[1] ?? profileEntries[0]?.[1] ?? null;
148
+ let rawProfile;
149
+ if (defaultProfile) {
150
+ const navigation = defaultProfile.navigation ? rawNavigations.get(defaultProfile.navigation) : void 0;
151
+ const mobileNavigation = defaultProfile.mobile_navigation ? rawNavigations.get(defaultProfile.mobile_navigation) : void 0;
152
+ const profileThemeSet = new Set(defaultProfile.themes);
153
+ const profileThemes = profileThemeSet.size > 0 ? Array.from(profileThemeSet).map((slug) => themeSlugToRaw.get(slug)).filter((t) => t != null) : rawThemes;
154
+ rawProfile = {
155
+ name: defaultProfile.name,
156
+ definition_id: definitionId,
157
+ themes: profileThemes,
158
+ ...navigation ? { navigation } : {},
159
+ ...mobileNavigation ? { mobile_navigation: mobileNavigation } : {}
160
+ };
161
+ } else if (rawThemes.length > 0 || rawNavigations.size > 0) {
162
+ const firstNav = rawNavigations.size > 0 ? rawNavigations.values().next().value : void 0;
163
+ rawProfile = {
164
+ name: "Default",
165
+ definition_id: definitionId,
166
+ themes: rawThemes,
167
+ ...firstNav ? { navigation: firstNav } : {}
168
+ };
169
+ }
170
+ return { manifest: {
171
+ definition_id: definitionId,
172
+ published_version: 0,
173
+ screens: rawScreens,
174
+ ...rawProfile ? { profile: rawProfile } : {}
175
+ } };
176
+ }
177
+ //#endregion
178
+ export { buildManifestFromLocalFiles, listLocalProfiles };
179
+
180
+ //# sourceMappingURL=build-manifest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-manifest.mjs","names":[],"sources":["../src/vite-plugin/build-manifest.ts"],"sourcesContent":["/**\n * Build a RawManifestResponse from local portal/ files.\n *\n * Reads the portal directory structure produced by `fluid portal pull` and\n * assembles it into the same shape the SDK expects from the\n * `/api/fluid_os/definitions/active` endpoint, so the existing\n * `transformManifestToRepAppData()` pipeline works unchanged.\n */\n\nimport { readFile, readdir } from \"node:fs/promises\";\nimport { join, basename, extname } from \"node:path\";\nimport { existsSync } from \"node:fs\";\nimport { createHash } from \"node:crypto\";\n\nimport type {\n LocalScreen,\n LocalTheme,\n LocalNavigation,\n LocalNavigationItem,\n LocalProfile,\n} from \"../utils/transform.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types matching the RawManifestResponse shape from\n// packages/portal/sdk/src/transforms/index.ts\n// ─────────────────────────────────────────────────────────────────────────────\n\ninterface RawNavigationItem {\n id: number;\n label: string;\n slug?: string;\n icon?: string;\n screen_id?: number;\n parent_id?: number;\n source?: string;\n position: number;\n children: RawNavigationItem[];\n}\n\ninterface RawNavigation {\n id: number;\n name?: string;\n definition_id: number;\n navigation_items?: RawNavigationItem[];\n}\n\ninterface RawTheme {\n id: number;\n config?: Record<string, unknown> | null;\n active?: boolean | null;\n name?: string | null;\n}\n\ninterface RawScreen {\n id: number;\n definition_id?: number;\n name?: string | null;\n slug?: string | null;\n component_tree?: unknown;\n}\n\ninterface RawManifestProfile {\n name?: string;\n definition_id: number;\n themes?: RawTheme[];\n navigation?: RawNavigation;\n mobile_navigation?: RawNavigation;\n}\n\ninterface RawManifestResponse {\n manifest: {\n definition_id: number;\n published_version?: number;\n screens?: RawScreen[];\n profile?: RawManifestProfile;\n };\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Synthetic ID generation\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Generate a deterministic synthetic numeric ID from a string key.\n * Uses a CRC32-like hash so the same slug always produces the same ID\n * within a dev session, while avoiding collisions in practice.\n */\nfunction syntheticId(key: string): number {\n const hash = createHash(\"md5\").update(key).digest();\n // Read first 4 bytes as unsigned 32-bit integer, ensure positive\n return hash.readUInt32BE(0);\n}\n\n/**\n * Slug reported for the profile this builder synthesises when a portal has no\n * `portal/profiles/` files. Not a real filename — it exists so a host offering\n * a profile switcher has something stable to key a selection on.\n */\nconst SYNTHETIC_PROFILE_SLUG = \"default\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// File reading helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Read and parse a JSON file, returning null on failure.\n */\nasync function readJsonFile<T>(filePath: string): Promise<T | null> {\n try {\n const content = await readFile(filePath, \"utf-8\");\n return JSON.parse(content) as T;\n } catch {\n return null;\n }\n}\n\n/**\n * Read all JSON files in a directory, returning an array of [slug, data] tuples.\n * Slug is the filename without extension.\n */\nasync function readJsonDir<T>(\n dirPath: string,\n): Promise<Array<[slug: string, data: T]>> {\n if (!existsSync(dirPath)) return [];\n\n const entries = await readdir(dirPath, { withFileTypes: true });\n const results: Array<[string, T]> = [];\n\n for (const entry of entries) {\n if (!entry.isFile() || extname(entry.name) !== \".json\") continue;\n\n const slug = basename(entry.name, \".json\");\n const data = await readJsonFile<T>(join(dirPath, entry.name));\n if (data != null) {\n results.push([slug, data]);\n }\n }\n\n return results;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Navigation item conversion\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Convert local navigation items (which reference screens by slug)\n * back to the raw API format (which uses screen_id).\n */\nfunction toRawNavigationItems(\n items: readonly LocalNavigationItem[],\n screenSlugToId: Map<string, number>,\n navigationSlug: string,\n parentPath: readonly number[] = [],\n): RawNavigationItem[] {\n return items.map((item, index) => {\n const itemPath = [...parentPath, index];\n const rawItem: RawNavigationItem = {\n id:\n item.id ??\n syntheticId(`navigation-item:${navigationSlug}:${itemPath.join(\".\")}`),\n label: item.label ?? \"Untitled\",\n position: item.position ?? 0,\n children: toRawNavigationItems(\n item.children ?? [],\n screenSlugToId,\n navigationSlug,\n itemPath,\n ),\n };\n\n if (item.slug != null) rawItem.slug = item.slug;\n if (item.icon != null) rawItem.icon = item.icon;\n if (item.source != null) rawItem.source = item.source;\n if (item.parent_id != null) rawItem.parent_id = item.parent_id;\n\n // Resolve screen slug -> synthetic screen ID\n if (item.screen != null) {\n const screenId = screenSlugToId.get(item.screen);\n if (screenId != null) {\n rawItem.screen_id = screenId;\n }\n }\n\n return rawItem;\n });\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Main builder\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface BuildManifestOptions {\n /**\n * Slug (filename stem) of the profile to assemble. Defaults to the profile\n * flagged `default`, else the first one found — the historical behaviour.\n *\n * A definition can hold several profiles, each with its own navigation and\n * themes, and hosts that let a user preview a profile other than their own\n * (the fluid-admin builder, Mist's in-process preview) need to pick which\n * one lands in the manifest. Unknown slugs fall back to the default rather\n * than producing an empty profile, so a stale persisted selection can't\n * blank a preview.\n */\n readonly profileSlug?: string;\n}\n\n/** A profile discovered on disk, for hosts that offer a profile switcher. */\nexport interface LocalProfileSummary {\n readonly slug: string;\n readonly name: string;\n /** Stable synthetic id, derived from the slug — not a server id. */\n readonly id: number;\n readonly isDefault: boolean;\n}\n\n/**\n * List the profiles a portal directory defines, without building a manifest.\n *\n * Deliberately separate from `buildManifestFromLocalFiles` rather than widening\n * its return type: `portal-dev-plugin` serialises that function's result\n * directly as the `/api/app/manifest` response body, so any extra key would\n * leak into the wire payload.\n *\n * When `portal/profiles/` is absent or empty, reports the single synthetic\n * \"Default\" profile the builder falls back to, so a switcher never renders an\n * empty list for a scratch portal.\n */\nexport async function listLocalProfiles(\n portalDir: string,\n): Promise<LocalProfileSummary[]> {\n const profileEntries = await readJsonDir<LocalProfile>(\n join(portalDir, \"profiles\"),\n );\n\n if (profileEntries.length === 0) {\n return [\n {\n slug: SYNTHETIC_PROFILE_SLUG,\n name: \"Default\",\n id: syntheticId(`profile:${SYNTHETIC_PROFILE_SLUG}`),\n isDefault: true,\n },\n ];\n }\n\n // Exactly one entry is flagged default, and it is the same one the builder\n // would assemble. `buildManifestFromLocalFiles` resolves the default with\n // `find(([, p]) => p.default) ?? profileEntries[0]` — first-wins, with a\n // fallback to the first profile — so mirror both halves here. Local files\n // are hand-edited and can easily claim zero or several defaults; leaving\n // either case unnormalised would make a host's initial selection disagree\n // with the manifest it actually receives, decided by directory order.\n const defaultIndex = Math.max(\n profileEntries.findIndex(([, profile]) => profile.default === true),\n 0,\n );\n\n return profileEntries.map(([slug, profile], index) => ({\n slug,\n name: profile.name ?? slug,\n id: syntheticId(`profile:${slug}`),\n isDefault: index === defaultIndex,\n }));\n}\n\n/**\n * Build a `RawManifestResponse` from local portal/ files.\n *\n * The returned object matches the shape from `/api/fluid_os/definitions/active`\n * so the SDK's `transformManifestToRepAppData()` works without modification.\n */\nexport async function buildManifestFromLocalFiles(\n portalDir: string,\n options: BuildManifestOptions = {},\n): Promise<RawManifestResponse> {\n // 1. Read definition.json\n const definition = await readJsonFile<{ name?: string }>(\n join(portalDir, \"definition.json\"),\n );\n const definitionName = definition?.name ?? \"Local Dev\";\n const definitionId = syntheticId(`definition:${definitionName}`);\n\n // 2. Read all resource files in parallel\n const [screenEntries, themeEntries, navEntries, profileEntries] =\n await Promise.all([\n readJsonDir<LocalScreen>(join(portalDir, \"screens\")),\n readJsonDir<LocalTheme>(join(portalDir, \"themes\")),\n readJsonDir<LocalNavigation>(join(portalDir, \"navigations\")),\n readJsonDir<LocalProfile>(join(portalDir, \"profiles\")),\n ]);\n\n // 3. Build screen slug -> synthetic ID map\n const screenSlugToId = new Map<string, number>();\n for (const [slug] of screenEntries) {\n screenSlugToId.set(slug, syntheticId(`screen:${slug}`));\n }\n\n // 4. Build raw screens\n const rawScreens: RawScreen[] = screenEntries.map(([slug, screen]) => ({\n id: screenSlugToId.get(slug)!,\n definition_id: definitionId,\n name: screen.name,\n slug,\n component_tree: screen.component_tree,\n }));\n\n // 5. Build raw themes (keyed by slug for profile lookup)\n const themeSlugToRaw = new Map<string, RawTheme>();\n for (const [slug, theme] of themeEntries) {\n themeSlugToRaw.set(slug, {\n id: syntheticId(`theme:${slug}`),\n name: theme.name,\n config: theme.config,\n active: theme.active,\n });\n }\n const rawThemes = Array.from(themeSlugToRaw.values());\n\n // 6. Build navigation slug -> synthetic ID map\n const navSlugToId = new Map<string, number>();\n for (const [slug] of navEntries) {\n navSlugToId.set(slug, syntheticId(`navigation:${slug}`));\n }\n\n // Build raw navigations (keyed by slug for profile lookup)\n const rawNavigations = new Map<string, RawNavigation>();\n for (const [slug, nav] of navEntries) {\n rawNavigations.set(slug, {\n id: navSlugToId.get(slug)!,\n name: nav.name,\n definition_id: definitionId,\n navigation_items: toRawNavigationItems(\n nav.navigation_items ?? [],\n screenSlugToId,\n slug,\n ),\n });\n }\n\n // 7. Pick the profile to assemble: the requested slug when it resolves,\n // else the one flagged `default`, else the first. An unknown requested\n // slug falls back rather than yielding an empty profile, so a stale\n // persisted selection in a host can never blank the manifest.\n const requestedProfile =\n options.profileSlug != null\n ? (profileEntries.find(([slug]) => slug === options.profileSlug)?.[1] ??\n null)\n : null;\n\n const defaultProfile =\n requestedProfile ??\n profileEntries.find(([, p]) => p.default)?.[1] ??\n profileEntries[0]?.[1] ??\n null;\n\n // 8. Assemble the profile for the manifest\n let rawProfile: RawManifestProfile | undefined;\n if (defaultProfile) {\n // Resolve navigation slugs to raw navigation objects\n const navigation = defaultProfile.navigation\n ? rawNavigations.get(defaultProfile.navigation)\n : undefined;\n\n const mobileNavigation = defaultProfile.mobile_navigation\n ? rawNavigations.get(defaultProfile.mobile_navigation)\n : undefined;\n\n // Filter themes to those referenced by the profile (by slug)\n const profileThemeSet = new Set(defaultProfile.themes);\n const profileThemes =\n profileThemeSet.size > 0\n ? Array.from(profileThemeSet)\n .map((slug) => themeSlugToRaw.get(slug))\n .filter((t): t is RawTheme => t != null)\n : rawThemes; // If no themes specified in profile, include all\n\n rawProfile = {\n name: defaultProfile.name,\n definition_id: definitionId,\n themes: profileThemes,\n ...(navigation ? { navigation } : {}),\n ...(mobileNavigation ? { mobile_navigation: mobileNavigation } : {}),\n };\n } else if (rawThemes.length > 0 || rawNavigations.size > 0) {\n // No profile files but we have themes/navs — create a synthetic profile\n const firstNav =\n rawNavigations.size > 0\n ? rawNavigations.values().next().value\n : undefined;\n\n rawProfile = {\n name: \"Default\",\n definition_id: definitionId,\n themes: rawThemes,\n ...(firstNav ? { navigation: firstNav } : {}),\n };\n }\n\n // 9. Return assembled manifest\n return {\n manifest: {\n definition_id: definitionId,\n published_version: 0,\n screens: rawScreens,\n ...(rawProfile ? { profile: rawProfile } : {}),\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuFA,SAAS,YAAY,KAAqB;AAGxC,QAFa,WAAW,MAAM,CAAC,OAAO,IAAI,CAAC,QAAQ,CAEvC,aAAa,EAAE;;;;;;;AAQ7B,MAAM,yBAAyB;;;;AAS/B,eAAe,aAAgB,UAAqC;AAClE,KAAI;EACF,MAAM,UAAU,MAAM,SAAS,UAAU,QAAQ;AACjD,SAAO,KAAK,MAAM,QAAQ;SACpB;AACN,SAAO;;;;;;;AAQX,eAAe,YACb,SACyC;AACzC,KAAI,CAAC,WAAW,QAAQ,CAAE,QAAO,EAAE;CAEnC,MAAM,UAAU,MAAM,QAAQ,SAAS,EAAE,eAAe,MAAM,CAAC;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