| 45 | } |
| 46 | |
| 47 | async function copyDirectory(source, destination) { |
| 48 | try { |
| 49 | await fs.promises.mkdir(destination, { recursive: true }); |
| 50 | const entries = await fs.promises.readdir(source, { withFileTypes: true }); |
| 51 | |
| 52 | for (const entry of entries) { |
| 53 | const srcPath = path.join(source, entry.name); |
| 54 | const destPath = path.join(destination, entry.name); |
| 55 | |
| 56 | try { |
| 57 | if (entry.isDirectory()) { |
| 58 | await copyDirectory(srcPath, destPath); |
| 59 | } else if (entry.isFile()) { |
| 60 | await fs.promises.copyFile(srcPath, destPath); |
| 61 | } |
| 62 | } catch (fileErr) { |
| 63 | console.warn(`⚠️ 跳过文件 ${entry.name}:`, fileErr.message); |
| 64 | // 继续处理其他文件 |
| 65 | } |
| 66 | } |
| 67 | } catch (err) { |
| 68 | throw new Error(`复制目录失败 ${source}: ${err.message}`); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | (async () => { |
| 73 | BuildLogger.log('🧹 清理 dist 目录...'); |