-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement region browsing, rename to "Habitat Inspector"
- Loading branch information
1 parent
6d71b0c
commit 9a38c4d
Showing
10 changed files
with
250 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fs from 'node:fs/promises' | ||
import { parseHabitatObject } from "../neohabitat.js" | ||
|
||
const buildJsonList = async (directory, jsonList) => { | ||
for (const dirent of (await fs.readdir(directory, { withFileTypes: true }))) { | ||
if (dirent.isFile() && dirent.name.endsWith(".json")) { | ||
jsonList.push(`${directory}/${dirent.name}`) | ||
} else if (dirent.isDirectory()) { | ||
await buildJsonList(`${directory}/${dirent.name}`, jsonList) | ||
} | ||
} | ||
} | ||
|
||
const buildContextMap = async (filenames) => { | ||
const contextMap = {} | ||
for (const filename of filenames) { | ||
const data = await fs.readFile(filename, { encoding: "utf-8" }) | ||
const objects = parseHabitatObject(data) | ||
if (Array.isArray(objects)) { | ||
for (const obj of objects) { | ||
if (obj.type == "context") { | ||
contextMap[obj.ref] = { | ||
filename: filename.replace(/^\.\//, "db/"), | ||
name: obj.name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return contextMap | ||
} | ||
|
||
const saveContextMap = async () => { | ||
const filenames = [] | ||
await buildJsonList(".", filenames) | ||
const contextMap = await buildContextMap(filenames) | ||
await fs.writeFile("contextmap.json", JSON.stringify(contextMap)) | ||
} | ||
|
||
saveContextMap() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.