Muse owns muse-shaped files now

This commit is contained in:
Endeavorance 2025-03-17 17:20:30 -04:00
parent 3e2ab6ec73
commit bf444ccb1a
23 changed files with 1288 additions and 201 deletions

View file

@ -1,16 +1,13 @@
import { watch } from "node:fs/promises";
import {
PlaybillSchema,
renderPlaybillToHTML,
renderPlaybillToJSON,
} from "@proscenium/playbill";
import chalk from "chalk";
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 { CLIError, MuseError, loadFromBinding, resolveBindingPath } from "#lib";
import { renderPlaybillToHTML } from "#render/html";
import {
type CLIArguments,
getAbsoluteDirname,
parseCLIArguments,
} from "#util";
import { version } from "../package.json" with { type: "json" };
import path from "node:path";
const usage = `
${chalk.bold("muse")} - Compile and validate Playbills for Proscenium
@ -39,47 +36,22 @@ async function processBinding({ inputFilePath, options }: CLIArguments) {
const bindingPath = await resolveBindingPath(inputFilePath);
const binding = await loadFromBinding(bindingPath);
// -- VALDATE PLAYBILL -- //
const validatedPlaybill = PlaybillSchema.safeParse(binding.playbill);
if (!validatedPlaybill.success) {
console.error("Error validating playbill");
console.error(validatedPlaybill.error.errors);
return ExitCode.Error;
}
// -- EXIT EARLY IF JUST CHECKING VALIDATION --//
if (options.check) {
console.log(chalk.green("Playbill validated successfully"));
return ExitCode.Success;
}
let css = "";
if (binding.styles && binding.styles.length > 0) {
for (const style of binding.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 = await renderPlaybillToJSON(validatedPlaybill.data);
serializedPlaybill = binding.playbill.serialize();
break;
case "html":
serializedPlaybill = await renderPlaybillToHTML(validatedPlaybill.data, {
styles: css,
serializedPlaybill = await renderPlaybillToHTML(binding.playbill, {
styles: binding.styles,
});
break;
default: