* Recursively copies the contents of one directory to another directory. * @param {string} sourcePath * @param {string} destinationPath * @returns
(sourcePath, destinationPath)
| 36 | * @returns |
| 37 | */ |
| 38 | function copyFolderRecursiveSync(sourcePath, destinationPath) { |
| 39 | if (!fs.existsSync(sourcePath) || !fs.lstatSync(sourcePath).isDirectory()) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // Check if folder needs to be created or integrated |
| 44 | if (!fs.existsSync(destinationPath)) { |
| 45 | fs.mkdirSync(destinationPath); |
| 46 | } |
| 47 | |
| 48 | const files = fs.readdirSync(sourcePath); |
| 49 | |
| 50 | for (const file of files) { |
| 51 | const srcFilePath = path.join(sourcePath, file); |
| 52 | const destFilePath = path.join(destinationPath, file); |
| 53 | |
| 54 | if (!shouldInclude(srcFilePath)) { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | const fileStats = fs.lstatSync(srcFilePath); |
| 59 | |
| 60 | if (fileStats.isDirectory()) { |
| 61 | console.log(`copy dir ${srcFilePath}`); |
| 62 | copyFolderRecursiveSync(srcFilePath, destFilePath); |
| 63 | } else if (fileStats.isSymbolicLink()) { |
| 64 | console.log("**** LINK"); |
| 65 | } else { |
| 66 | fs.copyFileSync(srcFilePath, destFilePath); |
| 67 | } |
| 68 | } |
| 69 | } // It will be possible to replace with `fs.cpSync` if the version of Node.js >= 16.7.0. |
| 70 | |
| 71 | /** |
| 72 | * Reads the contents of the root directory and recursively copies the contents of each folder, unless they are excluded. |
no test coverage detected