ConceptCreator/app/storage/storing/ItemgroupStorage.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-05-09 09:12:46 +02:00
import {FileUtils} from "../FileUtils";
import {StoreComponent} from "../StoreComponent";
import * as path from "node:path";
import * as fs from "node:fs";
export class ItemgroupStorage {
private itemgroupDir: string
constructor(itemgroupDir: string) {
this.itemgroupDir = itemgroupDir;
FileUtils.prepareDirectoryFroWriting(this.itemgroupDir);
}
public storeItemgroups(itemgroups: StoreComponent[]) {
itemgroups.forEach(itemgroup => {
this.storeItemgroup(itemgroup)
})
}
private storeItemgroup(itemgroup: StoreComponent) {
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.prepareDirectoryFroWriting(completeItemgroupDirectory);
fs.writeFileSync(completeFileName + ".json", itemgroup.jsonString, "utf-8")
}
storeItems(storedItems: StoreComponent[]) {
storedItems.forEach(item => this.storeItemgroup(item))
}
2024-05-09 09:12:46 +02:00
}