mirror of
https://github.com/donovanglover/nix-config.git
synced 2024-11-24 17:23:09 +01:00
0976968977
Also uses "async function" since I personally find that easier to skim and know that it's a function.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
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) {
|
|
if (walkEntry.path.includes("default.nix")) continue
|
|
files.push(walkEntry.path)
|
|
}
|
|
}
|
|
|
|
return files
|
|
}
|
|
|
|
async function getImportsInFile(file: string): Promise<string[]> {
|
|
const text = await Deno.readTextFile(file);
|
|
const lines = text.split("\n")
|
|
const imports = [];
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
if (lines[i].includes("./")) {
|
|
imports.push(file.split("./")[1].split("/")[0] + "/" + lines[i].split("./")[1].split(" ")[0])
|
|
}
|
|
}
|
|
|
|
return imports
|
|
}
|
|
|
|
async function assertAllModulesInDirectory(directory: string) {
|
|
const files = await getFilesInDirectory(`./${directory}`)
|
|
const imports = await getImportsInFile(`./${directory}/default.nix`)
|
|
|
|
console.log(files)
|
|
console.log(imports)
|
|
|
|
for (const file of files) {
|
|
assert(imports.includes(file))
|
|
}
|
|
}
|
|
|
|
Deno.test("imports all modules in ./packages", async () => {
|
|
await assertAllModulesInDirectory("packages")
|
|
})
|