Skip to content

Working with the ArduBlockly Library

chensation edited this page Jan 13, 2022 · 3 revisions

Introduction

This repo is a fork of the ArduBlockly library, which stopped development in 2018. We use this repo to make bug fixes and add new blocks to our CaSMM project. In truth, we only need to work with files inside the blockly directory. We can build the compressed js file seen inside that directory and include them into CaSMM to be used.

Cloning the Repo

Use git submodule update --recursive --init to initialize and clone the submodules (closure-library) used.

Building the Compressed Files

To build the files, run build.py. Keep in mind that the script only supports python 2.

We only need to build blockly_compressed.js, blocks_compressed.js, and arduino_compressed.js. The others are commented out by default, if for some reason they need to be built, feel free to uncomment those lines in build.py.

Google's Closure Compiler

build.py makes request to Google's cloud closure compiler service. That means you'll need internet access when running the script. As a cloud service, the closure compiler has a service quota that may be exceeded, if that occurs, we'll need to wait until the next day to make use of its service. In addition, making too many requests in a short amount of time will also temporary ban you from the service for a couple of hours. Keep these points in mind while running the script.

Adding Blocks and Making Changes

Refer back to the original ArduBlockly's wiki for info.

CASMM Specific Codes

Some changes made to the library are specific for integration with CASMM and does not apply to the general use case of ardublockly. These codes can be found by searching for //@CASMM comments.

Future-Proofing Concerns

The main concern is the use of Google's cloud closure compiler.

The version of the Blockly library that ArduBlockly relies on is from 2016, it is severally out of date. Blockly itself relies on Google's Closure Library. It makes use of this library through goog.require(...). These lines are the reason why we have to use the cloud closure compiler service.

Google's Closure Compiler is a program that minifies js code. As such, it can be downloaded, build, and run offline. However, the cloud closure compiler provided the additional feature of pulling all the goog.require(...) lines that makes reference to the Closure Library, and adding their definition to the minified js file. This feature is being utilized in our build script. When the cloud compiler adds the definition for the Closure Library, it pulls from the latest version of the Closure Library. Our Blockly is several years out of date, as a result, it makes references to several now depreciated closure library functions.

Currently, I've added the depreciated functions back, and stored them into depreciated.js in CaSMM. However, we do not know what Google will depreciate next. For future support, we either need to update Blockly to be always in time with the newest Google updates, or switch to an offline solution for the build process.

Another concern is the use of Python 2 inside build.py. This version of Python has official dropped support since 2020, we may need to consider updating the script to support Python 3.