Skip to content

Commit 57eac75

Browse files
committed
feat: ref noDeploy option when use layers
1 parent a0d67db commit 57eac75

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lib/layer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const BbPromise = require('bluebird');
22
const fse = require('fs-extra');
33
const path = require('path');
44
const JSZip = require('jszip');
5-
const { writeZip, addTree } = require('./zipTree');
5+
const { writeZip, addTreeNoDeploy } = require('./zipTree');
66
const { sha256Path, getRequirementsLayerPath } = require('./shared');
77

88
BbPromise.promisifyAll(fse);
@@ -39,9 +39,10 @@ function zipRequirements() {
3939
} else {
4040
const rootZip = new JSZip();
4141
const runtimepath = 'python';
42+
const noDeploy = new Set(this.options.noDeploy || []);
4243

4344
promises.push(
44-
addTree(rootZip.folder(runtimepath), src).then(() =>
45+
addTreeNoDeploy(rootZip.folder(runtimepath), src, noDeploy).then(() =>
4546
writeZip(rootZip, zipCachePath)
4647
)
4748
);

lib/zipTree.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ function addTree(zip, src) {
3232
.then(() => zip); // Original zip for chaining.
3333
}
3434

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+
3565
/**
3666
* Write zip contents to a file.
3767
* @param {JSZip} zip the zip object
@@ -81,4 +111,4 @@ function zipFile(zip, zipPath, bufferPromise, fileOpts) {
81111
.then(() => zip);
82112
}
83113

84-
module.exports = { addTree, writeZip, zipFile };
114+
module.exports = { addTree, writeZip, zipFile , addTreeNoDeploy };

0 commit comments

Comments
 (0)