lib/zipTree.js
function addTree(zip, src) {
  const srcN = path.normalize(src);

  return fse
    .readdirAsync(srcN)
    .map(name => {
      const srcPath = path.join(srcN, name);

      return fse.statAsync(srcPath).then(stat => {
        if (stat.isDirectory()) {
          return addTree(zip.folder(name), srcPath);
        } else {
          const opts = { date: stat.mtime, unixPermissions: stat.mode };
          return fse
            .readFileAsync(srcPath)
            .then(data => zip.file(name, data, opts));
        }
      });
    })
    .then(() => zip); // Original zip for chaining.
}
function addTree(zip, src) {
  const srcN = path.normalize(src);

  return fse
    .readdirAsync(srcN)
    .map(name => {
      const srcPath = path.join(srcN, name);

      return fse.statAsync(srcPath).then(stat => {
        if (stat.isDirectory()) {
          return addTree(zip.folder(name), srcPath);
        } else {
          const opts = { date: stat.mtime, unixPermissions: stat.mode };
          return fse
            .readFileAsync(srcPath)
            .then(data => zip.file(name, data, opts));
        }
      });
    })
    .then(() => zip); // Original zip for chaining.
}
function addTree ( zip , src ) { const srcN = path . normalize ( src ) ; return fse . readdirAsync ( srcN ) . map ( name => { const srcPath = path . join ( srcN , name ) ; return fse . statAsync ( srcPath ) . then ( stat => { if ( stat . isDirectory ( ) ) { return addTree ( zip . folder ( name ) , srcPath ) ; } else { const opts = { date : stat . mtime , unixPermissions : stat . mode } ; return fse . readFileAsync ( srcPath ) . then ( data => zip . file ( name , data , opts ) ) ; } } ) ; } ) . then ( ( ) => zip ) ; // Original zip for chaining. }
Add a directory recursively to a zip file. Files in src will be added to the top folder of zip.
@param {JSZip} zip a zip object in the folder you want to add files to.
@param {string} src the source folder.
@return {Promise} a promise offering the original JSZip object.
Add a directory recursively to a zip file . Files in src will be added to the top folder of zip .