import { promises } from 'fs'; import colors from 'colors'; import { Log } from '../../core/index.js'; export function getFileService(log?: Log): FileService { return new FileService(log); } export class FileService { constructor(private readonly log?: Log) {} async loadFileAsync(filename: string): Promise { const filePath = this.getFilePath(filename); this.log?.({ type: 'ReadFs', message: `Reading file '${colors.yellow(filePath)}'` }); const file = await promises.readFile(filePath); return file; } async writeFileAsync(fileNameWithoutExtension: string, content: any): Promise { const filePath = this.getFilePath(fileNameWithoutExtension); this.log?.({ type: 'WriteFs', message: `Writing file '${colors.yellow(filePath)}'` }); await promises.writeFile(filePath, content); } private getFilePath(filename: string) { return `./${filename}`; } }