everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
92 lines (90 loc) • 3.53 kB
JavaScript
const require_api_contract = require('./api-contract.cjs');
const require_config = require('./config.cjs');
const require_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/code-artifacts.ts
var ArtifactGenError = class extends effect.Schema.TaggedError()("ArtifactGenError", {
phase: effect.Schema.String,
cause: effect.Schema.optional(effect.Schema.Unknown)
}) {};
function uiManifestTargets(runtimeConfig) {
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: !(0, node_fs.existsSync)((0, node_path.join)(ui.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_config.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_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)) {
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=code-artifacts.cjs.map