forked from madneal/export-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
51 lines (45 loc) · 1.38 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import shutil
import zipfile
import json
zip_dir = 'export-to-markdown'
zip_filename = zip_dir + '.zip'
def create_dir():
os.makedirs(zip_dir)
def move_files():
shutil.copytree('icons', zip_dir + '/icons')
shutil.copytree('scripts', zip_dir + '/scripts')
shutil.copyfile('manifest.json', zip_dir + '/manifest.json')
shutil.copyfile('popup.html', zip_dir + '/popup.html')
shutil.copyfile('load.svg', zip_dir + '/load.svg')
def zip():
zipf = zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(zip_dir):
for file in files:
print(root + ':' + file)
zipf.write(os.path.join(root, file))
def modify_version():
manifest_path = zip_dir + '/manifest.json'
with open(manifest_path, 'r') as f:
manifest = json.load(f)
version = manifest['version']
version = version.replace('.', '')
version = int(version)
version = version + 1
version = str(version)
version = '.'.join(version)
if len(version) < 4:
version = '0.' + version
manifest['version'] = version
with open(manifest_path, 'w') as f:
json.dump(manifest, f, indent=4, separators=(',', ':'))
shutil.copyfile(manifest_path, 'manifest.json')
if __name__ == '__main__':
if os.path.isdir(zip_dir):
shutil.rmtree(zip_dir)
if os.path.exists(zip_filename):
os.remove(zip_filename)
create_dir()
move_files()
modify_version()
zip()