ConceptCreator/app/storage/storing/ItemgroupStorage.js
Sebastian Böckelmann 73edf03fa0
All checks were successful
E2E Testing / test (push) Successful in 1m37s
Load Itemgroups
2024-05-09 13:33:26 +02:00

30 lines
1.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ItemgroupStorage = void 0;
const FileUtils_1 = require("../FileUtils");
const path = require("node:path");
const fs = require("node:fs");
class ItemgroupStorage {
constructor(itemgroupDir) {
this.itemgroupDir = itemgroupDir;
FileUtils_1.FileUtils.prepareDirectoryFroWriting(this.itemgroupDir);
}
storeItemgroups(itemgroups) {
itemgroups.forEach(itemgroup => {
this.storeItemgroup(itemgroup);
});
}
storeItemgroup(itemgroup) {
const file = path.join(...itemgroup.fileName.split("/"));
const completeFileName = path.join(this.itemgroupDir, file);
const itemgroupDirectory = path.join(...itemgroup.fileName.split("/").slice(0, -1));
const completeItemgroupDirectory = path.join(this.itemgroupDir, itemgroupDirectory);
FileUtils_1.FileUtils.prepareDirectoryFroWriting(completeItemgroupDirectory);
fs.writeFileSync(completeFileName + ".json", itemgroup.jsonString, "utf-8");
}
storeItems(storedItems) {
storedItems.forEach(item => this.storeItemgroup(item));
}
}
exports.ItemgroupStorage = ItemgroupStorage;
//# sourceMappingURL=ItemgroupStorage.js.map