UNPKG

everything-dev

Version:

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

96 lines (94 loc) • 3.51 kB
import { syncApiContractBridge } from "./api-contract.mjs"; import { writeResolvedConfig } from "../resolution/serialize.mjs"; import { openResolution } from "../resolution/session.mjs"; import { existsSync } from "node:fs"; import { join } from "node:path"; import { Effect, Schema } from "effect"; import { CORE_UI_PLUGIN_KEY } from "every-plugin/ui/manifest"; import { emitCoreUiStubs } from "every-plugin/build/ui"; import { generateUiManifest } from "every-plugin/ui/manifest-generator"; //#region src/services/codegen/artifacts.ts var ArtifactGenError = class extends Schema.TaggedError()("ArtifactGenError", { phase: Schema.String, cause: Schema.optional(Schema.Unknown) }) {}; function uiManifestTargets(runtimeConfig, forceRouteTree) { const targets = []; const ui = runtimeConfig.ui; if (ui?.source === "local" && ui.localPath) targets.push({ workspaceRoot: ui.localPath, pluginName: CORE_UI_PLUGIN_KEY, emitRouteTree: forceRouteTree ? true : !existsSync(join(ui.localPath, "src/routeTree.gen.ts")) }); const authUi = runtimeConfig.auth?.ui; if (authUi?.source === "local" && authUi.localPath && !targets.some((t) => t.workspaceRoot === authUi.localPath)) targets.push({ workspaceRoot: authUi.localPath, pluginName: "auth", emitRouteTree: forceRouteTree ? true : !existsSync(join(authUi.localPath, "src/routeTree.gen.ts")) }); for (const [key, plugin] of Object.entries(runtimeConfig.plugins ?? {})) { const uiPath = plugin.ui?.localPath; if (plugin.ui?.source === "local" && uiPath && existsSync(join(uiPath, "rsbuild.config.ts"))) targets.push({ workspaceRoot: uiPath, pluginName: key, emitRouteTree: false }); } return targets; } const generateCodeArtifactsEffect = Effect.fn("generateCodeArtifacts")(function* (configDir, config, opts) { const env = opts?.env; if (env) yield* Effect.try({ try: () => writeResolvedConfig(configDir, config, env, opts?.extendsChain), catch: (cause) => new ArtifactGenError({ phase: "write resolved config", cause }) }); const runtimeConfig = opts?.runtimeConfig ?? (yield* Effect.tryPromise({ try: () => openResolution({ cwd: configDir }), catch: (cause) => new ArtifactGenError({ phase: "load resolved config", cause }) }))?.runtime; if (!runtimeConfig) return null; const bridge = yield* Effect.tryPromise({ try: () => syncApiContractBridge({ configDir, runtimeConfig, apiBaseUrl: runtimeConfig.api.url }), catch: (cause) => new ArtifactGenError({ phase: "sync api contract bridge", cause }) }); for (const target of uiManifestTargets(runtimeConfig, opts?.forceRouteTree)) { if (target.pluginName === CORE_UI_PLUGIN_KEY) yield* Effect.try({ try: () => emitCoreUiStubs(target.workspaceRoot), catch: (cause) => new ArtifactGenError({ phase: `emit ui stubs (${target.pluginName})`, cause }) }); yield* Effect.tryPromise({ try: () => generateUiManifest(target), catch: (cause) => new ArtifactGenError({ phase: `generate ui manifest (${target.pluginName})`, cause }) }); } return { resolvedConfigPath: env ? join(configDir, ".bos/bos.resolved-config.json") : void 0, contractBridgePath: bridge.bridgePath, contractStatus: bridge.status }; }); async function generateCodeArtifacts(configDir, config, opts) { return Effect.runPromise(generateCodeArtifactsEffect(configDir, config, opts)); } //#endregion export { ArtifactGenError, generateCodeArtifacts, generateCodeArtifactsEffect }; //# sourceMappingURL=artifacts.mjs.map