import { OutputType } from './external'; import { onion, initContext, Plugin, PluginContext } from './plugin'; export interface CompilerOptions { width: number, height: number, element: string, engine: string, config: any, // toBrowserUrl: (url: string) => Promise, plugins: Plugin[], type: OutputType, } export async function compile(options: CompilerOptions): Promise { const { plugins } = options; const ctx = initContext(); ctx.element = options.element; ctx.type = options.type; ctx.width = options.width || 800; ctx.height = options.height || 600; ctx.engine = options.engine; ctx.config = options.config; // ctx.toBrowserUrl = options.toBrowserUrl; const reversedPlugins = [...plugins].reverse(); await onion(plugins.map(p => p.onParse), ctx)(); await onion(reversedPlugins.map(p => p.onParsed), ctx)(); await onion(plugins.map(p => p.onCompile), ctx)(); await onion(reversedPlugins.map(p => p.onCompiled), ctx)(); await onion(plugins.map(p => p.onPrint), ctx)(); await onion(reversedPlugins.map(p => p.onPrinted), ctx)(); return ctx; }