Ver Fonte

pull latest and generate html page

Vladislav Folts há 12 anos atrás
pai
commit
8cdcae0424
3 ficheiros alterados com 41 adições e 13 exclusões
  1. 1 0
      browser/__init__.py
  2. 14 13
      browser/linkjs.py
  3. 26 0
      build.py

+ 1 - 0
browser/__init__.py

@@ -0,0 +1 @@
+

+ 14 - 13
browser/linkjs.py

@@ -15,23 +15,23 @@ def extract_require(s):
 			return None
 	return m.group(3)
 
-def resolve_require(req, out, resolved, resolving):
-	if not os.path.exists(req):
+def resolve_require(req, out, resolved, resolving, dir):
+	if not os.path.exists(os.path.join(dir, req)):
 		raise Exception('cannot resolve "%s"' % req)
-	process(req, out, resolved, resolving)
+	process(req, out, resolved, resolving, dir)
 
-def process(path, out, resolved, resolving):
+def process(path, out, resolved, resolving, dir):
 	module_name = os.path.splitext(os.path.basename(path))[0]
 	if module_name in resolving:
 		raise Exception('cyclic import detected: "%s"' % module_name)
 	result = 'imports["%s"] = {};\n' % path
 	result += '(function %s(exports){\n' % module_name
-	with open(path) as f:
+	with open(os.path.join(dir, path)) as f:
 		for l in f:
 			req = extract_require(l)
 			if req and not req in resolved:
 				try:
-					resolve_require(req, out, resolved, resolving + [module_name])
+					resolve_require(req, out, resolved, resolving + [module_name], dir)
 				except Exception:
 					print('while resolving "%s"...' % module_name)
 					raise sys.exc_info()[1]
@@ -40,15 +40,16 @@ def process(path, out, resolved, resolving):
 	out.write(result)
 	resolved += [path]
 
-if __name__ == '__main__':
-	if len(sys.argv) != 3:
-		raise Exception("Usage: linkjs.py <input js> <output js>")
-
-	input_path = sys.argv[1]
-	output_path = sys.argv[2]
+def link(input_path, output_path, dir):
 	with open(output_path, "w") as out:
 		prolog = "var imports = {};\n"
 		prolog += 'function require(module){return imports[module];}\n'
 		out.write(prolog)
-		process(input_path, out, [], [])
+		process(input_path, out, [], [], dir)
+
+if __name__ == '__main__':
+	if len(sys.argv) != 3:
+		raise Exception("Usage: linkjs.py <input js> <output js>")
+
+	link(sys.argv[1], sys.argv[2], '.')
 

+ 26 - 0
build.py

@@ -0,0 +1,26 @@
+#!/usr/bin/python
+from browser.linkjs import link
+import os
+import shutil
+import sys
+
+def run(cmd):
+    code = os.system(cmd)
+    if code:
+        raise Exception('"%s" failed: %d' % (cmd, code))
+
+def build(out):
+    run('git pull')
+    if not os.path.exists(out):
+        os.mkdir(out)
+    link('oc.js', os.path.join(out, 'oc.js'), 'src')
+
+    with open('browser/oberonjs.html') as input:
+        with open(os.path.join(out, 'oberonjs.html'), 'w') as output:
+            output.write(input.read())
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        print 'Pull repo and build html page\nUsage: build.py <output directory>'
+        exit(-1)
+    build(sys.argv[1])