2023-08-31 17:50:03 +02:00
|
|
|
import { assert } from "https://deno.land/std@0.200.0/assert/mod.ts";
|
|
|
|
import { walk } from "https://deno.land/std@0.200.0/fs/walk.ts";
|
|
|
|
|
|
|
|
async function getFilesInDirectory(directory: string): Promise<string[]> {
|
|
|
|
const files = [];
|
|
|
|
|
|
|
|
for await (const walkEntry of walk(directory)) {
|
|
|
|
if (walkEntry.isFile) {
|
2023-08-31 17:51:44 +02:00
|
|
|
if (walkEntry.path.includes("default.nix")) continue;
|
|
|
|
files.push(walkEntry.path);
|
2023-08-31 17:50:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 17:51:44 +02:00
|
|
|
return files;
|
2023-08-31 17:50:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getImportsInFile(file: string): Promise<string[]> {
|
|
|
|
const text = await Deno.readTextFile(file);
|
2023-08-31 17:51:44 +02:00
|
|
|
const lines = text.split("\n");
|
2023-08-31 17:50:03 +02:00
|
|
|
const imports = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
if (lines[i].includes("./")) {
|
2023-08-31 17:51:44 +02:00
|
|
|
imports.push(
|
|
|
|
file.split("./")[1].split("/")[0] + "/" +
|
|
|
|
lines[i].split("./")[1].split(" ")[0],
|
|
|
|
);
|
2023-08-31 17:50:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 17:51:44 +02:00
|
|
|
return imports;
|
2023-08-31 17:50:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function assertAllModulesInDirectory(directory: string) {
|
2023-08-31 17:51:44 +02:00
|
|
|
const files = await getFilesInDirectory(`./${directory}`);
|
|
|
|
const imports = await getImportsInFile(`./${directory}/default.nix`);
|
2023-08-31 17:50:03 +02:00
|
|
|
|
|
|
|
for (const file of files) {
|
2023-08-31 17:51:44 +02:00
|
|
|
assert(imports.includes(file));
|
2023-08-31 17:50:03 +02:00
|
|
|
}
|
|
|
|
}
|