forked from fabiomcosta/mootools-meio-autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·89 lines (76 loc) · 2.98 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
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
import os
class Builder:
javascript_files = []
extra_zip_files = []
def __init__(self, build_folder='./', minify_postfix='min', extension='js'):
self.minify_posfix = minify_postfix
self.build_folder = build_folder
self.extension = '.' + extension
def add_files(self, list_name, files, root='', path='', extension=''):
if type(files) == dict:
for key in files.keys():
self.add_files(list_name, files[key], root, path=path + key + '/', extension=extension)
elif type(files) == list or type(files) == tuple:
for _file in files:
getattr(self, list_name).append((_file, root + path + _file + extension))
elif type(files) == str:
getattr(self, list_name).append((files, root + path + files + extension))
def read_file(self, _file):
f = open(_file, 'r')
ret = []
try:
ret = f.readlines()
finally:
f.close()
ret.append('\r\n')
return ret
def create_built_file(self):
file_name = self.build_folder + self.file_name + self.extension
built_file = open(file_name, 'w+')
try:
for name, absolute_name in self.javascript_files:
built_file.writelines(self.read_file(absolute_name))
finally:
built_file.close()
print '** Succesfully created "' + file_name + '" file. **'
def create_minified_file(self):
uncompressed_file = self.build_folder + self.file_name + self.extension
compressed_file = self.build_folder + self.file_name + '.' + self.minify_posfix + self.extension
os.system('java -jar Assets/yui.jar --type js --charset utf8 -o %(compressed)s %(uncompressed)s' % {
'uncompressed': uncompressed_file,
'compressed': compressed_file
})
print '** Succesfully created minified file. **'
def build(self, file_name, files, root='Source/'):
self.file_name = file_name
try:
os.mkdir(self.build_folder)
except OSError:
# ok, the folder was there already
pass
self.add_files('javascript_files', files, root=root, extension=self.extension)
print 'Starting to build ' + file_name + ' files...'
self.create_built_file()
self.create_minified_file()
print ''
self.javascript_files = []
if __name__ == '__main__':
builder = Builder()
builder.build('Meio.Autocomplete', (
'BGIframe',
'Meio.Base',
'Meio.Widget',
'Meio.Element',
'Meio.Element.Field',
'Meio.Element.List',
'Meio.Autocomplete',
'Meio.Autocomplete.Select',
'Meio.Autocomplete.Select.One',
'Meio.Autocomplete.Filter',
'Meio.Autocomplete.Data',
'Meio.Autocomplete.Data.Source',
'Meio.Autocomplete.Data.Request',
'Meio.Autocomplete.Data.Request.URL',
'Meio.Autocomplete.Cache',
))