2024-03-19 17:03:07 +01:00
|
|
|
import * as path from "node:path";
|
|
|
|
import * as fs from "fs";
|
2024-03-19 17:55:11 +01:00
|
|
|
import {json} from "node:stream/consumers";
|
2024-03-19 17:03:07 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2024-03-19 17:55:11 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2024-03-19 17:03:07 +01:00
|
|
|
}
|