(folderPath, excludeSubFolders = [])
| 281 | } |
| 282 | |
| 283 | function deleteFolderRecursive(folderPath, excludeSubFolders = []) { |
| 284 | if (!fs.existsSync(folderPath)) return; |
| 285 | |
| 286 | const entries = fs.readdirSync(folderPath, { withFileTypes: true }); |
| 287 | |
| 288 | for (const entry of entries) { |
| 289 | const fullPath = path.join(folderPath, entry.name); |
| 290 | |
| 291 | if (entry.isDirectory()) { |
| 292 | if (excludeSubFolders.includes(entry.name)) { |
| 293 | continue; // Skip this folder |
| 294 | } |
| 295 | deleteFolderRecursive(fullPath, excludeSubFolders); |
| 296 | } else { |
| 297 | fs.unlinkSync(fullPath); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // After deleting contents, delete the root folder if it's not in the excluded list |
| 302 | const folderName = path.basename(folderPath); |
| 303 | if (!excludeSubFolders.includes(folderName)) { |
| 304 | const remaining = fs.readdirSync(folderPath); |
| 305 | if (remaining.length === 0) { |
| 306 | fs.rmdirSync(folderPath); |
| 307 | console.log(`Deleted folder: ${folderPath}`); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | function copyRecursiveExcludingGit(src, dest) { |
| 313 | if (!fs.existsSync(src)) return; |
no outgoing calls
no test coverage detected