| 70 | } |
| 71 | |
| 72 | export function copyRecursive(src, dest) { |
| 73 | try { |
| 74 | if (isFile(src)) { |
| 75 | copy(src, dest); |
| 76 | return; |
| 77 | } |
| 78 | const targetDirPath = path.resolve(dest, path.basename(src)); |
| 79 | if (!fs.existsSync(targetDirPath)) { |
| 80 | fs.mkdirSync(targetDirPath); |
| 81 | } |
| 82 | if (isDir(src)) { |
| 83 | const files = fs.readdirSync(src); |
| 84 | for (let i = 0; i < files.length; i++) { |
| 85 | const childPath = path.resolve(src, files[i]); |
| 86 | if (isDir(childPath)) { |
| 87 | copyRecursive(childPath, targetDirPath); |
| 88 | } else { |
| 89 | const targetFilePath = path.resolve( |
| 90 | targetDirPath, |
| 91 | path.basename(childPath), |
| 92 | ); |
| 93 | fs.writeFileSync(targetFilePath, fs.readFileSync(childPath)); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } catch (error) { |
| 98 | throw new Error( |
| 99 | `Received an error: [${error}] while trying to copy: ${src} -> ${dest}`, |
| 100 | ); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | export function removeRecursive(filePath) { |
| 105 | try { |