11import { type API } from './API' ;
22import { type EngineExecutionParams } from '../engine/Engine' ;
33import { type JsExecution } from '../engine/JsExecution' ;
4- import { type Component } from 'obsidian' ;
4+ import { type Component , TFile } from 'obsidian' ;
55import { ResultRenderer } from '../ResultRenderer' ;
66
77/**
@@ -14,11 +14,21 @@ export class InternalAPI {
1414 this . apiInstance = apiInstance ;
1515 }
1616
17- public async excute ( params : EngineExecutionParams ) : Promise < JsExecution > {
17+ public async execute ( params : EngineExecutionParams ) : Promise < JsExecution > {
1818 return await this . apiInstance . plugin . jsEngine . execute ( params ) ;
1919 }
2020
2121 public createRenderer ( container : HTMLElement , sourcePath : string , component : Component ) : ResultRenderer {
2222 return new ResultRenderer ( this . apiInstance . plugin , container , sourcePath , component ) ;
2323 }
24+
25+ public async executeFile ( path : string , params : Omit < EngineExecutionParams , 'code' > ) : Promise < JsExecution > {
26+ const file = this . apiInstance . app . vault . getAbstractFileByPath ( path ) ;
27+ if ( ! file || ! ( file instanceof TFile ) ) {
28+ throw new Error ( `File ${ path } not found.` ) ;
29+ }
30+ const fullParams = params as EngineExecutionParams ;
31+ fullParams . code = await this . apiInstance . app . vault . read ( file ) ;
32+ return await this . execute ( fullParams ) ;
33+ }
2434}
0 commit comments