-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack.py
More file actions
38 lines (27 loc) · 1020 Bytes
/
Copy pathpack.py
File metadata and controls
38 lines (27 loc) · 1020 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
import re
import os
import glob
import base64
import shutil
if (len(glob.glob('./dist/*.js')) == 0):
raise Exception('No javascript files found')
file = open("./dist/index.html", "r+")
content = file.read()
jsFileName = re.search("(?<=src=\.\/).*?\.js", content)[0]
jsFile = open(f"./dist/{jsFileName}")
js = jsFile.read().replace('\\n', '\\\\n')
spriteSheetName = re.search("(?<=src=\.\/assets\/).*?(?= )", content)[0]
with open(f"./dist/assets/{spriteSheetName}", 'rb') as image_file:
base64_bytes = base64.b64encode(image_file.read())
spriteSheetData = base64_bytes.decode()
spriteSheetData = f'"data:image/png;base64, {spriteSheetData}"'
replaced = re.sub("\ssrc=.*?\.js", "", content)
replaced = re.sub("(?<=src=)\.\/assets\/.*?(?= )", spriteSheetData, replaced)
replaced = re.sub("(?<=true>)(?=<\/script)", js, replaced)
file.seek(0)
file.write(replaced)
file.close()
jsFile.close()
os.remove(f'./dist/{jsFileName}')
os.remove(f'./dist/{jsFileName}.map')
shutil.rmtree(f'./dist/assets/')