Muse owns muse-shaped files now
This commit is contained in:
parent
3e2ab6ec73
commit
bf444ccb1a
23 changed files with 1288 additions and 201 deletions
48
src/index.ts
48
src/index.ts
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue