This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.py
79 lines (61 loc) · 2.36 KB
/
build.py
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
#!/bin/python
import os
import sys
import httplib
import urllib
import json
from StringIO import StringIO
import shutil
"""
Script for bundling Arduino Blockly extensions into one Node.JS module.
Based on build.py found in https://github.com/google/blockly
"""
# eslint doesn't play nice with closure compiled code
UNIHEADER = "/* eslint no-unused-expressions: 0, no-undef: 0 */"
# self global doesn't exist in react
UNIHEADER += "var self = window.self;"
BLOCKLY_PROVIDES = [ "Blockly", "Blockly.Block", "Blockly.FieldDropdown",
"Blockly.Generator", "Blockly.Procedures", "Blockly.Workspace", "Blockly.Msg", "Blockly.utils" ]
BLOCKS_PROVIDES = [ "Blockly.Blocks", "Blockly.Colours", "Blockly.Constants.Logic", "Blockly.Constants.Loops",
"Blockly.Constants.Math", "Blockly.Constants.Text", "Blockly.Constants.Procedures", "Blockly.Constants.Variables" ]
OUTPUT = os.path.join("client", "src", "blockly")
def import_path(path):
"""
Import a file with full path specification.
Allows one to import from any directory, something __import__ does not do.
Args:
path: Path and filename of import.
Returns:
An imported module.
"""
path, filename = os.path.split(path)
filename, ext = os.path.splitext(filename)
sys.path.append(path)
module = __import__(filename)
reload(module) # Might be out of date.
del sys.path[-1]
return module
def copy(file, provides, requires = None):
input = open(os.path.join("..", "pxt-blockly", file), "r")
output = open(os.path.join(OUTPUT, file), "w")
output.write(UNIHEADER + "\n")
if requires is not None:
for require in requires:
output.write("goog.require('" + require + "');\n")
for provide in provides:
output.write("goog.provide('" + provide + "');\n")
output.write(input.read())
input.close()
output.close()
if __name__ == "__main__":
print("Compiling PXT Blockly...")
try:
pxt = import_path(os.path.join("..", "pxt-blockly", "build.py"))
except ImportError:
print("Error importing ../pxt-blockly/build.py")
exit(1)
print("Copying files...")
copy("blockly_compressed.js", BLOCKLY_PROVIDES)
copy("blocks_compressed.js", BLOCKS_PROVIDES, [ "Blockly" ])
shutil.copy(os.path.join("..", "pxt-blockly", "msg", "messages.js"), os.path.join(OUTPUT, "en.js"))
print("Done.")