* Copy directory recursively * @param {string} src Source directory * @param {string} dest Destination directory * @param {string[]} skip Files to not copy
(src, dest, skip = [], currPath = '')
| 274 | * @param {string[]} skip Files to not copy |
| 275 | */ |
| 276 | function copyDirRecursively(src, dest, skip = [], currPath = '') { |
| 277 | const exists = fs.existsSync(src); |
| 278 | const stats = exists && fs.statSync(src); |
| 279 | const isDirectory = exists && stats.isDirectory(); |
| 280 | |
| 281 | if (!exists) { |
| 282 | console.log(`File ${src} does not exist`); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | if (!fs.existsSync(dest) && isDirectory) { |
| 287 | fs.mkdirSync(dest); |
| 288 | } |
| 289 | |
| 290 | if (exists && isDirectory) { |
| 291 | fs.mkdirSync(dest, { recursive: true }); |
| 292 | fs.readdirSync(src).forEach((childItemName) => { |
| 293 | const relativePath = path.join(currPath, childItemName); |
| 294 | if (childItemName.startsWith('.')) return; |
| 295 | if (skip.includes(childItemName) || skip.includes(relativePath)) return; |
| 296 | copyDirRecursively( |
| 297 | path.join(src, childItemName), |
| 298 | path.join(dest, childItemName), |
| 299 | skip, |
| 300 | relativePath, |
| 301 | ); |
| 302 | }); |
| 303 | } else { |
| 304 | removeConflictingResourceFiles(src, dest); |
| 305 | fs.copyFileSync(src, dest); |
| 306 | |
| 307 | // log |
| 308 | const message = `copied: ${path.basename(src)}`; |
| 309 | console.log('\x1b[32m%s\x1b[0m', message); // green |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | function removeConflictingResourceFiles(src, dest) { |
| 314 | const parentDir = path.dirname(dest); |
no test coverage detected