
const fs = require('fs');

const zipDir = require('zip-directory');

exports.zip = function zip (targetPath, ...destPath) {
    const d = destPath.shift();

    if (fs.existsSync(d)) {
        fs.unlinkSync(d);
    }

    return new Promise((resolve, reject) => {
        zipDir(targetPath, d, () => {
            if (destPath.length) {
                Promise.all(destPath.map(dest => {
                    return new Promise((resolve, reject) => {
                        fs.copyFile(d, dest, (err) => {
                            if (err) reject(err);

                            resolve();
                        });
                    });
                })).then(resolve, reject);
                return;
            }

            resolve();
        });
    });
};