{"version":3,"file":"core-file-ops-CkY4H0C_.cjs","sources":["../src/core/FileOperations.ts"],"sourcesContent":["import { promises as fs, type Stats } from 'fs'\nimport { join } from 'path'\nimport type { Dirent, Mode, ObjectEncodingOptions, OpenMode } from 'node:fs'\nimport type { Abortable } from 'node:events'\nimport type Stream from 'node:stream'\n\n/**\n * 文件操作工具类\n * 提供通用的文件和目录操作方法\n */\nexport class FileOperations {\n  // 读取文件\n  static async readFile(filePath: string): Promise<string> {\n    return await fs.readFile(filePath, 'utf-8')\n  }\n\n  // 写入文件\n  static async writeFile(\n    filePath: string,\n    content:\n      | string\n      | NodeJS.ArrayBufferView\n      | Iterable<string | NodeJS.ArrayBufferView>\n      | AsyncIterable<string | NodeJS.ArrayBufferView>\n      | Stream,\n    options:\n      | (ObjectEncodingOptions & {\n          mode?: Mode | undefined\n          flag?: OpenMode | undefined\n          flush?: boolean | undefined\n        } & Abortable)\n      | BufferEncoding\n      | null = 'utf-8'\n  ): Promise<void> {\n    await fs.writeFile(filePath, content, options)\n  }\n\n  // 文件重命名\n  static async rename(oldPath: string, newPath: string): Promise<void> {\n    await fs.rename(oldPath, newPath)\n  }\n\n  /**\n   * 递归复制目录\n   */\n  static async copyDirectory(source: string, target: string): Promise<void> {\n    await FileOperations.ensureDir(target)\n\n    const entries = await FileOperations.readDirWithFileTypes(source)\n\n    for (const entry of entries) {\n      const sourcePath = join(source, entry.name)\n      const targetPath = join(target, entry.name)\n\n      if (entry.isDirectory()) {\n        await FileOperations.copyDirectory(sourcePath, targetPath)\n      } else {\n        await fs.copyFile(sourcePath, targetPath)\n      }\n    }\n  }\n\n  /**\n   * 检查文件或目录是否存在\n   */\n  static async exists(path: string): Promise<boolean> {\n    try {\n      await fs.access(path)\n      return true\n    } catch {\n      return false\n    }\n  }\n\n  /**\n   * 确保目录存在，如果不存在则创建\n   */\n  static async ensureDir(dirPath: string): Promise<void> {\n    await fs.mkdir(dirPath, { recursive: true })\n  }\n\n  /**\n   * 复制单个文件\n   */\n  static async copyFile(source: string, target: string): Promise<void> {\n    await fs.copyFile(source, target)\n  }\n\n  // 设置执行权限（在Unix系统上）\n  static async setExecutable(filePath: string, mode: number): Promise<void> {\n    try {\n      await fs.chmod(filePath, mode)\n    } catch {\n      // Windows系统可能不支持chmod，忽略错误\n    }\n  }\n\n  /**\n   * 读取目录内容\n   */\n  static async readDir(dirPath: string): Promise<string[]> {\n    try {\n      return await fs.readdir(dirPath)\n    } catch {\n      return []\n    }\n  }\n\n  /**\n   * 读取目录内容（包含文件类型信息）\n   */\n  static async readDirWithFileTypes(dirPath: string): Promise<Dirent[] | []> {\n    try {\n      return await fs.readdir(dirPath, { withFileTypes: true })\n    } catch {\n      return []\n    }\n  }\n\n  /**\n   * 获取文件统计信息\n   */\n  static async stat(path: string): Promise<Stats | null> {\n    try {\n      return await fs.stat(path)\n    } catch {\n      return null\n    }\n  }\n\n  /**\n   * 检查路径是否为目录\n   */\n  static async isDirectory(path: string): Promise<boolean> {\n    try {\n      const stat = await fs.stat(path)\n      return stat.isDirectory()\n    } catch {\n      return false\n    }\n  }\n\n  /**\n   * 检查路径是否为文件\n   */\n  static async isFile(path: string): Promise<boolean> {\n    try {\n      const stat = await fs.stat(path)\n      return stat.isFile()\n    } catch {\n      return false\n    }\n  }\n}\n"],"names":["FileOperations","readFile","filePath","fs","writeFile","content","options","rename","oldPath","newPath","copyDirectory","source","target","ensureDir","entries","readDirWithFileTypes","entry","sourcePath","join","name","targetPath","isDirectory","copyFile","exists","path","access","dirPath","mkdir","recursive","setExecutable","mode","chmod","readDir","readdir","withFileTypes","stat","isFile"],"mappings":"qDAUO,MAAMA,EAEX,qBAAaC,CAASC,GACpB,aAAaC,EAAAA,SAAGF,SAASC,EAAU,QACrC,CAGA,sBAAaE,CACXF,EACAG,EAMAC,EAOW,eAELH,EAAAA,SAAGC,UAAUF,EAAUG,EAASC,EACxC,CAGA,mBAAaC,CAAOC,EAAiBC,SAC7BN,WAAGI,OAAOC,EAASC,EAC3B,CAKA,0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