Skip to main content
This release is 3 versions behind 0.3.6 — the latest version of @disjukr/bdl. Jump to latest

TypeScript implementation of BDL. You can use this library to implement your own BDL code generation.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
58%
Published
4 months ago (0.3.3)
Package root>cli>ir-builder.ts
import { walkSync } from "jsr:@std/fs/walk"; import { parse } from "jsr:@std/yaml"; import { dirname, relative, resolve } from "node:path"; import { pathToFileURL } from "node:url"; import { buildBdlIr } from "../src/ir-builder.ts"; const [configPath] = Deno.args; if (!configPath) { console.error("No config path provided."); Deno.exit(1); } const configDirectory = dirname(resolve(configPath)); interface ConfigYml { paths: Record<string, string>; } const configYmlText = await Deno.readTextFile(configPath); const configYml = parse(configYmlText, { schema: "json" }) as ConfigYml; const entryModulePaths = Object.entries(configYml.paths).flatMap( ([packageName, directoryPath]) => { const resolvedDirectoryPath = resolve(configDirectory, directoryPath); const bdlFiles = Array.from( walkSync(resolvedDirectoryPath, { exts: ["bdl"], includeDirs: false, includeSymlinks: false, }), ).map((entry) => relative(resolvedDirectoryPath, entry.path)); return bdlFiles .map((path) => path.replace(/\.bdl$/, "").split("/")) .filter((names) => names.every((name) => name.match(/^[a-z_][a-z0-9_]*$/i)) ) .map((names) => [packageName, ...names].join(".")); }, ); const result = await buildBdlIr({ entryModulePaths, resolveModuleFile: async (modulePath) => { const [packageName, ...fragments] = modulePath.split("."); const directoryPath = configYml.paths[packageName]; const resolvedDirectoryPath = resolve(configDirectory, directoryPath); const filePath = resolve( resolvedDirectoryPath, fragments.join("/") + ".bdl", ); const fileUrl = pathToFileURL(filePath).toString(); const text = await Deno.readTextFile(filePath); return { fileUrl, text }; }, }); console.log(JSON.stringify(result.ir, null, 2));