1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | import sys
|
---|
4 |
|
---|
5 | if sys.version_info < (2, 7):
|
---|
6 | print("This script requires at least Python 2.7.")
|
---|
7 | print("Please, update to a newer version: http://www.python.org/download/releases/")
|
---|
8 | exit()
|
---|
9 |
|
---|
10 | import argparse
|
---|
11 | import json
|
---|
12 | import os
|
---|
13 | import shutil
|
---|
14 | import tempfile
|
---|
15 |
|
---|
16 |
|
---|
17 | def main(argv=None):
|
---|
18 |
|
---|
19 | parser = argparse.ArgumentParser()
|
---|
20 | parser.add_argument('--include', action='append', required=True)
|
---|
21 | parser.add_argument('--externs', action='append', default=['externs/common.js'])
|
---|
22 | parser.add_argument('--minify', action='store_true', default=False)
|
---|
23 | parser.add_argument('--output', default='../../build/three.js')
|
---|
24 | parser.add_argument('--sourcemaps', action='store_true', default=False)
|
---|
25 |
|
---|
26 | args = parser.parse_args()
|
---|
27 |
|
---|
28 | output = args.output
|
---|
29 |
|
---|
30 | # merge
|
---|
31 |
|
---|
32 | print(' * Building ' + output)
|
---|
33 |
|
---|
34 | # enable sourcemaps support
|
---|
35 |
|
---|
36 | if args.sourcemaps:
|
---|
37 | sourcemap = output + '.map'
|
---|
38 | sourcemapping = '\n//@ sourceMappingURL=' + sourcemap
|
---|
39 | sourcemapargs = ' --create_source_map ' + sourcemap + ' --source_map_format=V3'
|
---|
40 | else:
|
---|
41 | sourcemap = sourcemapping = sourcemapargs = ''
|
---|
42 |
|
---|
43 | fd, path = tempfile.mkstemp()
|
---|
44 | tmp = open(path, 'w')
|
---|
45 | sources = []
|
---|
46 |
|
---|
47 | for include in args.include:
|
---|
48 | with open('includes/' + include + '.json','r') as f:
|
---|
49 | files = json.load(f)
|
---|
50 | for filename in files:
|
---|
51 | filename = '../../' + filename;
|
---|
52 | sources.append(filename)
|
---|
53 | with open(filename, 'r') as f:
|
---|
54 | tmp.write(f.read())
|
---|
55 | tmp.write('\n')
|
---|
56 |
|
---|
57 | tmp.close()
|
---|
58 |
|
---|
59 | # save
|
---|
60 |
|
---|
61 | if args.minify is False:
|
---|
62 | shutil.copy(path, output)
|
---|
63 | os.chmod(output, 0o664); # temp files would usually get 0600
|
---|
64 |
|
---|
65 | else:
|
---|
66 |
|
---|
67 | externs = ' --externs '.join(args.externs)
|
---|
68 | source = ' '.join(sources)
|
---|
69 | cmd = 'java -jar compiler/compiler.jar --warning_level=VERBOSE --jscomp_off=globalThis --externs %s --jscomp_off=checkTypes --language_in=ECMASCRIPT5_STRICT --js %s --js_output_file %s %s' % (externs, source, output, sourcemapargs)
|
---|
70 | os.system(cmd)
|
---|
71 |
|
---|
72 | # header
|
---|
73 |
|
---|
74 | with open(output,'r') as f: text = f.read()
|
---|
75 | with open(output,'w') as f: f.write('// three.js - http://github.com/mrdoob/three.js\n' + text + sourcemapping)
|
---|
76 |
|
---|
77 | os.close(fd)
|
---|
78 | os.remove(path)
|
---|
79 |
|
---|
80 |
|
---|
81 | if __name__ == "__main__":
|
---|
82 | main()
|
---|