Clean up
This commit is contained in:
parent
45580288e1
commit
8b276cc226
5 changed files with 145 additions and 119 deletions
|
@ -3,31 +3,36 @@ import { Glob } from "bun";
|
|||
import YAML from "yaml";
|
||||
import z from "zod";
|
||||
|
||||
const BindingSchema = z.object({
|
||||
const BindingFileSchema = z.object({
|
||||
$binding: z.literal("playbill"),
|
||||
id: z.string(),
|
||||
name: z.string().default("Unnamed playbill"),
|
||||
author: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
version: z.string(),
|
||||
files: z.array(z.string()).default(["**/*.yaml", "**/*.md"]),
|
||||
});
|
||||
|
||||
type Binding = z.infer<typeof BindingSchema>;
|
||||
type BindingFileContent = z.infer<typeof BindingFileSchema>;
|
||||
|
||||
export interface PlaybillBinding {
|
||||
info: Binding;
|
||||
bindingPath: string;
|
||||
files: string[];
|
||||
_raw: BindingFileContent;
|
||||
bindingFilePath: string;
|
||||
includedFiles: string[];
|
||||
|
||||
id: string;
|
||||
name: string;
|
||||
author: string;
|
||||
version: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export async function loadBindingFile(
|
||||
export function parseBindingFile(
|
||||
text: string,
|
||||
filePath: string,
|
||||
): Promise<PlaybillBinding> {
|
||||
const file = Bun.file(filePath);
|
||||
const text = await file.text();
|
||||
): PlaybillBinding {
|
||||
const parsed = YAML.parse(text);
|
||||
const binding = BindingSchema.parse(parsed);
|
||||
|
||||
const binding = BindingFileSchema.parse(parsed);
|
||||
const fileGlobs = binding.files;
|
||||
const bindingFileDirname = filePath.split("/").slice(0, -1).join("/");
|
||||
|
||||
|
@ -52,8 +57,14 @@ export async function loadBindingFile(
|
|||
});
|
||||
|
||||
return {
|
||||
info: binding,
|
||||
bindingPath: filePath,
|
||||
files: filteredFilePaths,
|
||||
_raw: binding,
|
||||
bindingFilePath: filePath,
|
||||
includedFiles: filteredFilePaths,
|
||||
|
||||
id: binding.id,
|
||||
name: binding.name,
|
||||
author: binding.author ?? "Anonymous",
|
||||
description: binding.description ?? "",
|
||||
version: binding.version,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue