Skip to content

Commit

Permalink
Add implementation for Brioche.glob global function (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewlacy authored May 26, 2024
1 parent 404c4de commit 3299c79
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions projects/std/core/global.bri
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { source } from "./source.bri";
export interface BriocheGlobal {
includeFile(path: string): Recipe<File>;
includeDirectory(path: string): Recipe<Directory>;
glob(...patterns: string[]): Recipe<Directory>;
}

(globalThis as any).Brioche ??= {};
Expand Down Expand Up @@ -58,3 +59,26 @@ export interface BriocheGlobal {
},
});
};
(globalThis as any).Brioche.glob ??= (
...patterns: string[]
): Recipe<Directory> => {
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,
},
);
},
});
};

0 comments on commit 3299c79

Please sign in to comment.