Search code examples
phonegap-buildarchiverjs

Archiver v1.3.0 - Unable to zip directory content without the directory name being the root folder


I am using https://archiverjs.com/docs/ to zip a directory for my PhoneGap application but I have not yet managed to achieve what I want to.

I have a folder structured like this: - www - css - images - scripts - config.xml - index.html

Now what I would like to have is a zip file containing the the CONTENT of the www folder but NOT the www itself.

BAD
 - www.zip
   - www
      - css
      - images
      - scripts
      - config.xml
      - index.html
GOOD
 - www.zip
   - css
   - images
   - scripts
   - config.xml
   - index.html

The code I have in place is the follow:

var archiver = require('archiver');

var output = fs.createWriteStream('./www/www.zip');
var archive = archiver('zip', {
   store: true // Sets the compression method to STORE.
});

output.on('close', function() {
  console.log(archive.pointer() + ' total bytes');
  console.log('archiver has been finalized and the output file descriptor has closed.');
});

archive.on('error', function(err) {
  throw err;
});

archive.pipe(output);
archive.directory('www/');
archive.finalize();

I have tried to add something like: archive.directory('www/*'); but it throws an error.

Any other way I can accomplish that? Thanks


Solution

  • I found the solution, I just needed to do the follow:

    archive.directory('www', '/');
    

    Problem solved :)

    Thanks