mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
3e7a15b9ee
fixes #10929
28 lines
803 B
JavaScript
28 lines
803 B
JavaScript
const fs = require('fs-extra');
|
|
|
|
module.exports = function 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();
|
|
};
|