diff --git a/build.py b/build.py index c1331ca9c..0647a0f69 100755 --- a/build.py +++ b/build.py @@ -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, "") diff --git a/core/blockly.js b/core/blockly.js index 6e3a3ddd8..123ab8c57 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -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