DaviBenNun
DaviBenNun

Reputation: 73

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

Upvotes: 5

Views: 4950

Answers (2)

zulucoda
zulucoda

Reputation: 868

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/

Upvotes: 6

François Petitit
François Petitit

Reputation: 409

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.

Upvotes: 11

Related Questions