]> jfr.im git - irc/quakenet/qwebirc.git/blob - bin/compile.py
Merge all javascript into one file when we 'compile'.
[irc/quakenet/qwebirc.git] / bin / compile.py
1 #!/usr/bin/env python
2 import pages, os, subprocess, pagegen
3
4 COPYRIGHT = open("js/copyright.js", "rb").read()
5
6 def jarit(src):
7 return subprocess.Popen(["java", "-jar", "bin/yuicompressor-2.3.5.jar", src], stdout=subprocess.PIPE).communicate()[0]
8
9 def jmerge_files(prefix, suffix, output, files, *args):
10 global COPYRIGHT
11 output = output + "." + suffix
12 o = os.path.join(prefix, "compiled", output)
13 merge_files(o, files, *args)
14 compiled = jarit(o)
15 os.unlink(o)
16 f = open(os.path.join(prefix, "static", suffix, output), "wb")
17 f.write(COPYRIGHT)
18 f.write(compiled)
19 f.close()
20
21 def merge_files(output, files, root_path=lambda x: x):
22 f = open(output, "wb")
23
24 for x in files:
25 f2 = open(root_path(x), "rb")
26 f.write(f2.read())
27 f2.close()
28 f.close()
29
30 def main(outputdir=".", produce_debug=False):
31 pagegen.main(outputdir, produce_debug=produce_debug)
32
33 coutputdir = os.path.join(outputdir, "compiled")
34 try:
35 os.mkdir(coutputdir)
36 except:
37 pass
38
39 try:
40 os.mkdir(os.path.join(outputdir, "static", "css"))
41 except:
42 pass
43
44 #jmerge_files(outputdir, "js", "qwebirc", pages.DEBUG_BASE, lambda x: os.path.join("js", x + ".js"))
45
46 for uiname, value in pages.UIs.items():
47 csssrc = pagegen.csslist(uiname, True)
48 jmerge_files(outputdir, "css", uiname, csssrc)
49 #jmerge_files(outputdir, "js", uiname, value["uifiles"], lambda x: os.path.join("js", "ui", "frontends", x + ".js"))
50
51 alljs = []
52 for y in pages.JS_BASE:
53 alljs.append(os.path.join("static", "js", y + ".js"))
54 for y in value.get("buildextra", []):
55 alljs.append(os.path.join("static", "js", "%s.js" % y))
56 for y in pages.DEBUG_BASE:
57 alljs.append(os.path.join("js", y + ".js"))
58 for y in value["uifiles"]:
59 alljs.append(os.path.join("js", "ui", "frontends", y + ".js"))
60 jmerge_files(outputdir, "js", uiname, alljs)
61
62 os.rmdir(coutputdir)
63
64 if __name__ == "__main__":
65 main()
66