({ dir, filename, isRequired })
| 46 | }; |
| 47 | |
| 48 | const deleteFile = ({ dir, filename, isRequired }) => { |
| 49 | validateDir(dir); |
| 50 | const filePath = join(dir, filename); |
| 51 | |
| 52 | if (existsSync(filePath)) { |
| 53 | const message = `⚠️ [FILE] ${filePath} Required file exist.`; |
| 54 | handleError(message, isRequired); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | try { |
| 59 | console.log(`[FILE] Deleting ${filePath} file ...`); |
| 60 | unlink(filePath, (error) => { |
| 61 | if (error) { |
| 62 | throw new Error(error); |
| 63 | } |
| 64 | }); |
| 65 | } catch (error) { |
| 66 | const message = `⚠️[FILE] Deleting file error. filePath: ${filePath}, message: ${error.message}`; |
| 67 | handleError(message, isRequired); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | const validateRequiredInputs = (inputs) => { |
| 72 | const inputKeys = Object.keys(inputs); |
no test coverage detected