45 lines
2.0 KiB
JavaScript
45 lines
2.0 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.GamesystemStorage = void 0;
|
||
|
const FileUtils_1 = require("../FileUtils");
|
||
|
const path = require("node:path");
|
||
|
const fs = require("fs");
|
||
|
class GamesystemStorage {
|
||
|
constructor(gamesystemRootDir) {
|
||
|
this.gamesystemRootDir = gamesystemRootDir;
|
||
|
}
|
||
|
storeGamesystems(gamesystems) {
|
||
|
this.detectUnusedGamesystemFiles(this.gamesystemRootDir, gamesystems);
|
||
|
gamesystems.forEach(gamesystem => this.storeGamesystem(gamesystem));
|
||
|
}
|
||
|
detectUnusedGamesystemFiles(gamesystemDir, gamesystems) {
|
||
|
const gamesystemFiles = FileUtils_1.FileUtils.listFilesInDirectory(gamesystemDir);
|
||
|
gamesystemFiles.forEach(gamesystemFile => {
|
||
|
if (fs.lstatSync(gamesystemFile).isDirectory()) {
|
||
|
this.detectUnusedGamesystemFiles(gamesystemFile, gamesystems);
|
||
|
}
|
||
|
else {
|
||
|
const currentFileName = path.parse(path.basename(gamesystemFile)).name;
|
||
|
const searchedGamesystem = gamesystems.find(gamesystem => path.basename(gamesystem.fileName) === currentFileName);
|
||
|
if (searchedGamesystem != undefined) {
|
||
|
if (path.dirname(searchedGamesystem.fileName) === currentFileName) {
|
||
|
//Aus Simple wurde Product => Delete .json
|
||
|
fs.unlinkSync(gamesystemFile);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
fs.unlinkSync(gamesystemFile);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
storeGamesystem(gamesystem) {
|
||
|
const gamesystemFile = path.join(...gamesystem.fileName.split("/"));
|
||
|
console.log(gamesystem.jsonString);
|
||
|
const completeGamesystemFile = path.join(this.gamesystemRootDir, gamesystemFile);
|
||
|
FileUtils_1.FileUtils.prepareFileForWriting(completeGamesystemFile);
|
||
|
fs.writeFileSync(completeGamesystemFile + ".json", gamesystem.jsonString, 'utf-8');
|
||
|
}
|
||
|
}
|
||
|
exports.GamesystemStorage = GamesystemStorage;
|
||
|
//# sourceMappingURL=GamesystemStorage.js.map
|