/
build.py
98 lines (80 loc) · 2.69 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
90
91
92
93
94
95
96
97
import css_compress
import getopt
import js_compress
import sys
import textwrap
def usage():
str = '''
USAGE:
CLI:
python3 build.py -v 3.0.0 --js_src src/ --css_src resources/css/ --build_dir build
As an imported module:
build.build(version, js_src[, css_src, build_dir='.'])
--version, -v The version of the minified script, must be specified.
--js_src The location of the JavaScript source files, must be specified.
--css_src The location of the CSS files.
--build_dir The location where the minified files will be moved, defaults to cwd.
'''
print(textwrap.dedent(str))
def main(argv):
version = ''
js_src = ''
css_src = None
build_dir = '.'
try:
opts, args = getopt.getopt(argv, 'hv:', ['help', 'version=', 'js_src=', 'css_src=', 'build_dir='])
except getopt.GetoptError:
print('Error: Unrecognized flag.')
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
sys.exit(0)
elif opt in ('-v', '--version'):
version = arg
elif opt == '--js_src':
js_src = arg
elif opt == '--css_src':
css_src = arg
elif opt == '--build_dir':
build_dir = arg
build(version, js_src, css_src, build_dir)
def build(version, js_src, css_src=None, build_dir='.'):
if not version:
print('Error: You must provide a version.')
sys.exit(2)
if not js_src:
print('Error: You must provide the location of the JavaScript source files.')
sys.exit(2)
# The order is very important due to some dependencies between scripts, so specify the dependency order here.
dependencies = [
'JSLITE.prototype.js',
'JSLITE.js',
'JSLITE.Element.js',
'JSLITE.Composite.js',
'JSLITE.Observer.js'
]
# copyright = '''\
# /*
# * jsLite {version!s}
# *
# * Copyright (c) 2009 - 2015 Benjamin Toll (benjamintoll.com)
# * Dual licensed under the MIT (MIT-LICENSE.txt)
# * and GPL (GPL-LICENSE.txt) licenses.
# *
# */
# '''.format(**locals())
#
# # Write to a buffer.
# buff = [textwrap.dedent(copyright)]
js_output = 'JSLITE_' + version + '.min.js'
css_output = 'JSLITE_CSS_' + version + '.min.js'
js_compress.compress(js_src, js_output, build_dir, version, dependencies)
if css_src:
css_compress.compress(css_src, css_output, build_dir, version)
if __name__ == '__main__':
if len(sys.argv) == 1:
usage()
sys.exit(2)
main(sys.argv[1:])