@@ -9,6 +9,46 @@ const { writeZip, zipFile } = require('./zipTree');
9
9
10
10
BbPromise . promisifyAll ( fse ) ;
11
11
12
+ /**
13
+ * Inject requirements into JSZip object
14
+ * @param {JSZip } zip js
15
+ * @param {string } requirementsPath requirements folder path
16
+ * @param {Object } options our options object
17
+ * @return {Promise } the JSZip object constructed.
18
+ */
19
+ function injectRequirementsToZip ( zip , requirementsPath , options ) {
20
+ const noDeploy = new Set ( options . noDeploy || [ ] ) ;
21
+ const runtimePath = 'python' ;
22
+
23
+ return BbPromise . resolve (
24
+ glob . sync ( [ path . join ( requirementsPath , '**' ) ] , {
25
+ mark : true ,
26
+ dot : true
27
+ } )
28
+ )
29
+ . map ( file => [ file , path . relative ( requirementsPath , file ) ] )
30
+ . filter (
31
+ ( [ file , relativeFile ] ) =>
32
+ ! file . endsWith ( '/' ) &&
33
+ ! relativeFile . match ( / ^ _ _ p y c a c h e _ _ [ \\ / ] / ) &&
34
+ ! noDeploy . has ( relativeFile . split ( / ( [ - \\ / ] | \. p y $ | \. p y c $ ) / , 1 ) [ 0 ] )
35
+ )
36
+ . map ( ( [ file , relativeFile ] ) =>
37
+ Promise . all ( [
38
+ file ,
39
+ options . layer ? path . join ( runtimePath , relativeFile ) : relativeFile ,
40
+ fse . statAsync ( file )
41
+ ] )
42
+ )
43
+ . mapSeries ( ( [ file , relativeFile , fileStat ] ) =>
44
+ zipFile ( zip , relativeFile , fse . readFileAsync ( file ) , {
45
+ unixPermissions : fileStat . mode ,
46
+ createFolders : false
47
+ } )
48
+ )
49
+ . then ( ( ) => zip ) ;
50
+ }
51
+
12
52
/**
13
53
* Inject requirements into packaged application.
14
54
* @param {string } requirementsPath requirements folder path
@@ -17,36 +57,11 @@ BbPromise.promisifyAll(fse);
17
57
* @return {Promise } the JSZip object constructed.
18
58
*/
19
59
function injectRequirements ( requirementsPath , packagePath , options ) {
20
- const noDeploy = new Set ( options . noDeploy || [ ] ) ;
21
-
22
60
return fse
23
61
. readFileAsync ( packagePath )
24
62
. then ( buffer => JSZip . loadAsync ( buffer ) )
25
- . then ( zip =>
26
- BbPromise . resolve (
27
- glob . sync ( [ path . join ( requirementsPath , '**' ) ] , {
28
- mark : true ,
29
- dot : true
30
- } )
31
- )
32
- . map ( file => [ file , path . relative ( requirementsPath , file ) ] )
33
- . filter (
34
- ( [ file , relativeFile ] ) =>
35
- ! file . endsWith ( '/' ) &&
36
- ! relativeFile . match ( / ^ _ _ p y c a c h e _ _ [ \\ / ] / ) &&
37
- ! noDeploy . has ( relativeFile . split ( / ( [ - \\ / ] | \. p y $ | \. p y c $ ) / , 1 ) [ 0 ] )
38
- )
39
- . map ( ( [ file , relativeFile ] ) =>
40
- Promise . all ( [ file , relativeFile , fse . statAsync ( file ) ] )
41
- )
42
- . mapSeries ( ( [ file , relativeFile , fileStat ] ) =>
43
- zipFile ( zip , relativeFile , fse . readFileAsync ( file ) , {
44
- unixPermissions : fileStat . mode ,
45
- createFolders : false
46
- } )
47
- )
48
- . then ( ( ) => writeZip ( zip , packagePath ) )
49
- ) ;
63
+ . then ( zip => injectRequirementsToZip ( zip , requirementsPath , options ) )
64
+ . then ( zip => writeZip ( zip , packagePath ) ) ;
50
65
}
51
66
52
67
/**
@@ -140,4 +155,7 @@ function injectAllRequirements(funcArtifact) {
140
155
}
141
156
}
142
157
143
- module . exports = { injectAllRequirements } ;
158
+ module . exports = {
159
+ injectAllRequirements,
160
+ injectRequirementsToZip
161
+ } ;
0 commit comments