🚑 hotfix: seeding system

This commit is contained in:
2026-01-29 02:40:25 +07:00
parent e305d955f1
commit 5bfb376e88
5 changed files with 77 additions and 39 deletions

View File

@ -0,0 +1,28 @@
import fs from "fs";
import path from "path";
interface CreateFileConfig {
targetDir: string;
fileName: string;
overwriteIfExists?: boolean;
}
export const createFile = async (content: string, config: CreateFileConfig) => {
const targetDir = path.join(process.cwd(), config.targetDir);
const targetFile = path.join(targetDir, config.fileName);
// If file exists and overwrite is not allowed, throw an error
if (fs.existsSync(targetFile) && !config.overwriteIfExists) {
throw new Error(
`File ${config.fileName} already exists in ${config.targetDir}`,
);
}
// Ensure target directory exists
if (!fs.existsSync(targetDir)) {
await fs.promises.mkdir(targetDir, { recursive: true });
}
// Write content to the file
await fs.promises.writeFile(targetFile, content, "utf8");
};