sindresorhus / gulp-zip

ZIP compress files
MIT License
270 stars 47 forks source link

Support destination directory in the zipfile #35

Closed wangxian closed 9 years ago

wangxian commented 9 years ago

I want to add dest option for setting destination directory in the zip file

Usage:

gulp.src(["apps/app-main/**", "apps/app-chat/**", "apps/app-xxx/**", "modules/**", "package.json", "index.html"])
    .pipe(zip('archive-141203.zip', {dest: "webapp"}))
    .pipe(gulp.dest('release'));

output zipfile structure

archive-141203.zip/
    webapp/apps/app-main/
    webapp/apps/app-chat/
    webapp/apps/app-xxx/
    webapp/modules/
    webapp/package.json
    webapp/index.html

When no options.dest parameters , directories, zip files is like:

archive-141203.zip/
    apps/app-main/
    apps/app-chat/
    apps/app-xxx/
    modules/
    package.json
    index.html

options.dest parameter allows gulp.src each item , output to the same directory , instead of the root zipfile

In one of our projects , we need to be labeled as a multiple apps zip package , if the compressed file is not the root directory , it will be very messy after decompression .

So I need to add a parameter options.dest

thanks!

sindresorhus commented 9 years ago

You can change the base option in gulp-src or use gulp-rename.

wangxian commented 9 years ago

gulp-src base parameter can not solve the problem, if opts.dest dir is not exists, base can not change file.relative

using gulp-rename is ok

return gulp.src(pkginfo.dependenciesSRC, {cwd: "../", base: "../"})
  .pipe(rename(function(path){ path.dirname = "webapp/" + path.dirname; }))

Thank you very much