]> jfr.im git - irc/quakenet/qwebirc.git/blame - compile.py
Cleanup compiling code and add clean/mkstatic.
[irc/quakenet/qwebirc.git] / compile.py
CommitLineData
8b8ebb78 1#!/usr/bin/env python
01a3d0e1
CP
2import pages, os, subprocess, pagegen
3
4COPYRIGHT = open("js/copyright.js", "rb").read()
8b8ebb78
CP
5
6def jarit(src):
7 return subprocess.Popen(["java", "-jar", "bin/yuicompressor-2.3.5.jar", src], stdout=subprocess.PIPE).communicate()[0]
8
01a3d0e1
CP
9def jmerge_files(prefix, output, files, *args):
10 global COPYRIGHT
8b8ebb78 11 output = output + ".js"
01a3d0e1 12 o = os.path.join(prefix, "compiled", output)
8b8ebb78
CP
13 merge_files(o, files, *args)
14 compiled = jarit(o)
15 os.unlink(o)
01a3d0e1
CP
16 f = open(os.path.join(prefix, "static", "js", output), "wb")
17 f.write(COPYRIGHT)
8b8ebb78
CP
18 f.write(compiled)
19 f.close()
20
21def 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
01a3d0e1
CP
30def main(outputdir="."):
31 pagegen.main(outputdir)
8b8ebb78 32
01a3d0e1 33 coutputdir = os.path.join(outputdir, "compiled")
8b8ebb78 34 try:
01a3d0e1 35 os.mkdir(coutputdir)
8b8ebb78
CP
36 except:
37 pass
38
01a3d0e1 39 jmerge_files(outputdir, "qwebirc", pages.DEBUG_BASE, lambda x: os.path.join("js", x + ".js"))
8b8ebb78 40
01a3d0e1
CP
41 for uiname, value in pages.UIs.items():
42 jmerge_files(outputdir, uiname, value["uifiles"], lambda x: os.path.join("js", "ui", "frontends", x + ".js"))
8b8ebb78 43
01a3d0e1 44 os.rmdir(coutputdir)
8b8ebb78
CP
45
46if __name__ == "__main__":
01a3d0e1 47 main()
8b8ebb78 48