* Recursively copy files and directories * @param {string} src - Source directory * @param {string} dest - Destination directory
(src, dest)
| 10 | * @param {string} dest - Destination directory |
| 11 | */ |
| 12 | function copyRecursive(src, dest) { |
| 13 | if (!fs.existsSync(src)) { |
| 14 | throw new Error(`Source directory ${src} does not exist`); |
| 15 | } |
| 16 | |
| 17 | // Create destination directory if it doesn't exist |
| 18 | if (!fs.existsSync(dest)) { |
| 19 | fs.mkdirSync(dest, { recursive: true }); |
| 20 | } |
| 21 | |
| 22 | const entries = fs.readdirSync(src, { withFileTypes: true }); |
| 23 | |
| 24 | for (const entry of entries) { |
| 25 | const srcPath = path.join(src, entry.name); |
| 26 | const destPath = path.join(dest, entry.name); |
| 27 | |
| 28 | if (entry.isDirectory()) { |
| 29 | copyRecursive(srcPath, destPath); |
| 30 | } else { |
| 31 | fs.copyFileSync(srcPath, destPath); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Execute a command in a specific directory |