-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.py
79 lines (59 loc) · 2.33 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests
import os
import threading
import sys
import shutil
def createJSFile(inputFile='public/', outputFile='templates/game-scripts-min.html'):
script_file = open(inputFile)
script = script_file.read()
url = 'https://www.toptal.com/developers/javascript-minifier/raw'
myobj = {'input': script}
x = requests.post(url, data=myobj)
print(x.status_code)
# print(x.text)
minified_file = open(outputFile, 'w')
minified_file.write(str(x.text))
print(outputFile + " file made successful")
script_file.close()
minified_file.close()
def createCSSMain(inputFile='static/css/main.css', outputFile='static/css/min/main.css'):
css_file = open(inputFile)
css = css_file.read()
# print(css)
url = 'https://cssminifier.com/raw'
data = {'input': css}
x = requests.post(url, data=data)
print(x.status_code)
# print(x.text)
minified_file = open(outputFile, 'w')
minified_file.write(x.text)
print(outputFile + " file made successful")
css_file.close()
minified_file.close()
if __name__ == '__main__':
try:
shutil.rmtree(os.getcwd() + "/build")
except:
print("Build not found, automatically will be created.")
shutil.copytree(os.getcwd() + "/public", os.getcwd() + "/build")
for subdir, dirs, files in os.walk(os.getcwd() + "/build/css"):
for file in files:
filepath = subdir + os.sep + file
if filepath.split(".")[-1] == "css":
createCSSMain(inputFile=filepath, outputFile=filepath)
for subdir, dirs, files in os.walk(os.getcwd() + "/build/js"):
for file in files:
filepath = subdir + os.sep + file
if filepath.split(".")[-1] == "js":
createJSFile(inputFile=filepath, outputFile=filepath)
firebase_file = os.getcwd() + "/firebase.json"
json_data = open(firebase_file).read()
json_data = json_data.replace('"public": "public"', '"public": "build"')
open(firebase_file, 'w').write(json_data)
print("Destination changed to build")
print("Running firebase deploy!")
os.system("firebase deploy --only=hosting")
json_data = open(firebase_file).read()
json_data = json_data.replace('"public": "build"', '"public": "public"')
open(firebase_file, 'w').write(json_data)
print("Destination changed back to public")