-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.py
38 lines (29 loc) · 876 Bytes
/
js.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
from . import action, File
from . import js_compilers
COMPILER_PREFERENCE = ['closure', 'uglifyjs', 'concatenate']
COMPILER_CLASS = {
'closure': js_compilers.ClosureCompiler,
'uglifyjs': js_compilers.UglifyJSCompiler,
'concatenate': js_compilers.ConcatenateCompiler
}
# TODO: Make this generic for all compilers, not just JS.
def get_compiler(preference=None):
if preference is None:
preference = COMPILER_PREFERENCE
for comp_name in preference:
compiler = COMPILER_CLASS[comp_name]()
if compiler.test():
return compiler
@action
def concatenate(source_files):
res = ''
for f in source_file:
res += f.read() + '\n'
return res
@action
def compile(source_files, target_path, method='concatenate'):
if method == 'concatenate':
out = File(target_path)
out.write(concatentae(source_files))
return out
raise Exception()