-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathclean_pack.js
More file actions
42 lines (37 loc) · 896 Bytes
/
clean_pack.js
File metadata and controls
42 lines (37 loc) · 896 Bytes
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
#!/usr/bin/env node
/**
* Remove Python bytecode caches before npm pack/publish.
* These files are environment-specific and just bloat the tarball.
*/
const fs = require('fs');
const path = require('path');
function rmrf(p) {
try {
fs.rmSync(p, { recursive: true, force: true });
} catch (_) {}
}
function walk(dir) {
let entries = [];
try {
entries = fs.readdirSync(dir, { withFileTypes: true });
} catch (_) {
return;
}
for (const e of entries) {
const p = path.join(dir, e.name);
if (e.isDirectory()) {
if (e.name === '__pycache__') {
rmrf(p);
continue;
}
walk(p);
continue;
}
if (e.isFile()) {
if (e.name.endsWith('.pyc') || e.name.endsWith('.pyo') || e.name.endsWith('.pyd')) {
try { fs.unlinkSync(p); } catch (_) {}
}
}
}
}
walk(path.join(__dirname, '..', 'beacon_skill'));