Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·55 lines (43 loc) · 1.43 KB
/
Copy pathbuild.js
File metadata and controls
executable file
·55 lines (43 loc) · 1.43 KB
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
#!/usr/bin/env python3
"""Rebuild bundle from split modules for iflow-cli-ce."""
import json, os, re
HERE = os.path.dirname(os.path.abspath(__file__))
with open(f'{HERE}/module_order.json') as f:
order = json.load(f)
with open(f'{HERE}/bundled_licenses.txt') as f:
licenses = f.read()
parts = []
# Add preamble
with open(f'{HERE}/preamble.js') as f:
parts.append(f.read())
# Add modules in order, stripping annotation headers
count = 0
for mod in order['order']:
name = mod['name']
cat = mod['category']
label = mod['label']
safe_label = re.sub(r'[^a-zA-Z0-9_-]', '_', label)
filepath = f'{HERE}/modules/{cat}/{name}_{safe_label}.js'
with open(filepath) as f:
module_code = f.read()
if module_code.startswith('/**'):
idx = module_code.index('*/\n\n')
module_code = module_code[idx + 4:]
parts.append(module_code)
count += 1
print(f" Modules: {count}")
# Add entry code
with open(f'{HERE}/entry_code.js') as f:
entry = f.read()
if entry.startswith('/**'):
idx = entry.index('*/\n')
entry = entry[idx + 3:]
parts.append(entry)
# Add licenses
parts.append(licenses)
# Write bundle
os.makedirs(f'{HERE}/bundle', exist_ok=True)
with open(f'{HERE}/bundle/iflow.js', 'w') as f:
f.write(''.join(parts))
size = os.path.getsize(f'{HERE}/bundle/iflow.js')
print(f"Bundle rebuilt: bundle/iflow.js ({size:,} chars, {size/1024/1024:.1f} MB)")