twolfson / grunt-zip

Zip and unzip files via a grunt plugin
MIT License
87 stars 19 forks source link

Zipping without root folder #15

Closed davibennun closed 11 years ago

davibennun commented 11 years ago

I have the following directory structure, and I want zip the content of dev without it being wrapped inside a root folder:

_build/     #build scripts
dist/       #destination
dev/        #source

Here is the code:

zip : {
    app : {
        src : ['dev/**/*'],
        dest : 'dist/dev.zip'
    }
}

I wish I could zip only the contents of dev folder and place it into dist folder. But when I try to do so I, all the content of dev are zipped inside a root folder.

Actual generated zip:

dist/
   |____ dev.zip
          |_____ dev/
                  |_____ index.html
                  |_____styles/style.css

But I want the zip file to be like this:

dist/
   |____ dev.zip
        |_____ index.html
        |_____ styles/style.css

You see? the files are being wrapped in a folder(with the same name as the zip) instead of beeing place into the root of zip file.

Can this be achieved in some way?

twolfson commented 11 years ago

Hey @DaviBenNun , indeed it can! There are 2 options which you can use to accomplish this:

cwd

{
  cwd: 'dev/',
  src: ['dev/**/*'],
  dest: 'dev.zip'
}

router

{
  src: ['dev/**/*'],
  dest: 'dev.zip',
  router: function (filepath) {
    return filepath.replace('dev/', '');
  }
}

More information on these options can be found in the README. Thanks!

davibennun commented 11 years ago

Hello @twolfson thank you so much for your answer. I just tried both suggestions but it didn't worked out, the destination zip contained one folder called "dev" and inside it was all the content, as I said the goal is to have the content directly in the root of the zip file, I have been playing with cwd and router variations but I just can't make it work...

twolfson commented 11 years ago

Alright, I cannot take a look now but I should be able to make a proof of concept this weekend.

twolfson commented 11 years ago

@DaviBenNun I implemented the cwd solution and the zip file does not have the dev/ folder in it as expected. Here is my proof of concept, you can clone it, npm install, and grunt to find the same .zip that I am viewing.

https://gist.github.com/twolfson/5992548