From 3299c79e792fbaaa021a6ba3fc5730bc6622da32 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Sun, 26 May 2024 13:22:32 -0700 Subject: [PATCH] Add implementation for `Brioche.glob` global function (#10) --- projects/std/core/global.bri | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/projects/std/core/global.bri b/projects/std/core/global.bri index 9427796..f7f7ba5 100644 --- a/projects/std/core/global.bri +++ b/projects/std/core/global.bri @@ -9,6 +9,7 @@ import { source } from "./source.bri"; export interface BriocheGlobal { includeFile(path: string): Recipe; includeDirectory(path: string): Recipe; + glob(...patterns: string[]): Recipe; } (globalThis as any).Brioche ??= {}; @@ -58,3 +59,26 @@ export interface BriocheGlobal { }, }); }; +(globalThis as any).Brioche.glob ??= ( + ...patterns: string[] +): Recipe => { + const sourceFrame = source({ depth: 1 }).at(0); + if (sourceFrame === undefined) { + throw new Error(`Could not find source file to resolve glob`); + } + + const sourceFile = sourceFrame.fileName; + + return createRecipe(["directory"], { + sourceDepth: 1, + briocheSerialize: async () => { + return await (globalThis as any).Deno.core.ops.op_brioche_get_static( + sourceFile, + { + type: "glob", + patterns, + }, + ); + }, + }); +};