UNPKG

express-hale

Version:

🚀 Interactive Express.js scaffold CLI with comprehensive error handling, TypeScript/JavaScript, database integrations, Git Flow, and development tools

63 lines 1.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileUtils = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); /** * 文件操作工具函数 */ class FileUtils { /** * 确保目录存在,如果不存在则创建 */ static async ensureDir(dirPath) { await fs_extra_1.default.ensureDir(dirPath); } /** * 安全地写入文件,确保目录存在 */ static async writeFile(filePath, content) { const dir = path_1.default.dirname(filePath); await this.ensureDir(dir); await fs_extra_1.default.writeFile(filePath, content, 'utf8'); } /** * 检查文件是否存在 */ static async exists(filePath) { return fs_extra_1.default.pathExists(filePath); } /** * 复制文件 */ static async copyFile(src, dest) { const dir = path_1.default.dirname(dest); await this.ensureDir(dir); await fs_extra_1.default.copy(src, dest); } /** * 删除文件或目录 */ static async remove(filePath) { await fs_extra_1.default.remove(filePath); } /** * 读取JSON文件 */ static async readJson(filePath) { return fs_extra_1.default.readJson(filePath); } /** * 写入JSON文件 */ static async writeJson(filePath, data) { const dir = path_1.default.dirname(filePath); await this.ensureDir(dir); await fs_extra_1.default.writeJson(filePath, data, { spaces: 2 }); } } exports.FileUtils = FileUtils; //# sourceMappingURL=file-utils.js.map