@@ -32,6 +32,36 @@ function addTree(zip, src) {
32
32
. then ( ( ) => zip ) ; // Original zip for chaining.
33
33
}
34
34
35
+ /**
36
+ * Add a directory recursively to a zip file. Files in src will be added to the top folder of zip.
37
+ * @param {JSZip } zip a zip object in the folder you want to add files to.
38
+ * @param {string } src the source folder.
39
+ * @param {Object } noDeploy the source folder.
40
+ * @return {Promise } a promise offering the original JSZip object.
41
+ */
42
+ function addTreeNoDeploy ( zip , src , noDeploy ) {
43
+ const srcN = path . normalize ( src ) ;
44
+
45
+ return fse
46
+ . readdirAsync ( srcN )
47
+ . filter ( name => ! noDeploy . has ( name ) )
48
+ . map ( ( name ) => {
49
+ const srcPath = path . join ( srcN , name ) ;
50
+
51
+ return fse . statAsync ( srcPath ) . then ( ( stat ) => {
52
+ if ( stat . isDirectory ( ) ) {
53
+ return addTreeNoDeploy ( zip . folder ( name ) , srcPath , noDeploy ) ;
54
+ } else {
55
+ const opts = { date : stat . mtime , unixPermissions : stat . mode } ;
56
+ return fse
57
+ . readFileAsync ( srcPath )
58
+ . then ( ( data ) => zip . file ( name , data , opts ) ) ;
59
+ }
60
+ } ) ;
61
+ } )
62
+ . then ( ( ) => zip ) ; // Original zip for chaining.
63
+ }
64
+
35
65
/**
36
66
* Write zip contents to a file.
37
67
* @param {JSZip } zip the zip object
@@ -81,4 +111,4 @@ function zipFile(zip, zipPath, bufferPromise, fileOpts) {
81
111
. then ( ( ) => zip ) ;
82
112
}
83
113
84
- module . exports = { addTree, writeZip, zipFile } ;
114
+ module . exports = { addTree, writeZip, zipFile , addTreeNoDeploy } ;
0 commit comments