UNPKG

everything-dev

Version:

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

98 lines (96 loc) • 4 kB
const require_api_contract = require('./api-contract.cjs'); const require_serialize = require('../resolution/serialize.cjs'); const require_services_resolution_session = require('../resolution/session.cjs'); let node_fs = require("node:fs"); let node_path = require("node:path"); let effect = require("effect"); let every_plugin_ui_manifest = require("every-plugin/ui/manifest"); let every_plugin_build_ui = require("every-plugin/build/ui"); let every_plugin_ui_manifest_generator = require("every-plugin/ui/manifest-generator"); //#region src/services/codegen/artifacts.ts var ArtifactGenError = class extends effect.Schema.TaggedError()("ArtifactGenError", { phase: effect.Schema.String, cause: effect.Schema.optional(effect.Schema.Unknown) }) {}; function uiManifestTargets(runtimeConfig, forceRouteTree) { const targets = []; const ui = runtimeConfig.ui; if (ui?.source === "local" && ui.localPath) targets.push({ workspaceRoot: ui.localPath, pluginName: every_plugin_ui_manifest.CORE_UI_PLUGIN_KEY, emitRouteTree: forceRouteTree ? true : !(0, node_fs.existsSync)((0, node_path.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 : !(0, node_fs.existsSync)((0, node_path.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 && (0, node_fs.existsSync)((0, node_path.join)(uiPath, "rsbuild.config.ts"))) targets.push({ workspaceRoot: uiPath, pluginName: key, emitRouteTree: false }); } return targets; } const generateCodeArtifactsEffect = effect.Effect.fn("generateCodeArtifacts")(function* (configDir, config, opts) { const env = opts?.env; if (env) yield* effect.Effect.try({ try: () => require_serialize.writeResolvedConfig(configDir, config, env, opts?.extendsChain), catch: (cause) => new ArtifactGenError({ phase: "write resolved config", cause }) }); const runtimeConfig = opts?.runtimeConfig ?? (yield* effect.Effect.tryPromise({ try: () => require_services_resolution_session.openResolution({ cwd: configDir }), catch: (cause) => new ArtifactGenError({ phase: "load resolved config", cause }) }))?.runtime; if (!runtimeConfig) return null; const bridge = yield* effect.Effect.tryPromise({ try: () => require_api_contract.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 === every_plugin_ui_manifest.CORE_UI_PLUGIN_KEY) yield* effect.Effect.try({ try: () => (0, every_plugin_build_ui.emitCoreUiStubs)(target.workspaceRoot), catch: (cause) => new ArtifactGenError({ phase: `emit ui stubs (${target.pluginName})`, cause }) }); yield* effect.Effect.tryPromise({ try: () => (0, every_plugin_ui_manifest_generator.generateUiManifest)(target), catch: (cause) => new ArtifactGenError({ phase: `generate ui manifest (${target.pluginName})`, cause }) }); } return { resolvedConfigPath: env ? (0, node_path.join)(configDir, ".bos/bos.resolved-config.json") : void 0, contractBridgePath: bridge.bridgePath, contractStatus: bridge.status }; }); async function generateCodeArtifacts(configDir, config, opts) { return effect.Effect.runPromise(generateCodeArtifactsEffect(configDir, config, opts)); } //#endregion exports.ArtifactGenError = ArtifactGenError; exports.generateCodeArtifacts = generateCodeArtifacts; exports.generateCodeArtifactsEffect = generateCodeArtifactsEffect; //# sourceMappingURL=artifacts.cjs.map