newsletter CRUD & pdf

This commit is contained in:
Julian Krauser 2024-12-25 12:22:28 +01:00
parent e9b29f8acf
commit 01ce3fdd39
31 changed files with 1185 additions and 23 deletions

View file

@ -0,0 +1,31 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { join } from "path";
import { readdirSync } from "fs";
export abstract class FileSystemHelper {
static createFolder(newFolder: string) {
const exportPath = join(process.cwd(), "export", newFolder);
if (!existsSync(exportPath)) {
mkdirSync(exportPath, { recursive: true });
}
}
static readFile(filePath: string) {
return readFileSync(join(process.cwd(), filePath), "utf8");
}
static writeFile(filePath: string, file: any) {
writeFileSync(filePath, file);
}
static formatPath(...args: string[]) {
return join(...args);
}
static getFilesInDirectory(directoryPath: string, filetype?: string): string[] {
const fullPath = join(process.cwd(), directoryPath);
return readdirSync(fullPath, { withFileTypes: true })
.filter((dirent) => !dirent.isDirectory() && (!filetype || dirent.name.endsWith(filetype)))
.map((dirent) => dirent.name);
}
}