|
| 1 | +#from __future__ import print_function, division |
| 2 | + |
| 3 | +# This is the modified Python 3 build file, used in building GlowScript |
| 4 | +# according to the scheme described in docs/MakingNewVersion.txt. |
| 5 | +# A more sophisticated build program is build_cli.py contributed by Iblis Lin. |
| 6 | + |
| 7 | +# The main runtime library glow.X.Y.min.js apparently is too large to use |
| 8 | +# in Jupyter VPython, so this program in addition to producing glow.X.Y.min.js |
| 9 | +# also produces the two pieces glow.X.Ya.min.js and glow.X.Yb.min.js used in |
| 10 | +# Jupyter VPython. |
| 11 | + |
| 12 | +"""This python program converts various parts of glowscript from the most |
| 13 | +convenient format for modification into the most convenient format for |
| 14 | +deployment. |
| 15 | +
|
| 16 | +* Take shaders from shaders/*.shader and combine them into lib/glow/shaders.gen.js |
| 17 | +
|
| 18 | +TODO |
| 19 | +
|
| 20 | +* Come up with a less painful model for development than running this after every change |
| 21 | +* Combine and minify lib/*.js into ide.min.js, run.min.js, and embed.min.js |
| 22 | +""" |
| 23 | + |
| 24 | +from glob import glob |
| 25 | +import re, os, subprocess |
| 26 | +import platform |
| 27 | + |
| 28 | + |
| 29 | +##shader_file = ["Export({ shaders: {"] |
| 30 | +##for fn in sorted(glob("shaders/*.shader")): |
| 31 | +## name = re.match(r"^shaders[/\\]([^.]+).shader$", fn).group(1) |
| 32 | +## f = open(fn, "rt").read() |
| 33 | +## shader_file.append( '"' + name + '":' + repr(f) + "," ) |
| 34 | +##shader_file.append("}});") |
| 35 | +##shader_file = "\n".join(shader_file) |
| 36 | +##open("lib/glow/shaders.gen.js", "wb").write(shader_file) |
| 37 | + |
| 38 | +version = "3.2" |
| 39 | +# TODO: Extract this information from run.js |
| 40 | + |
| 41 | +glowscript_libraries = { |
| 42 | + "run": [ |
| 43 | + "../lib/jquery/"+"2.1"+"/jquery.mousewheel.js", # use 2.1 lib with later versions |
| 44 | + "../lib/flot/jquery.flot.js", |
| 45 | + "../lib/flot/jquery.flot.crosshair_GS.js", |
| 46 | + "../lib/opentype/poly2tri.js", |
| 47 | + "../lib/opentype/opentype.js", |
| 48 | + "../lib/glMatrix.js", |
| 49 | + "../lib/webgl-utils.js", |
| 50 | + "../lib/glow/property.js", |
| 51 | +## "../lib/glow/vectors.js", |
| 52 | + "../lib/glow/vectors_no_overload.js", # glowcomm doesn't need or want overloading |
| 53 | + "../lib/glow/mesh.js", |
| 54 | + "../lib/glow/canvas.js", |
| 55 | + "../lib/glow/orbital_camera.js", |
| 56 | + "../lib/glow/autoscale.js", |
| 57 | + "../lib/glow/WebGLRenderer.js", |
| 58 | + "../lib/glow/graph.js", |
| 59 | + "../lib/glow/color.js", |
| 60 | + "../lib/glow/shapespaths.js", |
| 61 | + "../lib/glow/primitives.js", |
| 62 | + "../lib/glow/api_misc.js", |
| 63 | + "../lib/glow/extrude.js", |
| 64 | + "../lib/glow/shaders.gen.js" |
| 65 | + ], |
| 66 | + "plotly": [ |
| 67 | + "../lib/plotly.js" |
| 68 | + ] |
| 69 | + } |
| 70 | + |
| 71 | +def combine(inlibs): |
| 72 | + # Apparently uglify moves the following string to the end of the package. |
| 73 | + # "(function(){x})();" appears at the both the start and the end of the package. |
| 74 | + all = [ |
| 75 | + "/*This is a combined, compressed file. Look at https://github.com/BruceSherwood/glowscript for source code and copyright information.*/", |
| 76 | + ";(function(){})();" |
| 77 | + ] |
| 78 | + for fn in inlibs: |
| 79 | + if fn.startswith("../"): fn = fn[3:] |
| 80 | + all.append( open(fn, "r").read() ) |
| 81 | + return "\n".join(all) |
| 82 | + |
| 83 | +env = os.environ.copy() |
| 84 | +env["NODE_PATH"] = "build-tools/UglifyJS" |
| 85 | + |
| 86 | +def minify(inlibs, inlibs_nomin, outlib): |
| 87 | + all = combine(inlibs) |
| 88 | + outf = open(outlib, "w") |
| 89 | + |
| 90 | + if True: # minify if True |
| 91 | + if platform.system() == 'Darwin': # it's spelled a little differently on a mac |
| 92 | + uglify = subprocess.Popen( "node build-tools/Uglify-ES/uglify-es/bin/uglifyjs", |
| 93 | + shell=True, |
| 94 | + stdin=subprocess.PIPE, |
| 95 | + stdout=outf, |
| 96 | + stderr=outf, # write uglify errors into output file |
| 97 | + env=env |
| 98 | + ) |
| 99 | + else: |
| 100 | + uglify = subprocess.Popen( "build-tools/node.exe build-tools/Uglify-ES/uglify-es/bin/uglifyjs", |
| 101 | + stdin=subprocess.PIPE, |
| 102 | + stdout=outf, |
| 103 | + stderr=outf, # write uglify errors into output file |
| 104 | + env=env |
| 105 | + ) |
| 106 | + uglify.communicate( all.encode("utf-8") ) |
| 107 | + rc = uglify.wait() |
| 108 | + if rc != 0: |
| 109 | + print("Something went wrong") |
| 110 | + else: |
| 111 | + outf.write(all) |
| 112 | + outf.write( combine(inlibs_nomin) ) |
| 113 | + outf.close() |
| 114 | + |
| 115 | +minify( glowscript_libraries["run"], [], "ForInstalledPython/glow.min.js" ) |
| 116 | +print('Finished glow run-time package\n') |
| 117 | +minify( glowscript_libraries["plotly"], [], "ForInstalledPython/plotly.min.js" ) |
| 118 | +print('Finished glow run-time package\n') |
| 119 | + |
0 commit comments