feat: add domain core and verification harness
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { readdir, readFile, stat } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
export const repositoryRoot = path.resolve(import.meta.dirname, "..");
|
||||
|
||||
const excludedDirectories = new Set([
|
||||
".git",
|
||||
".gradle",
|
||||
".idea",
|
||||
"build",
|
||||
"node_modules",
|
||||
]);
|
||||
|
||||
export async function walkFiles(directory = repositoryRoot) {
|
||||
const result = [];
|
||||
const entries = await readdir(directory, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
if (entry.isDirectory() && excludedDirectories.has(entry.name)) continue;
|
||||
const absolutePath = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
result.push(...(await walkFiles(absolutePath)));
|
||||
} else if (entry.isFile()) {
|
||||
result.push(absolutePath);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function readTextFileIfSmall(file, maximumBytes = 2_000_000) {
|
||||
const metadata = await stat(file);
|
||||
if (metadata.size > maximumBytes) return null;
|
||||
const buffer = await readFile(file);
|
||||
if (buffer.includes(0)) return null;
|
||||
return buffer.toString("utf8");
|
||||
}
|
||||
|
||||
export function relative(file) {
|
||||
return path.relative(repositoryRoot, file).replaceAll(path.sep, "/");
|
||||
}
|
||||
Reference in New Issue
Block a user