Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress content to the archive root using grunt-contrib-compress

I have the following directory structure, and I want to zip the content of dev folder and place it in the root of the generated archive without it being wrapped inside a top level folder:

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

Here is the code (gruntfile.js inside _build):

    compress: {             
         main : {
            options : {
                archive : "../dist/dev.zip"
            },
            files : [
                { expand: true, src : "../dev/**/*" }
            ]
        }     
      }

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 being place into the root of zip file.

Can this be achieved in some way?

Thank you

like image 469
DaviBenNun Avatar asked Jul 12 '13 14:07

DaviBenNun


2 Answers

you can do as exposed here : https://github.com/gruntjs/grunt-contrib-compress/issues/33

For example :

compress : {
  main : {
    options : {
      archive : "myapp.zip"
    },
    files : [
      { expand: true, src : "**/*", cwd : "dist/" }
    ]
  }
}

will generate myapp.zip in the root path, countaining all files and directory included in /dist, but not the dist directory itself.

like image 169
François Petitit Avatar answered Oct 24 '22 22:10

François Petitit


another example, more in line with original question:

    compress: {
    main: {
        options: {
            archive : "../dist/dev.zip"
        },
        files: [
            {
                expand: true,
                cwd: '../dev/',
                src: ['**'],
            }
        ]
    },
},

This should give your flat structure:

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

checkout this great article on grunt-compress: http://www.charlestonsw.com/what-i-learned-about-grunt-compress/

like image 6
zulucoda Avatar answered Oct 24 '22 21:10

zulucoda