sindresorhus / gulp-zip

ZIP compress files
MIT License
270 stars 47 forks source link

How do i zip a directory? #41

Closed djmittens closed 9 years ago

djmittens commented 9 years ago

Clearly doing this

gulp.task('build', ['clean', 'html', 'images', 'fonts'], function() {
  return gulp.src('dist/**/*').
    pipe($.size({title: 'build', gzip: true})).
    pipe($.zip('tremor.zip')).
    pipe(gulp.dest('dist'));
});

produces a zip with a flat file structure, but i want the zip file to unzip into a folder when running unzip command, so is there any way to stuff all the output into a folder before zipping it up?

sindresorhus commented 9 years ago

https://github.com/sindresorhus/gulp-zip/issues/39

djmittens commented 9 years ago

That does not answer my question, because if you execute that code the file when extracted will extract into the current directory and not make a new one. I want to be able to name a directory after the zip

for instance

unzip tremor.zip should produce a directory named tremor and not unpack all the files into the cwd

ajoah commented 9 years ago

For those, like me, stumble upon this issue, the solution is there : https://github.com/sindresorhus/gulp-zip/issues/23#issuecomment-46083758

mariovalney commented 4 years ago

You can use gulp-rename to add a "parent" directory:

gulp.src(your_files)
    .pipe(
      rename(
        function(path) {
          path.dirname = 'parent-diretory/' + path.dirname;
        }
      )
    )
    .pipe(zip('your-zip-file.zip'))
    .pipe(gulp.dest('.'));