mirror of
https://github.com/google/blockly.git
synced 2026-02-01 13:10:22 +01:00
Merge pull request #209 from Immortalin/master
Fix potential issue with naming and merged changes from techplexengineer to ensure headless works
This commit is contained in:
128
build.py
128
build.py
@@ -75,62 +75,68 @@ class Gen_uncompressed(threading.Thread):
|
||||
self.search_paths = search_paths
|
||||
|
||||
def run(self):
|
||||
target_filename = "blockly_uncompressed.js"
|
||||
add_dependency = []
|
||||
base_path = calcdeps.FindClosureBasePath(self.search_paths)
|
||||
deps = calcdeps.BuildDependenciesFromFiles(self.search_paths)
|
||||
filenames = calcdeps.CalculateDependencies(self.search_paths,
|
||||
[os.path.join("core", "blockly.js")])
|
||||
|
||||
for dep in deps:
|
||||
if dep.filename in filenames:
|
||||
add_dependency.append(calcdeps.GetDepsLine(dep, base_path))
|
||||
add_dependency = "\n".join(add_dependency)
|
||||
# Find the Blockly directory name and replace it with a JS variable.
|
||||
# This allows blockly_uncompressed.js to be compiled on one computer and be
|
||||
# used on another, even if the directory name differs.
|
||||
m = re.search("[\\/]([^\\/]+)[\\/]core[\\/]blockly.js", add_dependency)
|
||||
add_dependency = re.sub("([\\/])" + re.escape(m.group(1)) +
|
||||
"([\\/]core[\\/])", '\\1" + dir + "\\2', add_dependency)
|
||||
|
||||
provides = []
|
||||
for dep in deps:
|
||||
if dep.filename in filenames:
|
||||
if not dep.filename.startswith(os.pardir + os.sep): # "../"
|
||||
provides.extend(dep.provides)
|
||||
provides.sort()
|
||||
|
||||
f = open(target_filename, "w")
|
||||
target_filename = 'blockly_uncompressed.js'
|
||||
f = open(target_filename, 'w')
|
||||
f.write(HEADER)
|
||||
f.write("""
|
||||
// 'this' is 'window' in a browser, or 'global' in node.js.
|
||||
this.BLOCKLY_DIR = (function() {
|
||||
// Find name of current directory.
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var re = new RegExp('(.+)[\/]blockly_uncompressed\.js$');
|
||||
for (var x = 0, script; script = scripts[x]; x++) {
|
||||
var match = re.exec(script.src);
|
||||
if (match) {
|
||||
return match[1];
|
||||
var isNodeJS = !!(typeof module !== 'undefined' && module.exports);
|
||||
|
||||
if (isNodeJS) {
|
||||
var window = {};
|
||||
require('../closure-library/closure/goog/bootstrap/nodejs')
|
||||
}
|
||||
|
||||
window.BLOCKLY_DIR = (function() {
|
||||
if (!isNodeJS)
|
||||
{
|
||||
// Find name of current directory.
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var re = new RegExp('(.+)[\/]blockly_uncompressed\.js$');
|
||||
for (var x = 0, script; script = scripts[x]; x++) {
|
||||
var match = re.exec(script.src);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
alert('Could not detect Blockly\\'s directory name.');
|
||||
}
|
||||
alert('Could not detect Blockly\\'s directory name.');
|
||||
return '';
|
||||
})();
|
||||
|
||||
this.BLOCKLY_BOOT = function() {
|
||||
// Execute after Closure has loaded.
|
||||
if (!this.goog) {
|
||||
alert('Error: Closure not found. Read this:\\n' +
|
||||
'developers.google.com/blockly/hacking/closure');
|
||||
}
|
||||
|
||||
// Build map of all dependencies (used and unused).
|
||||
var dir = this.BLOCKLY_DIR.match(/[^\\/]+$/)[0];
|
||||
window.BLOCKLY_BOOT = function() {
|
||||
var dir = '';
|
||||
if (isNodeJS) {
|
||||
require('../closure-library/closure/goog/bootstrap/nodejs')
|
||||
dir = 'blockly';
|
||||
} else {
|
||||
// Execute after Closure has loaded.
|
||||
if (!window.goog) {
|
||||
alert('Error: Closure not found. Read this:\\n' +
|
||||
'developers.google.com/blockly/hacking/closure');
|
||||
}
|
||||
dir = window.BLOCKLY_DIR.match(/[^\\/]+$/)[0];
|
||||
}
|
||||
""")
|
||||
f.write(add_dependency + "\n")
|
||||
f.write("\n")
|
||||
f.write("// Load Blockly.\n")
|
||||
add_dependency = []
|
||||
base_path = calcdeps.FindClosureBasePath(self.search_paths)
|
||||
for dep in calcdeps.BuildDependenciesFromFiles(self.search_paths):
|
||||
add_dependency.append(calcdeps.GetDepsLine(dep, base_path))
|
||||
add_dependency = '\n'.join(add_dependency)
|
||||
# Find the Blockly directory name and replace it with a JS variable.
|
||||
# This allows blockly_uncompressed.js to be compiled on one computer and be
|
||||
# used on another, even if the directory name differs.
|
||||
m = re.search('[\\/]([^\\/]+)[\\/]core[\\/]blockly.js', add_dependency)
|
||||
add_dependency = re.sub('([\\/])' + re.escape(m.group(1)) +
|
||||
'([\\/]core[\\/])', '\\1" + dir + "\\2', add_dependency)
|
||||
f.write(add_dependency + '\n')
|
||||
|
||||
provides = []
|
||||
for dep in calcdeps.BuildDependenciesFromFiles(self.search_paths):
|
||||
if not dep.filename.startswith(os.pardir + os.sep): # '../'
|
||||
provides.extend(dep.provides)
|
||||
provides.sort()
|
||||
f.write('\n')
|
||||
f.write('// Load Blockly.\n')
|
||||
for provide in provides:
|
||||
f.write("goog.require('%s');\n" % provide)
|
||||
|
||||
@@ -139,17 +145,17 @@ delete this.BLOCKLY_DIR;
|
||||
delete this.BLOCKLY_BOOT;
|
||||
};
|
||||
|
||||
if (typeof DOMParser == 'undefined' && typeof require == 'function') {
|
||||
// Node.js needs DOMParser loaded separately.
|
||||
var DOMParser = require('xmldom').DOMParser;
|
||||
if (isNodeJS) {
|
||||
window.BLOCKLY_BOOT()
|
||||
module.exports = Blockly;
|
||||
} else {
|
||||
// Delete any existing Closure (e.g. Soy's nogoog_shim).
|
||||
document.write('<script>var goog = undefined;</script>');
|
||||
// Load fresh Closure Library.
|
||||
document.write('<script src="' + window.BLOCKLY_DIR +
|
||||
'/../closure-library/closure/goog/base.js"></script>');
|
||||
document.write('<script>window.BLOCKLY_BOOT()</script>');
|
||||
}
|
||||
|
||||
// Delete any existing Closure (e.g. Soy's nogoog_shim).
|
||||
document.write('<script>var goog = undefined;</script>');
|
||||
// Load fresh Closure Library.
|
||||
document.write('<script src="' + this.BLOCKLY_DIR +
|
||||
'/../closure-library/closure/goog/base.js"></script>');
|
||||
document.write('<script>this.BLOCKLY_BOOT()</script>');
|
||||
""")
|
||||
f.close()
|
||||
print("SUCCESS: " + target_filename)
|
||||
@@ -437,9 +443,11 @@ if __name__ == "__main__":
|
||||
"Please rename this directory.")
|
||||
elif os.path.isdir(os.path.join(os.path.pardir, "google-closure-library")):
|
||||
# When Closure is installed by npm, it is named "google-closure-library".
|
||||
#calcdeps = import_path(os.path.join(
|
||||
# os.path.pardir, "google-closure-library", "closure", "bin", "calcdeps.py"))
|
||||
print("Error: Closure directory needs to be renamed from"
|
||||
"'google-closure-library' to 'closure-library'.\n"
|
||||
"Please rename this directory.")
|
||||
"'google-closure-library' to 'closure-library'.\n"
|
||||
"Please rename this directory.")
|
||||
else:
|
||||
print("""Error: Closure not found. Read this:
|
||||
https://developers.google.com/blockly/hacking/closure""")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "blockly-src",
|
||||
"name": "blockly",
|
||||
"version": "1.0.0",
|
||||
"description": "Blockly is a library for building visual programming editors.",
|
||||
"keywords": ["blockly"],
|
||||
|
||||
Reference in New Issue
Block a user