-
Notifications
You must be signed in to change notification settings - Fork 15
/
vulcan.py
executable file
·67 lines (52 loc) · 2.18 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
#!/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 static/des_components/elements-built.html')
command = 'vulcanize static/des_components/elements.html --exclude static/bower_components/polymer/lib/legacy/ --out-html static/des_components/elements-built.html'
os.system(command)
def minimize():
with open('static/scripts/app.js') as js_file:
minified = jsmin(js_file.read())
with open('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/index.html')
changedebug('build')
#changeports('build')
if args.dev:
replaceout('templates/index.html')
changedebug('dev')
#changeports('dev')