ConceptCreator/app/DeleteModel.ts
Sebastian Böckelmann b62f93bfd5
All checks were successful
E2E Testing / test (push) Successful in 1m36s
Delete Gamesystems from Filesystem
2024-03-19 17:55:11 +01:00

51 lines
1.7 KiB
TypeScript

import * as path from "node:path";
import * as fs from "fs";
import {json} from "node:stream/consumers";
export class DeleteTransaction {
static deleteScriptAccount(projectDir: string, componentName: string) {
const filename = path.join(projectDir, "script-accounts", componentName + ".json")
fs.unlinkSync(filename)
console.log("Delete ", filename)
}
static deleteGamesystem(projectDir: string, componentName: string) {
const gamesystemDir = path.join(projectDir, "gamesystems")
const gamesystemFile = this.findGamesystemPath(gamesystemDir, componentName)
try {
if(gamesystemFile != undefined) {
console.log("Delete Gamesystem under File: ", gamesystemFile)
if(fs.lstatSync(gamesystemFile).isDirectory()) {
fs.rmSync(gamesystemFile, {recursive: true, force: true})
} else {
fs.unlinkSync(gamesystemFile)
}
}
}catch (e) {
console.log(e)
}
}
static findGamesystemPath(gamesystemRootDir: string, searchedFilename: string) {
const directoriesToProcess: string[] = [];
directoriesToProcess.push(gamesystemRootDir);
while(directoriesToProcess.length > 0) {
const currentDirectory = directoriesToProcess.shift();
const filesInDirectory = fs.readdirSync(currentDirectory!)
for(let i=0; i<filesInDirectory.length; i++) {
const currentFile = path.join(currentDirectory!, filesInDirectory[i])
if(fs.lstatSync(currentFile).isDirectory()) {
directoriesToProcess.push(currentFile);
}
if(path.parse(path.basename(currentFile)).name === searchedFilename) {
return currentFile;
}
}
}
return undefined
}
}