MCPcopy Create free account
hub / github.com/everx-labs/everdev / loadJSON

Function loadJSON

src/core/utils.ts:668–692  ·  view source on GitHub ↗
(dataPath: string)

Source from the content-addressed store, hash-verified

666}
667
668export function loadJSON(dataPath: string): any {
669 const [filePath, fieldPath] = dataPath.split("@")
670 const resolvedFilePath = path.resolve(process.cwd(), filePath)
671 let json
672 try {
673 json = JSON.parse(fs.readFileSync(resolvedFilePath, "utf-8"))
674 } catch (err: any) {
675 throw new Error(
676 `Failed to load JSON args from file "${resolvedFilePath}": ${err}`,
677 )
678 }
679 const fields = (fieldPath ?? "")
680 .trim()
681 .split(".")
682 .filter(x => x !== "")
683 for (const field of fields) {
684 json = json[field]
685 if (json === undefined) {
686 throw new Error(
687 `Failed to load JSON args from file "${filePath}": missing required field ${fieldPath}`,
688 )
689 }
690 }
691 return json
692}

Callers 1

parseComponentsMethod · 0.90

Calls 2

parseMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected