MCPcopy Create free account
hub / github.com/EmNudge/watlings / findFile

Function findFile

scripts/utils/findFile.mjs:6–23  ·  view source on GitHub ↗
(stub, dir)

Source from the content-addressed store, hash-verified

4
5/** @param {string} stub @param {'exercises' | 'patch' | 'tests'} dir */
6export async function findFile(stub, dir) {
7 const folderFiles = await readdir(
8 fileURLToPath(new URL(`../../${dir}`, import.meta.url))
9 );
10
11 const targetFileName = basename(stub, extname(stub));
12
13 const sourceFileNameWithExt = folderFiles.find((fileName) => {
14 if (dir === "exercises" && !fileName.endsWith(".wat")) return false;
15 if (dir === "patch" && !fileName.endsWith(".patch")) return false;
16 if (dir === "tests" && !fileName.endsWith(".test.js")) return false;
17
18 return fileName.includes(targetFileName);
19 });
20
21 /** @type {string | undefined} */
22 return sourceFileNameWithExt;
23}

Callers 3

test.mjsFile · 0.90
show-solution.mjsFile · 0.90
patchFileFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected