| 102 | } |
| 103 | |
| 104 | export function removeRecursive(filePath) { |
| 105 | try { |
| 106 | if (fs.existsSync(filePath)) { |
| 107 | if (isFile(filePath)) { |
| 108 | fs.unlinkSync(filePath); |
| 109 | return; |
| 110 | } |
| 111 | const files = fs.readdirSync(filePath); |
| 112 | for (let i = 0; i < files.length; i++) { |
| 113 | const childPath = path.resolve(filePath, files[i]); |
| 114 | if (isDir(childPath)) { |
| 115 | removeRecursive(childPath); |
| 116 | } else { |
| 117 | fs.unlinkSync(childPath); |
| 118 | } |
| 119 | } |
| 120 | fs.rmdirSync(filePath); |
| 121 | } |
| 122 | } catch (error) { |
| 123 | throw new Error( |
| 124 | `Received an error: [${error}] while trying to remove: ${filePath}`, |
| 125 | ); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | export function includes(sequence, target) { |
| 130 | return sequence.indexOf(target) > -1; |