-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler.py
54 lines (44 loc) · 1.6 KB
/
compiler.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
import os
import glob
import jsmin
class JSCompiler:
def __init__(self, folder, js_files, output_file):
self.folder = folder
self.js_files =js_files
self.output_file = output_file
self.debug_pattern = ['@@@IF NOT BUILD@@@', '@@@ENDIF@@@']
def compile(self):
with open(self.output_file, 'w') as outfile:
for js_file in self.js_files:
with open( os.path.join(self.folder, js_file), 'r') as infile:
lines = infile.readlines()
# Skip any lines between the debug patterns
skip = False
for line in lines:
if self.debug_pattern[0] in line:
skip = True
elif self.debug_pattern[1] in line:
skip = False
elif not skip:
outfile.write(line)
with open(self.output_file, 'r') as infile:
minified = jsmin.jsmin(infile.read())
with open(self.output_file, 'w') as outfile:
outfile.write(minified)
def list_from_dir(dir):
components = []
_dir = os.path.join(os.path.dirname(__file__), "src", dir)
for file in glob.glob(_dir + "/*.js"):
components.append(file)
return components
if __name__ == '__main__':
js_files = [
'core.js',
'helper.js',
] + list_from_dir("helpers") + [
'component.js',
] + list_from_dir("components") + [
'fabr.js',
]
compiler = JSCompiler('src', js_files, 'fabr.min.js')
compiler.compile()