Ghost/ghost/zip/lib/zip-folder.js
Hannah Wolfe 62c2fce6cc Switch to OG extract-zip w/ promise based interface
- switch back from @tryghost/extract-zip to extract-zip now that it has been fixed (and is much better maintained)
- switch the internal interface to be fully promise-based and test promise-based too
2020-04-08 12:48:20 +01:00

31 lines
874 B
JavaScript

const fs = require('fs-extra');
const Promise = require('bluebird');
const zipFolder = (folderToZip, destination, callback) => {
var archiver = require('archiver'),
output = fs.createWriteStream(destination),
archive = archiver.create('zip', {});
// If folder to zip is a symlink, we want to get the target
// of the link and zip that instead of zipping the symlink
if (fs.lstatSync(folderToZip).isSymbolicLink()) {
folderToZip = fs.realpathSync(folderToZip);
}
output.on('close', function () {
callback(null, archive.pointer());
});
archive.on('error', function (err) {
callback(err, null);
});
archive.glob(`**/*`, {
cwd: folderToZip,
ignore: ['node_modules/**']
});
archive.pipe(output);
archive.finalize();
};
module.exports = Promise.promisify(zipFolder);