Use new playbill updates

This commit is contained in:
Endeavorance 2025-03-21 16:40:47 -04:00
parent c1f3c6cade
commit f7f861a1cb
8 changed files with 81 additions and 210 deletions

View file

@ -21,17 +21,17 @@ enum ExitCode {
}
async function processBinding({ inputFilePath, options }: CLIArguments) {
// -- BINDING FILE -- //
// Load the binding
const bindingPath = await resolveBindingPath(inputFilePath);
const binding = await loadFromBinding(bindingPath);
// -- EXIT EARLY IF JUST CHECKING VALIDATION --//
// If --check is specified, exit early
if (options.check) {
console.log(chalk.green("Playbill validated successfully"));
return ExitCode.Success;
}
// -- SERIALIZE USING RENDERER --//
// Serialize (default: JSON)
let serializedPlaybill = "";
switch (options.renderer) {
@ -48,12 +48,13 @@ async function processBinding({ inputFilePath, options }: CLIArguments) {
throw new CLIError(`Unknown renderer: ${options.renderer}`);
}
// Write to disk if an outfile is specified
// Write to disk if --outfile is specified
if (options.outfile !== "") {
await Bun.write(options.outfile, serializedPlaybill);
return ExitCode.Success;
}
// Otherwise, write to stdout
console.log(serializedPlaybill);
return ExitCode.Success;
}
@ -62,26 +63,27 @@ async function main(): Promise<number> {
const cliArguments = parseCLIArguments(Bun.argv.slice(2));
const { options } = cliArguments;
// -- HELP TEXT -- //
// If --help is specified, print usage and exit
if (options.help) {
console.log(USAGE);
return ExitCode.Success;
}
console.log(`Processing ${cliArguments.inputFilePath}`);
let lastProcessResult = await processBinding(cliArguments);
if (options.watch) {
const watchDir = getAbsoluteDirname(cliArguments.inputFilePath);
console.log(`Watching ${watchDir} for changes`);
console.log(`Watching ${watchDir} for changes...`);
const watcher = watch(watchDir, {
recursive: true,
});
for await (const event of watcher) {
console.log(`Detected ${event.eventType} on ${event.filename}`);
console.log(
`Detected ${event.eventType} on ${event.filename}. Reprocessing...`,
);
try {
lastProcessResult = await processBinding(cliArguments);