-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
28 lines (22 loc) · 1.22 KB
/
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
import os
import zipfile
def zip_directory(base_dir, browser, exclude_list):
os.makedirs('dist', exist_ok=True)
exclude_list = set(exclude_list)
def should_include(path):
rel_path = os.path.relpath(path, base_dir)
return not any(rel_path.startswith(exclude) for exclude in exclude_list)
with zipfile.ZipFile(os.path.join(base_dir, f'dist/{browser}.zip'), 'w', zipfile.ZIP_DEFLATED) as zip_file:
zip_file.write(f'manifest_{browser}.json', arcname='manifest.json')
for foldername, subfolders, filenames in os.walk(base_dir):
subfolders[:] = [f for f in subfolders if should_include(os.path.join(foldername, f))]
for filename in filenames:
file_path = os.path.join(foldername, filename)
if should_include(file_path):
arcname = os.path.relpath(file_path, base_dir)
zip_file.write(file_path, arcname=arcname)
if __name__ == '__main__':
base_dir = os.path.dirname(os.path.abspath(__file__))
exclude_list = ['dist', 'manifest_chrome.json', 'manifest_firefox.json', 'build.py', '.git' ,'.gitignore']
for browser in ["chrome","firefox"]:
zip_directory(base_dir, browser, exclude_list)