Files
bun.sh/scripts/glob-sources.mjs
2025-07-21 01:24:59 -07:00

48 lines
1.3 KiB
JavaScript

import { Glob, file, write } from "bun";
import { join, relative, resolve } from "path";
import { normalize } from "path/posix";
const root = resolve(import.meta.dirname, "..");
let total = 0;
async function globSources(output, patterns, excludes = []) {
const paths = [];
for (const pattern of patterns) {
const glob = new Glob(pattern);
for await (const path of glob.scan()) {
if (excludes?.some(exclude => normalize(path) === normalize(exclude))) {
continue;
}
paths.push(path);
}
}
total += paths.length;
const sources =
paths
.map(path => normalize(relative(root, path).replaceAll("\\", "/")))
.sort((a, b) => a.localeCompare(b))
.join("\n")
.trim() + "\n";
await write(join(root, "cmake", "sources", output), sources);
}
const input = await file(join(root, "cmake", "Sources.json")).json();
const start = performance.now();
for (const item of input) {
await globSources(item.output, item.paths, [
...(item.exclude || []),
"src/bun.js/bindings/GeneratedBindings.zig",
"src/bun.js/bindings/GeneratedJS2Native.zig",
]);
}
const end = performance.now();
const green = "\x1b[32m";
const reset = "\x1b[0m";
const bold = "\x1b[1m";
console.log(`\nGlobbed ${bold}${green}${total}${reset} sources [${(end - start).toFixed(2)}ms]`);