UNPKG

@autorest/adl

Version:
43 lines 1.41 kB
import { createProgram } from "@azure-tools/adl"; import { readdir, readFile, realpath, stat } from "fs/promises"; import { join, resolve } from "path"; import { fileURLToPath, pathToFileURL } from "url"; export function createAdlHost(writeFile) { return { readFile: (path) => readFile(path, "utf-8"), readDir: (path) => readdir(path, { withFileTypes: true }), getCwd: () => process.cwd(), getExecutionRoot: () => resolve(fileURLToPath(import.meta.url), "../../node_modules/@azure-tools/adl"), getJsImport: (path) => import(pathToFileURL(path).href), writeFile, getLibDirs() { const rootDir = this.getExecutionRoot(); return [join(rootDir, "lib"), join(rootDir, "dist/lib")]; }, stat(path) { return stat(path); }, realpath(path) { return realpath(path); }, }; } export async function compileAdl(entrypoint) { const output = {}; const writeFile = async (path, content) => { output[path] = content; }; try { const program = await createProgram(createAdlHost(writeFile), { mainFile: entrypoint, }); return { compiledFiles: output }; } catch (e) { if ("diagnostics" in e) { return { error: e }; } throw e; } } //# sourceMappingURL=adl-compiler.js.map