-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbuildRSnew.py
More file actions
109 lines (97 loc) · 3.59 KB
/
Copy pathbuildRSnew.py
File metadata and controls
109 lines (97 loc) · 3.59 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from __future__ import print_function, division
"""This python program converts various parts of glowscript from the most
convenient format for modification into the most convenient format for
deployment.
* Take shaders from shaders/*.shader and combine them into lib/glow/shaders.gen.js
TODO
* Come up with a less painful model for development than running this after every change
* Combine and minify lib/*.js into ide.min.js, run.min.js, and embed.min.js
"""
from glob import glob
import re, os, subprocess
shader_file = ["Export({ shaders: {"]
for fn in glob("shaders/*.shader"):
name = re.match(r"^shaders[/\\]([^.]+).shader$", fn).group(1)
f = open(fn, "rt").read()
shader_file.append( '"' + name + '":' + repr(f) + "," )
shader_file.append("}});")
shader_file = "\n".join(shader_file)
open("lib/glow/shaders.gen.js", "wb").write(shader_file)
version = "1.2dev"
# TODO: Extract this information from run.js
glowscript_libraries = {
"run": [
"../lib/jquery/jquery.mousewheel.js",
"../lib/flot/jquery.flot.min.js",
"../lib/flot/jquery.flot.crosshair_GS.js",
"../lib/glMatrix.js",
"../lib/webgl-utils.js",
"../lib/glow/property.js",
"../lib/glow/vectors.js",
"../lib/glow/mesh.js",
"../lib/glow/canvas.js",
"../lib/glow/orbital_camera.js",
"../lib/glow/autoscale.js",
"../lib/glow/WebGLRenderer.js",
"../lib/glow/graph.js",
"../lib/glow/color.js",
"../lib/glow/primitives.js",
"../lib/glow/api_misc.js",
"../lib/glow/shaders.gen.js"
],
"compile": [
"../lib/compiler.js",
"../lib/papercomp.js",
"../lib/transform-all.js",
"../lib/coffee-script.js"],
"RSrun": [
"../lib/rapydscript/stdlib.js"
],
"RScompile": [
"../lib/compiler.js",
"../lib/papercomp.js",
"../lib/transform-all.js",
"../lib/rapydscript/baselib.js",
"../lib/rapydscript/utils.js",
"../lib/rapydscript/ast.js",
"../lib/rapydscript/output.js",
"../lib/rapydscript/parse.js"],
"ide": []
}
def combine(inlibs):
all = [
"/*This is a combined, compressed file. Look at https://github.com/BruceSherwood/glowscript for source code and copyright information.*/",
";(function(){})();"
]
for fn in inlibs:
if fn.startswith("../"): fn = fn[3:]
all.append( open(fn, "rt").read() )
return "\n".join(all)
def minify(inlibs, inlibs_nomin, outlib):
all = combine(inlibs)
outf = open(outlib, "wb")
if True: # minify if True
env = os.environ.copy()
env["NODE_PATH"] = "build-tools/UglifyJS"
uglify = subprocess.Popen( "build-tools/node.exe build-tools/UglifyJS/bin/uglifyjs",
stdin=subprocess.PIPE,
stdout=outf,
env=env
)
uglify.communicate( all )
rc = uglify.wait()
print("uglify " + outlib + ":", rc)
if rc != 0:
print("Something went wrong")
else:
outf.write(all)
outf.write( combine(inlibs_nomin) )
outf.close()
minify( glowscript_libraries["run"], [], "package/glow." + version + ".min.js" )
print('Finished glow run-time package')
minify( glowscript_libraries["compile"], [], "package/compiler." + version + ".min.js" )
print('Finished compiler package')
minify( glowscript_libraries["RSrun"], [], "package/RSrun." + version + ".min.js" )
print('Finished RapydScript run-time package')
minify( glowscript_libraries["RScompile"], [], "package/RScompiler." + version + ".min.js" )
print('Finished GlowScript package')