Inject Blockly version into binaries (#2750)

* Inject the Blockly version in package.json into compressed Blockly builds.
This commit is contained in:
Sam El-Husseini
2019-08-06 10:55:24 -07:00
committed by GitHub
parent 7d29ac44ae
commit 9e4e909baa
2 changed files with 18 additions and 1 deletions

View File

@@ -56,6 +56,9 @@ else:
from urllib.parse import urlencode
from importlib import reload
# Read package.json and extract the current Blockly version.
blocklyVersion = json.loads(open('package.json', 'r').read())['version']
def import_path(fullpath):
"""Import a file with full path specification.
Allows one to import from any directory, something __import__ does not do.
@@ -221,7 +224,11 @@ class Gen_compressed(threading.Thread):
if filename.startswith(os.pardir + os.sep): # '../'
continue
f = codecs.open(filename, encoding="utf-8")
params.append(("js_code", "".join(f.readlines()).encode("utf-8")))
code = "".join(f.readlines()).encode("utf-8")
# Inject the Blockly version.
if filename == "core/blockly.js":
code = code.replace("Blockly.VERSION = 'uncompiled';", "Blockly.VERSION = '" + blocklyVersion + "';")
params.append(("js_code", code))
f.close()
self.do_compile(params, target_filename, filenames, "")

View File

@@ -65,6 +65,16 @@ goog.require('Blockly.Xml');
var CLOSURE_DEFINES = {'goog.DEBUG': false};
/* eslint-enable no-unused-vars */
/**
* Blockly core version.
* This constant is overriden by the build script (build.py) to the value of the version
* in package.json. This is done during the gen_core build step.
* For local builds, you can pass --define='Blockly.VERSION=X.Y.Z' to the compiler
* to override this constant.
* @define {string}
*/
Blockly.VERSION = 'uncompiled';
/**
* The main workspace most recently used.
* Set by Blockly.WorkspaceSvg.prototype.markFocused