ConceptCreator/app/SaveProject.ts
Sebastian Böckelmann d56166b245
All checks were successful
E2E Testing / test (push) Successful in 1m31s
Restructure Saving Logic to extra class and save on Strg+S + display changed savestatus in editor
2024-02-17 07:30:29 +01:00

30 lines
961 B
TypeScript

import {StorageModel} from "../src/app/game-model/StorageModel";
import * as fs from "fs";
import * as path from "node:path";
export class SaveProject {
static saveProject(projectDir: string, storageModels: StorageModel[]) {
const directoryPath = 'testModel/'
if(!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath, {recursive: true});
}
storageModels.forEach(storageModel => {
const modelDir = path.join(directoryPath, storageModel.storageDir);
if(!fs.existsSync(modelDir)) {
fs.mkdirSync(modelDir, {recursive: true});
}
const filePath = path.join(directoryPath, storageModel.storageDir, storageModel.fileName + ".json");
fs.writeFile(filePath, storageModel.jsonString ,'utf-8', (err) => {
if (err) {
console.error('Error writing JSON to file:', err);
} else {
console.log('JSON file saved successfully:', filePath);
}
})
})
}
}