MCPcopy Create free account
hub / github.com/Gin-Quin/gravity / readFileSystem

Function readFileSystem

packages/gravity/scripts/utilities/readFileSystem.ts:15–32  ·  view source on GitHub ↗
(
	path: string,
)

Source from the content-addressed store, hash-verified

13 * If path is a directory, return an object with directory's contents.
14 */
15export async function readFileSystem(
16 path: string,
17): Promise<FileSystemEntity | undefined> {
18 if (!fs.existsSync(path)) return undefined;
19 if (fs.statSync(path).isDirectory()) {
20 const directory: FileSystemDirectory = {};
21 for (const file of fs.readdirSync(path)) {
22 const content = await readFileSystem(join(path, file));
23 if (content) directory[file] = content;
24 }
25 return directory;
26 } else {
27 const file = await open(path, "r");
28 const content = await file.readFile("utf-8");
29 file.close();
30 return content;
31 }
32}

Callers 1

generateFunction · 0.90

Calls 1

closeMethod · 0.80

Tested by

no test coverage detected