newsletter CRUD & pdf
This commit is contained in:
parent
e9b29f8acf
commit
01ce3fdd39
31 changed files with 1185 additions and 23 deletions
31
src/helpers/fileSystemHelper.ts
Normal file
31
src/helpers/fileSystemHelper.ts
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue