Created
February 18, 2014 11:09
-
-
Save avaly/9068932 to your computer and use it in GitHub Desktop.
gulp-zip-custom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'), | |
gutil = require('gulp-util'), | |
nodeZip = require('node-native-zip'), | |
through = require('through2'); | |
var gulpZipCustom = function(filename) { | |
if (!filename) { | |
throw new gutil.PluginError('gulp-zip-custom', chalk.blue('filename') + ' required'); | |
} | |
var firstFile; | |
var zip = new nodeZip(); | |
return through.obj(function(file, enc, cb){ | |
if (file.isNull()) { | |
this.push(file); | |
return cb(); | |
} | |
if (file.isStream()) { | |
this.emit('error', new gutil.PluginError('gulp-zip-custom', 'Streaming not supported')); | |
return cb(); | |
} | |
if (!firstFile) { | |
firstFile = file; | |
} | |
var relativePath = file.path.replace(file.cwd + path.sep, ''); | |
zip.add(relativePath, file.contents); | |
cb(); | |
}, function (cb) { | |
if (!firstFile) { | |
return cb(); | |
} | |
this.push(new gutil.File({ | |
cwd: firstFile.cwd, | |
base: firstFile.cwd, | |
path: path.join(firstFile.cwd, filename), | |
contents: zip.toBuffer() | |
})); | |
cb(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment