36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
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)
|
|
FileUtils.prepareDirectoryFroWriting(completeItemgroupDirectory);
|
|
fs.writeFileSync(completeFileName + ".json", itemgroup.jsonString, "utf-8")
|
|
}
|
|
|
|
|
|
storeItems(storedItems: StoreComponent[]) {
|
|
storedItems.forEach(item => this.storeItemgroup(item))
|
|
}
|
|
}
|