-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.py
65 lines (53 loc) · 2.15 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
#!/usr/bin/python
"""
Build-script that brings together all the JS files for wii.js and
takes care of minifying it down to a decent size.
Before you even ask, no, we're not using uglify.js or Closure. Both
of them are simply too aggressive for their own good; while normally this
is an excellent feature to have, the JS engine that the Opera version on the Wii
uses has a really odd set of quirks when you start trying to get smart with code,
and YUI is the only minifier that doesn't appear to totally destroy it all through
obfuscation. We'll forego a few bytes to have the thing working. ;P
Uglify also requires Node.js. While I *love* Node, I'll wait until it's more readily
available on Windows - there are a large amount of Windows-based programmers that I'm
not keen on keeping out of development.
"""
import os
from subprocess import call
currdir = os.getcwd()
# The names of our JS files (minus the .js) that we want to build into the
# final distribution.
DEPENDENCIES = [
'wii',
'util',
'console',
'remote',
]
# What we're going to end up injecting as our core build, into core.js.
inject_build = ''
def minify_code(filename, final_filename):
"""
Dips out to Java/YUI compressor and runs the minifier on the specified file, dumping the
output into the specified final_filename.
"""
#cmd = 'java -jar %s/utilities/yuicompressor-2.4.2.jar %s -o %s' % (currdir, filename, final_filename)
call(['java', '-jar', '%s/utilities/yuicompressor-2.4.2.jar' % currdir, filename, '-o', final_filename])
# Run through each dependency, read it into "inject build", then do a simple split on the
# contents of core.js and wrap it all up.
for dependency in DEPENDENCIES:
f = open('%s/js/src/%s.js' % (currdir, dependency), 'r')
inject_build += f.read()
f.close()
# Open core.js, split it on our build spot, wrap junks.
f = open('%s/js/src/core.js' % currdir, 'r')
core = f.read()
f.close()
core = core.split('/*{{inject_build}}*/')
# Write out a non-minified build.
f = open('%s/js/wii.js' % currdir, 'w')
f.write(core[0])
f.write(inject_build)
f.write(core[1])
f.close()
# Write out a minified build.
minify_code('%s/js/wii.js' % currdir, '%s/js/wii.min.js' % currdir)