diff --git a/build.py b/build.py index 5ac1f353e..ca36691fa 100755 --- a/build.py +++ b/build.py @@ -60,9 +60,10 @@ for arg in sys.argv[1:len(sys.argv)]: if (arg != 'core' and arg != 'accessible' and arg != 'generators' and - arg != 'langfiles'): + arg != 'langfiles' and + arg != 'demo'): raise Exception("Invalid argument: \"" + arg + "\". Usage: build.py <0 or more of accessible," + - " core, generators, langfiles>") + " core, generators, langfiles, demo>") import errno, glob, httplib, json, os, re, subprocess, threading, urllib @@ -214,6 +215,37 @@ class Gen_compressed(threading.Thread): self.gen_generator("dart") self.gen_generator("lua") + if ('demo' in self.bundles): + self.gen_together() + + def gen_together(self): + target_filename = os.path.join("demos", "fixed-advanced", "main_compressed.js") + # Define the parameters for the POST request. + params = [ + # TODO switch to advanced + ("compilation_level", "SIMPLE_OPTIMIZATIONS"), + ("use_closure_library", "true"), + ("output_format", "json"), + ("output_info", "compiled_code"), + ("output_info", "warnings"), + ("output_info", "errors"), + ("output_info", "statistics"), + ] + + # Read in all the source files. + filenames = calcdeps.CalculateDependencies(self.search_paths, + [os.path.join("demos", "fixed-advanced", "main.js")]) + filenames.sort() # Deterministic build. + for filename in filenames: + # Filter out the Closure files (the compiler will add them). + if filename.startswith(os.pardir + os.sep): # '../' + continue + f = open(filename) + params.append(("js_code", "".join(f.readlines()))) + f.close() + + self.do_compile(params, target_filename, filenames, "") + def gen_core(self): target_filename = "blockly_compressed.js" # Define the parameters for the POST request. @@ -544,8 +576,15 @@ developers.google.com/blockly/guides/modify/web/closure""") if ('accessible' in args): Gen_uncompressed(full_search_paths, 'blockly_accessible_uncompressed.js').start() - # Compressed is limited by network and server speed. - Gen_compressed(full_search_paths, args).start() + if ('demo' in args): + all_search_paths = calcdeps.ExpandDirectories( + ["accessible", "core", "blocks", os.path.join("demos", "fixed-advanced"), os.path.join("msg", "js"), os.path.join(os.path.pardir, "closure-library")]) + all_search_paths.sort() # Deterministic build. + Gen_compressed(all_search_paths, args).start() + + else: + # Compressed is limited by network and server speed. + Gen_compressed(full_search_paths, args).start() # This is run locally in a separate thread # defaultlangfiles checks for changes in the msg files, while manually asking diff --git a/demos/fixed-advanced/index.html b/demos/fixed-advanced/index.html new file mode 100644 index 000000000..89175eb5e --- /dev/null +++ b/demos/fixed-advanced/index.html @@ -0,0 +1,39 @@ + + + + + Blockly Demo: Fixed Blockly + + + + +

Blockly > + Demos > Fixed Blockly

+ +

This is a simple demo of injecting Blockly into a fixed-sized 'div' element.

+ +

→ More info on injecting fixed-sized Blockly

+ +
+ + + + + diff --git a/demos/fixed-advanced/main.js b/demos/fixed-advanced/main.js new file mode 100644 index 000000000..dfe00b488 --- /dev/null +++ b/demos/fixed-advanced/main.js @@ -0,0 +1,31 @@ +/** + * @fileoverview Main file (entry point) for the advanced compilation demo. + */ +'use strict'; + +goog.provide('Demo'); + +// core +goog.require('Blockly'); +// blocks +goog.require('Blockly.Constants.Colour'); +goog.require('Blockly.Constants.Lists'); +goog.require('Blockly.Constants.Logic'); +goog.require('Blockly.Constants.Loops'); +goog.require('Blockly.Constants.Math'); +goog.require('Blockly.Blocks.procedures'); +goog.require('Blockly.Constants.Text'); +goog.require('Blockly.Constants.Variables'); +// messages (in some language) +goog.require('Blockly.Msg.en'); + + +Demo.init = function() { + Blockly.inject('blocklyDiv', { + media: '../../media/', + toolbox: document.getElementById('toolbox') + }); +} + +window.addEventListener('load', Demo.init); + diff --git a/demos/fixed-advanced/main_compressed.js b/demos/fixed-advanced/main_compressed.js new file mode 100644 index 000000000..f23c30b3f --- /dev/null +++ b/demos/fixed-advanced/main_compressed.js @@ -0,0 +1,1913 @@ +// Do not edit this file; automatically generated by build.py. +'use strict'; + +var COMPILED=!0,goog=goog||{};goog.global=this;goog.isDef=function(a){return void 0!==a};goog.isString=function(a){return"string"==typeof a};goog.isBoolean=function(a){return"boolean"==typeof a};goog.isNumber=function(a){return"number"==typeof a};goog.exportPath_=function(a,b,c){a=a.split(".");c=c||goog.global;a[0]in c||!c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)!a.length&&goog.isDef(b)?c[d]=b:c=c[d]&&c[d]!==Object.prototype[d]?c[d]:c[d]={}}; +goog.define=function(a,b){var c=b;COMPILED||(goog.global.CLOSURE_UNCOMPILED_DEFINES&&void 0===goog.global.CLOSURE_UNCOMPILED_DEFINES.nodeType&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_UNCOMPILED_DEFINES,a)?c=goog.global.CLOSURE_UNCOMPILED_DEFINES[a]:goog.global.CLOSURE_DEFINES&&void 0===goog.global.CLOSURE_DEFINES.nodeType&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_DEFINES,a)&&(c=goog.global.CLOSURE_DEFINES[a]));goog.exportPath_(a,c)};goog.DEBUG=!1;goog.LOCALE="en"; +goog.TRUSTED_SITE=!0;goog.STRICT_MODE_COMPATIBLE=!1;goog.DISALLOW_TEST_ONLY_CODE=COMPILED&&!goog.DEBUG;goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING=!1;goog.provide=function(a){if(goog.isInModuleLoader_())throw Error("goog.provide can not be used within a goog.module.");if(!COMPILED&&goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');goog.constructNamespace_(a)}; +goog.constructNamespace_=function(a,b){if(!COMPILED){delete goog.implicitNamespaces_[a];for(var c=a;(c=c.substring(0,c.lastIndexOf(".")))&&!goog.getObjectByName(c);)goog.implicitNamespaces_[c]=!0}goog.exportPath_(a,b)};goog.VALID_MODULE_RE_=/^[a-zA-Z_$][a-zA-Z0-9._$]*$/; +goog.module=function(a){if(!goog.isString(a)||!a||-1==a.search(goog.VALID_MODULE_RE_))throw Error("Invalid module identifier");if(!goog.isInModuleLoader_())throw Error("Module "+a+" has been loaded incorrectly. Note, modules cannot be loaded as normal scripts. They require some kind of pre-processing step. You're likely trying to load a module via a script tag or as a part of a concatenated bundle without rewriting the module. For more info see: https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.");if(goog.moduleLoaderState_.moduleName)throw Error("goog.module may only be called once per module."); +goog.moduleLoaderState_.moduleName=a;if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a]}};goog.module.get=function(a){return goog.module.getInternal_(a)};goog.module.getInternal_=function(a){if(!COMPILED){if(a in goog.loadedModules_)return goog.loadedModules_[a];if(!goog.implicitNamespaces_[a])return a=goog.getObjectByName(a),null!=a?a:null}return null};goog.moduleLoaderState_=null; +goog.isInModuleLoader_=function(){return null!=goog.moduleLoaderState_};goog.module.declareLegacyNamespace=function(){if(!COMPILED&&!goog.isInModuleLoader_())throw Error("goog.module.declareLegacyNamespace must be called from within a goog.module");if(!COMPILED&&!goog.moduleLoaderState_.moduleName)throw Error("goog.module must be called prior to goog.module.declareLegacyNamespace.");goog.moduleLoaderState_.declareLegacyNamespace=!0}; +goog.setTestOnly=function(a){if(goog.DISALLOW_TEST_ONLY_CODE)throw a=a||"",Error("Importing test-only code into non-debug environment"+(a?": "+a:"."));};goog.forwardDeclare=function(a){};COMPILED||(goog.isProvided_=function(a){return a in goog.loadedModules_||!goog.implicitNamespaces_[a]&&goog.isDefAndNotNull(goog.getObjectByName(a))},goog.implicitNamespaces_={"goog.module":!0}); +goog.getObjectByName=function(a,b){for(var c=a.split("."),d=b||goog.global,e;e=c.shift();)if(goog.isDefAndNotNull(d[e]))d=d[e];else return null;return d};goog.globalize=function(a,b){var c=b||goog.global,d;for(d in a)c[d]=a[d]}; +goog.addDependency=function(a,b,c,d){if(goog.DEPENDENCIES_ENABLED){var e;a=a.replace(/\\/g,"/");var f=goog.dependencies_;d&&"boolean"!==typeof d||(d=d?{module:"goog"}:{});for(var g=0;e=b[g];g++)f.nameToPath[e]=a,f.loadFlags[a]=d;for(d=0;b=c[d];d++)a in f.requires||(f.requires[a]={}),f.requires[a][b]=!0}};goog.ENABLE_DEBUG_LOADER=!0;goog.logToConsole_=function(a){goog.global.console&&goog.global.console.error(a)}; +goog.require=function(a){if(!COMPILED){goog.ENABLE_DEBUG_LOADER&&goog.IS_OLD_IE_&&goog.maybeProcessDeferredDep_(a);if(goog.isProvided_(a)){if(goog.isInModuleLoader_())return goog.module.getInternal_(a)}else if(goog.ENABLE_DEBUG_LOADER){var b=goog.getPathFromDeps_(a);if(b)goog.writeScripts_(b);else throw a="goog.require could not find: "+a,goog.logToConsole_(a),Error(a);}return null}};goog.basePath="";goog.nullFunction=function(){}; +goog.abstractMethod=function(){throw Error("unimplemented abstract method");};goog.addSingletonGetter=function(a){a.instance_=void 0;a.getInstance=function(){if(a.instance_)return a.instance_;goog.DEBUG&&(goog.instantiatedSingletons_[goog.instantiatedSingletons_.length]=a);return a.instance_=new a}};goog.instantiatedSingletons_=[];goog.LOAD_MODULE_USING_EVAL=!0;goog.SEAL_MODULE_EXPORTS=goog.DEBUG;goog.loadedModules_={};goog.DEPENDENCIES_ENABLED=!COMPILED&&goog.ENABLE_DEBUG_LOADER;goog.TRANSPILE="detect"; +goog.TRANSPILER="transpile.js"; +goog.DEPENDENCIES_ENABLED&&(goog.dependencies_={loadFlags:{},nameToPath:{},requires:{},visited:{},written:{},deferred:{}},goog.inHtmlDocument_=function(){var a=goog.global.document;return null!=a&&"write"in a},goog.findBasePath_=function(){if(goog.isDef(goog.global.CLOSURE_BASE_PATH)&&goog.isString(goog.global.CLOSURE_BASE_PATH))goog.basePath=goog.global.CLOSURE_BASE_PATH;else if(goog.inHtmlDocument_()){var a=goog.global.document;var b=a.currentScript;a=b?[b]:a.getElementsByTagName("SCRIPT");for(b= +a.length-1;0<=b;--b){var c=a[b].src,d=c.lastIndexOf("?"),d=-1==d?c.length:d;if("base.js"==c.substr(d-7,7)){goog.basePath=c.substr(0,d-7);break}}}},goog.importScript_=function(a,b){(goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_)(a,b)&&(goog.dependencies_.written[a]=!0)},goog.IS_OLD_IE_=!(goog.global.atob||!goog.global.document||!goog.global.document.all),goog.oldIeWaiting_=!1,goog.importProcessedScript_=function(a,b,c){goog.importScript_("",'goog.retrieveAndExec_("'+a+'", '+b+", "+c+");")}, +goog.queuedModules_=[],goog.wrapModule_=function(a,b){return goog.LOAD_MODULE_USING_EVAL&&goog.isDef(goog.global.JSON)?"goog.loadModule("+goog.global.JSON.stringify(b+"\n//# sourceURL="+a+"\n")+");":'goog.loadModule(function(exports) {"use strict";'+b+"\n;return exports});\n//# sourceURL="+a+"\n"},goog.loadQueuedModules_=function(){var a=goog.queuedModules_.length;if(0\x3c/script>')},goog.appendScriptSrcNode_=function(a){var b=goog.global.document,c=b.createElement("script"); +c.type="text/javascript";c.src=a;c.defer=!1;c.async=!1;b.head.appendChild(c)},goog.writeScriptTag_=function(a,b){if(goog.inHtmlDocument_()){var c=goog.global.document;if(!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING&&"complete"==c.readyState){if(/\bdeps.js$/.test(a))return!1;throw Error('Cannot write "'+a+'" after document load');}if(void 0===b)if(goog.IS_OLD_IE_){goog.oldIeWaiting_=!0;var d=" onreadystatechange='goog.onScriptLoad_(this, "+ ++goog.lastNonModuleScriptIndex_+")' ";c.write('