UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

91 lines (89 loc) • 3.51 kB
import { readText, writeText } from "../fs.mjs"; import { Effect } from "effect"; //#region src/services/scaffold/upgrade-audit/steps/author-config.ts const targetedRef = (ref, key) => ref.includes("#") ? ref : `${ref}#plugins.${key}`; const translatePlugins = (config) => { const plugins = {}; for (const [key, entry] of Object.entries(config.plugins ?? {})) { const localMatch = (typeof entry.development === "string" ? entry.development : "").match(/^local:plugins\/([^/]+)$/); if (localMatch) { plugins[key] = { path: `plugins/${localMatch[1]}`, ...entry.variables ? { variables: entry.variables } : {}, ...entry.secrets ? { secrets: entry.secrets } : {} }; continue; } if (typeof entry.extends === "string") { plugins[key] = { extends: targetedRef(entry.extends, key), ...entry.variables ? { variables: entry.variables } : {} }; continue; } plugins[key] = { extends: targetedRef(`${config.extends}`, key) }; } return plugins; }; const descriptorBody = (config, _inventory) => { const localApi = config.app?.api?.development === "local:api"; const localUi = config.app?.ui?.development === "local:ui"; return { name: config.domain, extends: config.extends, account: config.account, domain: config.domain, ...config.title ? { title: config.title } : {}, ...config.description ? { description: config.description } : {}, ...config.testnet ? { testnet: config.testnet } : {}, ...config.staging ? { staging: config.staging } : {}, ...config.repository ? { repository: config.repository } : {}, ...config.ci ? { ci: config.ci } : {}, ...localUi ? { ui: { path: "ui" } } : {}, ...localApi ? { api: { path: "api", secrets: config.app?.api?.secrets ?? [] } } : {}, plugins: translatePlugins(config) }; }; const renderBosAppTs = (body) => [ "import { App } from \"everything-dev/descriptor\";", "", "// Authored app descriptor. The published config is canonicalized to JSON", "// from this file; dev-only overrides live in bos.dev.ts (never published).", `export default App(${JSON.stringify(body, null, 2)});`, "" ].join("\n"); const renderBosDevTs = () => [ "import type { AppDescriptor } from \"everything-dev/descriptor\";", "", "/**", " * Dev overlay for the everything.dev runtime (bos.app.ts) — merged", " * child-wins over the resolved config when the environment is development.", " * Never published.", " */", "export default {} satisfies Partial<AppDescriptor>;", "" ].join("\n"); const authorConfig = (projectDir, inventory, dryRun) => Effect.gen(function* () { const config = JSON.parse(yield* readText(projectDir, "bos.config.json")); if (!config.extends || !config.account || !config.domain) return yield* Effect.fail(/* @__PURE__ */ new Error("bos.config.json missing extends/account/domain — audit gate should have caught this")); const bosApp = renderBosAppTs(descriptorBody(config, inventory)); const bosDev = renderBosDevTs(); if (dryRun) return { writes: ["bos.app.ts", "bos.dev.ts"], deletes: [], notes: ["bos.config.json deletion deferred until after first successful types:gen from the descriptor"] }; yield* writeText(projectDir, "bos.app.ts", bosApp); yield* writeText(projectDir, "bos.dev.ts", bosDev); return { writes: ["bos.app.ts", "bos.dev.ts"], deletes: [], notes: ["bos.config.json deletion deferred until after first successful types:gen from the descriptor"] }; }); //#endregion export { authorConfig }; //# sourceMappingURL=author-config.mjs.map