Move rendering to playbill
This commit is contained in:
parent
2e0d4b45ea
commit
d550f057c5
5 changed files with 42 additions and 414 deletions
31
src/index.ts
31
src/index.ts
|
@ -1,15 +1,16 @@
|
|||
import { watch } from "node:fs/promises";
|
||||
import {
|
||||
ValidatedPlaybillSchema,
|
||||
serializePlaybill,
|
||||
renderPlaybillToHTML,
|
||||
renderPlaybillToJSON,
|
||||
} from "@proscenium/playbill";
|
||||
import chalk from "chalk";
|
||||
import { loadFromBinding, resolveBindingPath } from "#filetypes/binding";
|
||||
import { CLIError, MuseError } from "#lib/errors";
|
||||
import { renderAsHTML } from "#renderers/html";
|
||||
import { loadFromBinding, resolveBindingPath } from "#lib/binding";
|
||||
import { CLIError, FileNotFoundError, MuseError } from "#lib/errors";
|
||||
import { type CLIArguments, parseCLIArguments } from "#util/args";
|
||||
import { getAbsoluteDirname } from "#util/files";
|
||||
import { version } from "../package.json" with { type: "json" };
|
||||
import path from "node:path";
|
||||
|
||||
const usage = `
|
||||
${chalk.bold("muse")} - Compile and validate Playbills for Proscenium
|
||||
|
@ -53,15 +54,33 @@ async function processBinding({ inputFilePath, options }: CLIArguments) {
|
|||
return ExitCode.Success;
|
||||
}
|
||||
|
||||
let css = "";
|
||||
|
||||
if (binding.html?.styles) {
|
||||
for (const style of binding.html.styles) {
|
||||
const cssFilePath = path.resolve(binding.bindingFileDirname, style);
|
||||
const cssFile = Bun.file(cssFilePath);
|
||||
const cssFileExists = await cssFile.exists();
|
||||
|
||||
if (cssFileExists) {
|
||||
css += `${await cssFile.text()}\n`;
|
||||
} else {
|
||||
throw new FileNotFoundError(cssFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -- SERIALIZE USING RENDERER --//
|
||||
let serializedPlaybill = "";
|
||||
|
||||
switch (options.renderer) {
|
||||
case "json":
|
||||
serializedPlaybill = serializePlaybill(validatedPlaybill.data);
|
||||
serializedPlaybill = await renderPlaybillToJSON(validatedPlaybill.data);
|
||||
break;
|
||||
case "html":
|
||||
serializedPlaybill = await renderAsHTML(validatedPlaybill.data, binding);
|
||||
serializedPlaybill = await renderPlaybillToHTML(validatedPlaybill.data, {
|
||||
styles: css,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new CLIError(`Unknown renderer: ${options.renderer}`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue