import{resolveWorkflowBuildDirectory}from"#internal/application/paths.js";import{readFile}from"node:fs/promises";import{createAuthoredSourceRuntimeCompiledArtifactsSource}from"#internal/application/runtime-compiled-artifacts-source.js";import{resolveRuntimeCompilerArtifactPaths}from"#runtime/loaders/artifact-paths.js";import{activateDevelopmentRuntimeArtifactsSnapshot,stageDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts.js";import{createScheduleRegistrations}from"#runtime/schedules/register.js";import{loadResolvedCompiledSchedules}from"#runtime/schedules/resolve-schedule.js";import{compileAgent}from"#compiler/compile-agent.js";import{writeCompiledArtifactsFiles}from"#internal/application/compiled-artifacts.js";async function prepareApplicationHost(e,t={}){let n=await compileAgent({startPath:e}),r=await loadResolvedCompiledSchedules({compiledArtifactsSource:createAuthoredSourceRuntimeCompiledArtifactsSource(n.project.appRoot)}),i=createScheduleRegistrations(r),a=resolveWorkflowBuildDirectory(n.project.appRoot),o=t.dev===!0?await stageDevelopmentRuntimeArtifactsSnapshot(n):void 0,s=resolveRuntimeCompilerArtifactPaths(o===void 0?n.project.appRoot:o.runtimeAppRoot),c=await writeCompiledArtifactsFiles({compileResult:t.dev===!0?{...n,manifest:JSON.parse(await readFile(s.compiledManifestPath,`utf8`))}:n,outDir:s.compileDirectoryPath});return o!==void 0&&await activateDevelopmentRuntimeArtifactsSnapshot({appRoot:n.project.appRoot,snapshot:o}),{appRoot:n.project.appRoot,compileResult:n,compiledArtifacts:c,scheduleRegistrations:i,schedules:r,workflowBuildDir:a}}export{prepareApplicationHost};