| 60 | .map((dirent) => dirent.name); |
| 61 | |
| 62 | export const zip = (inputPath) => |
| 63 | new Promise((resolve, reject) => { |
| 64 | try { |
| 65 | readdirSync(inputPath); |
| 66 | } catch (err) { |
| 67 | reject( |
| 68 | new Error( |
| 69 | `Cannot zip directory ${inputPath}. Directory doesn't exist.`, |
| 70 | ), |
| 71 | ); |
| 72 | return; |
| 73 | } |
| 74 | const archive = archiver("zip"); |
| 75 | logger.log(`Zipping ${inputPath}...`); |
| 76 | |
| 77 | const output = createWriteStream(`${inputPath}.zip`); |
| 78 | output.on("close", handleZipEnd(resolve, `${inputPath}.zip`)); |
| 79 | |
| 80 | archive.pipe(output); |
| 81 | archive.on("error", reject); |
| 82 | archive.on("warning", handleZipWarning(resolve)); |
| 83 | archive.directory(inputPath, false); |
| 84 | archive.finalize(); |
| 85 | }); |