Improved HTML output
This commit is contained in:
parent
d8ddff01a6
commit
2032103412
16 changed files with 480 additions and 105 deletions
34
src/index.ts
34
src/index.ts
|
@ -1,9 +1,13 @@
|
|||
import { parseArgs } from "node:util";
|
||||
import { ValidatedPlaybillSchema } from "@proscenium/playbill";
|
||||
import {
|
||||
serializePlaybill,
|
||||
ValidatedPlaybillSchema,
|
||||
} from "@proscenium/playbill";
|
||||
import chalk from "chalk";
|
||||
import { loadFromBinding, resolveBindingPath } from "./binding";
|
||||
import { usage } from "./usage";
|
||||
import { CLIError, MuseError } from "./errors";
|
||||
import { renderAsHTML } from "./renderers/html";
|
||||
|
||||
enum ExitCode {
|
||||
Success = 0,
|
||||
|
@ -45,6 +49,11 @@ async function main(): Promise<number> {
|
|||
default: false,
|
||||
type: "boolean",
|
||||
},
|
||||
renderer: {
|
||||
short: "r",
|
||||
default: "json",
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
|
@ -103,20 +112,27 @@ async function main(): Promise<number> {
|
|||
return ExitCode.Success;
|
||||
}
|
||||
|
||||
// -- SERIALIZE TO JSON --//
|
||||
const finalizedPlaybill = JSON.stringify(
|
||||
validatedPlaybill.data,
|
||||
null,
|
||||
options.minify ? undefined : 2,
|
||||
);
|
||||
// -- SERIALIZE USING RENDERER --//
|
||||
let serializedPlaybill = "";
|
||||
|
||||
switch (options.renderer) {
|
||||
case "json":
|
||||
serializedPlaybill = serializePlaybill(validatedPlaybill.data);
|
||||
break;
|
||||
case "html":
|
||||
serializedPlaybill = await renderAsHTML(validatedPlaybill.data, binding);
|
||||
break;
|
||||
default:
|
||||
throw new CLIError(`Unknown renderer: ${options.renderer}`);
|
||||
}
|
||||
|
||||
// -- WRITE TO DISK OR STDOUT --//
|
||||
if (options.write) {
|
||||
await Bun.write(options.outfile, finalizedPlaybill);
|
||||
await Bun.write(options.outfile, serializedPlaybill);
|
||||
return ExitCode.Success;
|
||||
}
|
||||
|
||||
console.log(finalizedPlaybill);
|
||||
console.log(serializedPlaybill);
|
||||
return ExitCode.Success;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue