/** * 递归创建目录(同步方法) * 如果目录已存在则直接返回,否则递归创建父目录 * @param dirname - 要创建的目录路径 * @returns 创建成功返回 true * @example * ```ts * mkDirsSync('/path/to/new/directory'); * ``` */ export declare function mkDirsSync(dirname: string): boolean; /** * 拷贝目录以及子文件 * 递归复制整个目录结构,包括所有子目录和文件 * @param src - 源目录路径 * @param dist - 目标目录路径 * @param callback - 可选的回调函数,复制完成后执行 * @example * ```ts * copyDir('/source/path', '/target/path', () => { * console.log('复制完成'); * }); * ``` */ export declare function copyDir(src: string, dist: string, callback?: Function): void; /** * 删除目录及其所有内容 * 递归删除目录下的所有文件和子目录 * @param tPath - 要删除的目录路径 * @example * ```ts * deleteFolder('/path/to/folder'); * ``` */ export declare function deleteFolder(tPath: string): void; /** * 递归删除空目录 * 从指定路径开始,递归删除所有空目录(不删除包含文件的目录) * @param tPath - 要检查和删除的目录路径 * @param level - 当前递归层级,默认为 0(根层级不会被删除) * @example * ```ts * rmEmptyDir('/path/to/check'); * ``` */ export declare function rmEmptyDir(tPath: string, level?: number): void; /** * 递归删除文件夹(可配置是否删除文件) * 递归遍历目录,根据配置决定是否删除文件,并删除空目录 * @param path - 要处理的目录路径 * @param options - 配置选项 * @param options.deleteFile - 是否删除文件,默认为 false * @param options.log - 是否输出日志,默认为 false * @example * ```ts * // 只删除空目录 * deleteFolderRecursive('/path/to/folder'); * * // 删除所有文件和目录 * deleteFolderRecursive('/path/to/folder', { deleteFile: true, log: true }); * ``` */ export declare function deleteFolderRecursive(path: string, options?: { deleteFile: boolean; log: boolean; }): void; /** * 拷贝单个文件 * 将文件从源路径复制到目标路径 * @param from - 源文件路径 * @param to - 目标文件路径 * @returns 写入操作的结果 * @example * ```ts * copyFile('/source/file.txt', '/target/file.txt'); * ``` */ export declare function copyFile(from: string, to: string): void; /** * 递归遍历文件夹,并对每个文件执行回调函数 * 遍历目录树,对每个文件(非目录)执行指定的回调函数 * @param cb - 回调函数,接收文件路径作为参数 * @param tPath - 要遍历的文件夹或文件路径 * @example * ```ts * traverseFolder((filePath) => { * console.log('处理文件:', filePath); * }, '/path/to/folder'); * ``` */ export declare function traverseFolder(cb: Function, tPath: string): void; /** * 从日志目录读取 JSON 文件 * 读取 ./log 目录下的 JSON 文件内容 * @param file - 文件名(相对于 log 目录) * @param defaultContent - 文件不存在时返回的默认内容,默认为 '{}' * @returns JSON 文件内容字符串 * @example * ```ts * const content = readJsonLog('data.json', '[]'); * ``` */ export declare function readJsonLog(file: string, defaultContent?: string): any; /** * 获取 JSON 日志目录的绝对路径 * @returns 日志目录的绝对路径 * @example * ```ts * const logDir = getJsonLogDir(); * console.log(logDir); // /path/to/project/log * ``` */ export declare function getJsonLogDir(): string; /** * 将 JSON 对象保存到日志文件 * 将对象序列化为 JSON 并保存到 ./log 目录下 * @param content - 要保存的对象内容 * @param file - 文件名(相对于 log 目录) * @param needLog - 是否需要保存日志,默认为 true * @example * ```ts * saveJsonToLog({ status: 'success', data: [1, 2, 3] }, 'result.json'); * ``` */ export declare function saveJsonToLog(content: object, file: string, needLog?: boolean): void; /** * 将内容追加保存到日志文件(支持保留历史记录) * 以数组形式保存多条日志记录,每条记录包含时间戳和数据,支持限制最大记录数 * @param content - 要保存的内容 * @param file - 文件名(相对于 log 目录) * @param options - 配置选项 * @param options.needLog - 是否需要保存日志,默认为 true * @param options.max - 最大保留记录数,默认为 10 * @example * ```ts * saveJsonToLogMore({ action: 'upload', status: 'success' }, 'history.json', { * needLog: true, * max: 20 * }); * ``` */ export declare function saveJsonToLogMore(content: any, file: string, options?: { needLog?: boolean; max?: number; }): void; /** * 从日志目录读取并解析 JSON 文件 * 读取 ./log 目录下的 JSON 文件并解析为对象 * @param file - 文件名(相对于 log 目录) * @returns 解析后的 JSON 对象,解析失败或文件不存在时返回空对象 * @example * ```ts * const data = getJsonFromLog('config.json'); * console.log(data); * ``` */ export declare function getJsonFromLog(file: string): {}; /** * 从文件路径中提取文件名(不含扩展名) * @param file - 文件路径 * @returns 不含扩展名的文件名 * @example * ```ts * const name = getFileName('/path/to/file.txt'); * console.log(name); // 'file' * ``` */ export declare function getFileName(file: string): string; /** * 解析 JSON 字符串为对象 * 安全地解析 JSON 字符串,解析失败时输出错误信息并返回空对象 * @param content - JSON 字符串内容 * @param file - 文件路径(用于错误日志) * @returns 解析后的对象,解析失败时返回空对象 * @example * ```ts * const data = readJson('{"name":"test"}', 'config.json'); * console.log(data); // { name: 'test' } * ``` */ export declare function readJson(content: string, file: string): Record;