ConceptCreator/app/storage/storing/ItemgroupStorage.js
Sebastian Böckelmann ddcbfc5bb3
All checks were successful
E2E Testing / test (push) Successful in 1m40s
Persist Items independly from Itemgroups
2024-05-09 10:10:55 +02:00

31 lines
1.3 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);
console.log(completeItemgroupDirectory);
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