MCPcopy Create free account
hub / github.com/IceClusters/icmysql / InitData

Function InitData

src/json/Load.js:7–25  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5var loadingData = true;
6
7async function InitData() {
8 if (!await DirExist(Config.SaveDirPath)) {
9 await CreateIfNotExist(Config.SaveDirPath + `/${global.resourceName}.json`, "{}");
10 }
11
12 ReadDir(Config.SaveDirPath).then(async function (files) {
13 let promises = [];
14 for (let i = 0; i < files.length; i++) {
15 if (!files[i].endsWith(".json")) continue;
16 let fileName = files[i].replace(".json", "");
17 promises.push(ReadFile(Config.SaveDirPath + "/" + files[i]).then(function (data) {
18 loadedData[fileName] = JSON.parse(data);
19 }));
20 }
21 await Promise.all(promises);
22 loadingData = false;
23 Log(LogTypes.Debug, `Loaded data from: ${files.map(file => file.replace(".json", "")).join(", ")}`);
24 });
25}
26
27// module.exports = { InitData }

Callers

nothing calls this directly

Calls 5

DirExistFunction · 0.85
CreateIfNotExistFunction · 0.85
ReadDirFunction · 0.85
ReadFileFunction · 0.85
LogFunction · 0.85

Tested by

no test coverage detected