* 复制文件 * @param {string} source 源文件路径 * @param {string} target 目标文件路径 * @returns {Promise }
(source, target)
| 131 | * 递归删除目录 |
| 132 | * @param {string} directory 要删除的目录 |
| 133 | * @returns {Promise<void>} |
| 134 | */ |
| 135 | async cleanDirectory(directory) { |
| 136 | try { |
| 137 | if (!fs.existsSync(directory)) { |
| 138 | return; |
| 139 | } |
| 140 | await fsp.rm(directory, { recursive: true, force: true }); |
| 141 | logger.debug(`删除目录: ${directory}`); |
| 142 | } catch (err) { |
| 143 | logger.error(`删除目录 ${directory} 时出错:`, err); |
| 144 | throw err; |
| 145 | } |
| 146 | }, |
| 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * JSON.stringify that breaks cycles instead of throwing. |
| 151 | * Already-seen objects become {"__circular__": true}. |
| 152 | * Prefer resourceProcessor.toIdReferencedArray for Cocos scene graphs. |
| 153 | */ |
| 154 | function safeJsonStringify(value, space = 2) { |
| 155 | const seen = new WeakSet(); |
| 156 | return JSON.stringify( |
| 157 | value, |
| 158 | (key, val) => { |
| 159 | if (val && typeof val === 'object') { |
| 160 | if (seen.has(val)) { |
| 161 | return { __circular__: true }; |
| 162 | } |
| 163 | seen.add(val); |
| 164 | } |
| 165 | return val; |
no test coverage detected