Add more flags and verbose logging
This commit is contained in:
parent
4e31f18045
commit
542d28cb53
13 changed files with 406 additions and 135 deletions
|
@ -1,19 +1,59 @@
|
|||
import path from "node:path";
|
||||
import { Glob } from "bun";
|
||||
import YAML from "yaml";
|
||||
import z from "zod";
|
||||
|
||||
const BindingSchema = z.object({
|
||||
$binding: z.literal("playbill"),
|
||||
id: z.string(),
|
||||
playbill: z.string().default("Unnamed playbill"),
|
||||
name: z.string().default("Unnamed playbill"),
|
||||
author: z.string().optional(),
|
||||
version: z.number(),
|
||||
version: z.string(),
|
||||
files: z.array(z.string()).default(["**/*.yaml"]),
|
||||
});
|
||||
|
||||
type Binding = z.infer<typeof BindingSchema>;
|
||||
|
||||
export async function loadBindingFile(filePath: string): Promise<Binding> {
|
||||
export interface PlaybillBinding {
|
||||
info: Binding;
|
||||
bindingPath: string;
|
||||
files: string[];
|
||||
}
|
||||
|
||||
export async function loadBindingFile(
|
||||
filePath: string,
|
||||
): Promise<PlaybillBinding> {
|
||||
const file = Bun.file(filePath);
|
||||
const text = await file.text();
|
||||
const parsed = YAML.parse(text);
|
||||
return BindingSchema.parse(parsed);
|
||||
const binding = BindingSchema.parse(parsed);
|
||||
|
||||
const fileGlobs = binding.files;
|
||||
const bindingFileDirname = filePath.split("/").slice(0, -1).join("/");
|
||||
|
||||
const allFilePaths: string[] = [];
|
||||
|
||||
for (const thisGlob of fileGlobs) {
|
||||
const glob = new Glob(thisGlob);
|
||||
|
||||
const results = glob.scanSync({
|
||||
cwd: bindingFileDirname,
|
||||
absolute: true,
|
||||
followSymlinks: true,
|
||||
onlyFiles: true,
|
||||
});
|
||||
|
||||
allFilePaths.push(...results);
|
||||
}
|
||||
|
||||
const bindingFileAbsolutePath = path.resolve(filePath);
|
||||
const filteredFilePaths = allFilePaths.filter((filePath) => {
|
||||
return filePath !== bindingFileAbsolutePath;
|
||||
});
|
||||
|
||||
return {
|
||||
info: binding,
|
||||
bindingPath: filePath,
|
||||
files: filteredFilePaths,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue