Path: blob/main/src/project/engine-project-context.ts
6458 views
/*1* engine-project-context.ts2*3* Copyright (C) 2023 Posit Software, PBC4*/56import { MappedString } from "../core/mapped-text.ts";7import { ExecutionEngineInstance } from "../execute/types.ts";8import { projectOutputDir } from "./project-shared.ts";9import {10EngineProjectContext,11FileInformation,12ProjectContext,13} from "./types.ts";1415/**16* Creates an EngineProjectContext adapter from a ProjectContext17* This provides a restricted view of ProjectContext with additional utility methods18*19* @param context The source ProjectContext20* @returns An EngineProjectContext adapter21*/22export function engineProjectContext(23context: ProjectContext,24): EngineProjectContext {25const project: EngineProjectContext = {26// Core properties27dir: context.dir,28isSingleFile: context.isSingleFile,29config: context.config30? {31engines: context.config.engines as string[] | undefined,32project: context.config.project33? {34"output-dir": context.config.project["output-dir"],35}36: undefined,37}38: undefined,39fileInformationCache: context.fileInformationCache,4041// Path utilities42getOutputDirectory: () => {43return projectOutputDir(context);44},4546// Core methods47resolveFullMarkdownForFile: (48engine: ExecutionEngineInstance | undefined,49file: string,50markdown?: MappedString,51force?: boolean,52) => context.resolveFullMarkdownForFile(engine, file, markdown, force),53};5455return project;56}5758/**59* Type guard to check if an object implements the EngineProjectContext interface60*61* @param obj Object to check62* @returns Whether the object is an EngineProjectContext63*/64export function isEngineProjectContext(65obj: unknown,66): obj is EngineProjectContext {67if (!obj) return false;6869const ctx = obj as Partial<EngineProjectContext>;70return (71typeof ctx.dir === "string" &&72typeof ctx.isSingleFile === "boolean" &&73typeof ctx.resolveFullMarkdownForFile === "function"74);75}767778