Gulp: Zip Folder for Archive

var $ = require('gulp-load-plugins')(); var fs = require('fs'); var gutil = require('gulp-util'); gulp.task(':archive:zip', function (done) { var path = require('path'); var dist = config.deployment.target; var archiveName = path.resolve(__dirname, dist + '.zip'); var archiveDir = path.resolve(__dirname, dist); var archiver = require('archiver')('zip'); var files = require('glob').sync('**/*.*', { 'cwd': archiveDir, 'dot': false // include hidden files }); var output = fs.createWriteStream(archiveName); archiver.on('error', function (error) { done(); throw error; }); output.on('close', done); files.forEach(function (file) { var filePath = path.resolve(archiveDir, file); // `archiver.bulk` does not maintain the file // permissions, so we need to add files individually archiver.append(fs.createReadStream(filePath), { 'name': file, 'mode': fs.statSync(filePath) }); }); archiver.pipe(output); archiver.finalize(); gutil.log(gutil.colors.magenta('\nZip created at ' + archiveName)); });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.