-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
executable file
·42 lines (29 loc) · 904 Bytes
/
build.py
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
#! /usr/bin/env python3
import content_script_embed
import os
import pathlib
import shutil
DIR = pathlib.Path(__file__).parent
WEB_EXT_OUT = DIR / 'web-ext/out'
WEB_EXT_OUT_INLINE = DIR / 'web-ext-inline/out'
def write_to(dest, data):
print(f' ({len(data)} bytes) => {dest}')
dest.write_bytes(data)
def clean():
print('[clean]')
if WEB_EXT_OUT.exists():
shutil.rmtree(WEB_EXT_OUT)
os.mkdir(WEB_EXT_OUT)
if WEB_EXT_OUT.exists():
shutil.rmtree(WEB_EXT_OUT_INLINE)
os.mkdir(WEB_EXT_OUT_INLINE)
def build_content_script(src, dest):
print(f'[build_content_script {src}]')
data = src.read_bytes()
data = content_script_embed.from_script(data)
write_to(dest, data)
# -
clean()
write_to(WEB_EXT_OUT / 'rr-record.js', (DIR / 'rr-record.js').read_bytes())
build_content_script(DIR / 'rr-record.js', WEB_EXT_OUT_INLINE / 'rr-record.content.js')
print('Build complete.')