-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvulcan.py
executable file
·83 lines (68 loc) · 2.86 KB
/
vulcan.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
80
81
82
83
#!/usr/bin/env python3
import os,sys
import fileinput
import argparse
from jsmin import jsmin
def replacein(inputfile):
with fileinput.FileInput(inputfile, inplace=True) as file:
for line in file:
print(line.replace('elements.html', 'elements-built.html'), end='')
with fileinput.FileInput(inputfile, inplace=True) as file:
for line in file:
print(line.replace('app.js', 'app.min.js'), end='')
def replaceout(inputfile):
with fileinput.FileInput(inputfile, inplace=True) as file:
for line in file:
print(line.replace('elements-built.html', 'elements.html'), end='')
with fileinput.FileInput(inputfile, inplace=True) as file:
for line in file:
print(line.replace('app.min.js', 'app.js'), end='')
def changedebug(mode):
if mode == 'build':
with fileinput.FileInput('Settings.py', inplace=True) as file:
for line in file:
print(line.replace('DEBUG = True', 'DEBUG = False'), end='')
if mode == 'dev':
with fileinput.FileInput('Settings.py', inplace=True) as file:
for line in file:
print(line.replace('DEBUG = False', 'DEBUG = True'), end='')
def vulcanize():
os.system('rm -f easyweb/static/elements/elements-built.html')
command = 'vulcanize easyweb/static/elements/elements.html --out-html easyweb/static/elements/elements-built.html'
os.system(command)
def minimize():
with open('easyweb/static/scripts/app.js') as js_file:
minified = jsmin(js_file.read())
with open('easyweb/static/scripts/app.min.js','w') as js_file:
js_file.write(minified)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--build","-b", help="vulcanize",action="store_true")
parser.add_argument("--dev","-d", help="(de)vulcanize",action="store_true")
args = parser.parse_args()
if args.build:
vulcanize()
minimize()
replacein('templates/activate.html')
replacein('templates/login-public.html')
replacein('templates/main-public.html')
replacein('templates/reset.html')
replacein('templates/signup.html')
replacein('templates/404.html')
replacein('templates/service-down.html')
replacein('templates/limited.html')
replacein('templates/stats.html')
changedebug('build')
#changeports('build')
if args.dev:
replaceout('templates/activate.html')
replaceout('templates/login-public.html')
replaceout('templates/main-public.html')
replaceout('templates/reset.html')
replaceout('templates/signup.html')
replaceout('templates/404.html')
replaceout('templates/service-down.html')
replaceout('templates/limited.html')
replaceout('templates/stats.html')
changedebug('dev')
#changeports('dev')