Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial (unfinished) implementation of simple build script.

  • Loading branch information...
commit 8f28680c1f8fe6293a7c7636783e69c1f0005ba5 1 parent 273ac6f
@chromakode authored
View
54 build.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+import sys
+import os, os.path
+import shutil
+import subprocess
+from xml.dom import minidom
+
+"""Minifies JS and copies to build/ directory"""
+
+join = os.path.join
+
+def touch_dir(path):
+ if not os.path.isdir(path):
+ print "Creating directory {0}".format(path)
+
+
+def clean(build_dir):
+ if os.path.isdir(build_dir):
+ print "Removing existing directory: {0}".format(build_dir)
+ shutil.rmtree(build_dir)
+
+def build(build_dir, minified_name):
+ to_minify = []
+
+ touch_dir(build_dir)
+
+ print "Writing index.html"
+ document = minidom.parse("src/index.html")
+ mini_script = document.createElement("script")
+ mini_script.setAttribute("src", minified_name)
+ for script in document.getElementsByTagName("script"):
+ src = script.getAttribute("src")
+
+ # Minify only JS with relative paths
+ if not src.startswith("http"):
+ to_minify.append(join("src", src))
+ script.parentNode.replaceChild(mini_script, script)
+
+ document.writexml(open(join(build_dir, "index.html"), "w"))
+
+ print "Minifying: {0}".format(", ".join(to_minify))
+ minified_path = join(build_dir, minified_name)
+ if os.path.isfile(minified_path):
+ os.remove(minified_path)
+ mini_file = open(minified_path, "a")
+ for mini_src in to_minify:
+ subprocess.call(["java", "-jar", "tools/yuicompressor-2.4.2.jar", mini_src],
+ stdout=mini_file)
+
+if __name__=="__main__":
+ if len(sys.argv) == 2 and sys.argv[1] == "clean":
+ clean("build")
+ else:
+ build("build", "xkcd_cli_all.js")
View
0  cli.js → src/cli.js
File renamed without changes
View
1  index.html → src/index.html
@@ -12,6 +12,7 @@
<link rel="stylesheet" type="text/css" href="style.css" media="screen" title="Default" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+
<script type="text/javascript" src="jquery.hotkeys-0.7.9.js"></script>
<script type="text/javascript" src="jquery.browser.js"></script>
<script type="text/javascript" src="jquery.konami.js"></script>
View
0  jquery.browser.js → src/jquery.browser.js
File renamed without changes
View
0  jquery.hotkeys-0.7.9.js → src/jquery.hotkeys-0.7.9.js
File renamed without changes
View
0  jquery.konami.js → src/jquery.konami.js
File renamed without changes
View
0  over9000.png → src/over9000.png
File renamed without changes
View
0  style.css → src/style.css
File renamed without changes
View
0  xkcd_cli.js → src/xkcd_cli.js
File renamed without changes
View
BIN  tools/yuicompressor-2.4.2.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.