forked from serverless/serverless-python-requirements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslim.js
59 lines (55 loc) · 1.22 KB
/
slim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const isWsl = require('is-wsl');
const glob = require('glob-all');
const fse = require('fs-extra');
const getStripMode = options => {
if (
options.strip === false ||
options.strip === 'false' ||
options.slim === false ||
options.slim === 'false'
) {
return 'skip';
} else if (options.dockerizePip) {
return 'docker';
} else if (
(!isWsl && process.platform === 'win32') ||
process.platform === 'darwin'
) {
return 'skip';
} else {
return 'direct';
}
};
const getStripCommand = (options, folderPath) => [
'find',
folderPath,
'-name',
'*.so',
'-exec',
'strip',
'{}',
';'
];
const deleteFiles = (options, folderPath) => {
let patterns = ['**/*.py[c|o]', '**/__pycache__*', '**/*.dist-info*'];
if (options.slimPatterns) {
if (
options.slimPatternsAppendDefaults === false ||
options.slimPatternsAppendDefaults == 'false'
) {
patterns = options.slimPatterns;
} else {
patterns = patterns.concat(options.slimPatterns);
}
}
for (const pattern of patterns) {
for (const file of glob.sync(`${folderPath}/${pattern}`)) {
fse.removeSync(file);
}
}
};
module.exports = {
getStripMode,
getStripCommand,
deleteFiles
};