Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change root within zip? #3

Closed
bartlewis opened this issue Jan 14, 2014 · 7 comments
Closed

Change root within zip? #3

bartlewis opened this issue Jan 14, 2014 · 7 comments

Comments

@bartlewis
Copy link

gulp.task('default', function () {
    gulp.src('src/*')
        .pipe(zip('archive.zip'))
        .pipe(gulp.dest('dist'));
});

The above results in the "src" folder being the top level within the zip file. How do I make the contents of "src" the top level of the zip instead?

@bartlewis
Copy link
Author

I tried the following, but this resulted in an empty zip, like #1.

gulp.task('default', function () {
    gulp.src('*', {cwd:'build'})
        .pipe(zip('archive.zip'))
        .pipe(gulp.dest('dist'));
});

@bartlewis
Copy link
Author

Answer:

var path = require('path');

gulp.task('default', function () {
  gulp.src('*', {cwd: process.cwd() + path.sep + 'build'})
    .pipe(zip('archive.zip'))
    .pipe(gulp.dest('dist'));
});

@sindresorhus
Copy link
Owner

Ya, cwd probably expects an absolute path. I would tweak it slightly though:

var path = require('path');

gulp.task('default', function () {
  gulp.src('*', {cwd: path.join(process.cwd(), 'build')})
    .pipe(zip('archive.zip'))
    .pipe(gulp.dest('dist'));
});

@contra @phated is this the correct way to handle this?

@yocontra
Copy link

@bartlewis In 3.4 I'll make sure cwd accepts relative paths. Should be out soon

@bartlewis
Copy link
Author

Thanks guys.

@kaelteschutz
Copy link

For me on OSX it is impossible to create an archive without the parent folder in it:

var scormArchiveTask = function () {
  gulp.src('**', {cwd: 'public'})
  .pipe(zip('archive.zip'))
  .pipe(gulp.dest('./public'))
}

@warengonzaga
Copy link

Anything doesnt work! I've tried the code but unlucky to achieve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants