microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3fdd7fc5612f6f0db1446a76d6a915c10330db22

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/html-program-viewer/src/emitter.ts

17lines · modecode

1import { Program, resolvePath } from "@cadl-lang/compiler";
2import { readFile } from "fs/promises";
3import { dirname, resolve } from "path";
4import { fileURLToPath } from "url";
5import { renderProgram } from "./ui.js";
6
7export async function $onEmit(program: Program) {
8 const html = renderProgram(program);
9 const htmlPath = resolvePath(program.compilerOptions.outputPath!, "cadl-program.html");
10 const cssPath = resolvePath(program.compilerOptions.outputPath!, "style.css");
11 await program.host.writeFile(
12 htmlPath,
13 `<!DOCTYPE html><html lang="en"><link rel="stylesheet" href="style.css"><body>${html}</body></html>`
14 );
15 const cssFile = resolve(dirname(fileURLToPath(import.meta.url)), "../../src/style.css");
16 await program.host.writeFile(cssPath, await (await readFile(cssFile)).toString());
17}
18