Espruino, CLI, IDE, and Babel

Posted on
  • There are a couple other posts that have talked about NPM and Webpack, some that mention Babel, but I thought I would start a new post. I'm relative noob to espruino stuff, but an experienced web developer, so I thought I would share my thoughts about the toolchain.

    A little about Babel for those who don't know it:

    • Its primary usage is a polyfill for ES standards that don't exist in whatever environment you're running your code on. For instance, some browsers don't understand Object.assign(..., but Babel can make that syntax available to many environments (mostly browsers of various vintages)
    • Has a rich ecosystem of presets and plugins that do various transforms on javascript code before it gets run or sent to production.
    • Very well supported, an absolutely insensible tool for almost every modern web company, including Facebook, AirBnB, Reddit, and where I work, Redfin.
    • Babel has a CLI that is fast and runs on node and in the browser, this opens many possibilities for the Espruino ecosystem.

    Overall thoughts:

    • Im a big baby and want to be able to work in the tools I'm familiar with. I'm sure I'll offend someone by saying this, but the Espruino IDE is a bit lacking, compared to what tools are available to web developers such as Atom or Sublime.
    • When I started on Espruino, I had expected that I would just be able to create a new file on my local disk, use my editor of choice to write code, and have a bulletproof CLI to send it to the device and get logging back. For instance React Native (a project that runs Javascript on iOS and Android) has very simple tools to build and watch local files and move them to the device. I want this for espruino.
    • A babel-preset-espruino would be extremely useful and amazing. Moving from my day job where I write JS thats run through babel, then coming home and playing with espruino, I feel like I walked into a time machine that took me back a few years. No module syntax, no async/await, persistent fear of using a language feature that is going to blow up on my target environment. Its not optimal.

    Actual question:

    After reading through the docs I'm actually a bit suprised that I didn't find a simple single command to just deploy and run a static JS file on a board plugged in via usb and get a non interactive log back.
    Hello world:
    $ npm install espruino -g
    $ touch index.js
    edit file, write a simple blink app
    plug in board via usb
    $ espruino run index.js (with options to specify a port if you need to to that)
    then the terminal shows the std out from the app as it runs

    I also expected a good watch mode for local files, which would look like such
    $ espruino watch index.js
    cli starts the app, and runs it
    then you make changes, hit save in your editor and the terminal window shows:
    changes found, restarting
    then the terminal shows the std out from the app as it runs

    Did I miss some docs somewhere or is a CLI like this not available?

  • In deed... listening to you is about re-listening to myself... With a similar background and with the options of shimming/polyfilling/frameworking specific platforms to a common platform, things just work portably perfect. 'Unfortunately' with the resource constraints and a non-ES(X) JavaScript interpreter/vm, things aren't as forthcoming. I recall my first request to have a module to be able to deliver 'class'/constructor and at the same time mentioning browser-side require.js/AMD - because that was the 'thing' I was used to. In the meantime I know that require() looks the same, delivers (almost) the same but works a bit different...

    Espruino JavaScript puts as a bit back into the time where it really really mattered in what Browser Web pages with JavaScript had to run in... to not have a run in... ;-). I feel it is amazing how far Espruino came from when I experienced it the first time - and that was already way beyond version 1v00. Just to mention a small detail: Promises. I started out with just callbacks.

    Just recently I contemplated to extend require(). With different styles of Web communications and Promises available, AMD is done... and Espruino becomes an IoT/Hardware/Controlling-'Browser' in an M2M environment vs. the original - known for quite some time now - UI/Rendering-Browser in a U2M/C2M environment.

    Espruino's frugalness in just everything - power, (eep)rom and ram, and even size (w/ Espruino Pico and now Puck) - except performance and ease-of-use made me reconcile with being put a bit back in time. If mentioned resourcefulness does not matter, no need for Espruino, any other environment of dog bones and xyz berries and ... what ever single board computer you find on the market - in numbers like ants in a hill - would do (btw: rasp means obsolete... because raspberries had to be consumed right away after picking because they mush and rot/ferment quickly... may be that's why the French originally made wine out of them).

    Have no answers to your questions(*), because "Was der Bauer nicht kennt, (fr)isst er nicht!" - What the farmer does not know he does not eat!... but I'm willing to learn and become an educated, gourmet farmer... ;)

    (*) except for the last one: may be because reality - hardware with sensors to the real world - is involved, which is not that easy to (unit/integration-test-)emulate as what we call real databases (and other emulatable) system, even though I did that serveral time already when (cross) developing (in the Browser only) logic that uses sensor and display and motion sub-systems. The Sensors, Displays and Motions were DOM nodes. Another reason is: doing IoT on MC level, the targeted environment is pretty given and not much changing. The software is dedicated and not intended general and universal, because latter virtues are just not affordable by the available memory resources. Extensibility has to be 'thought in' in a different way.

  • Did I miss some docs somewhere or is a CLI like this not available?

    You definitely missed something :) In fact literally just typing the command that you posted npm install espruino -g will give you a CLI: https://www.npmjs.com/package/espruino

    There's also the ability to watch files so it'll integrate with your editor - just not with the exact syntax you posted :)

    In terms of using it with Babel, I'd assume that there is already a framework for running Babel or other CLI tools when the source files change? If so, you could just add the Espruino CLI tool to the end of the list of tools to run - or could watch the output file of babel for upload with the CLI.

    But yes, there's also thingsSDK for ESP8266, which wraps the transformations up as well.

  • I'm a bit late to the party, but I'm new to Espruino and I too, did miss some of the modern features of JS.

    I spend some time handpicking Babel plugins and did some sanity testing to see if the resulting code worked as expected in Espruino.

    I found some bugs (which I've raised as issues in GitHub), but I'm so far, pretty happy with the result.
    I have published a sample project which could be used as a starting point. It can be found here:
    https://github.com/andrewwakeling/esprui­no-webpack-babel-sample

    I would love to hear any feedback here or via GitHub. Thanks!

  • Thanks! I'm on holiday this week, but hopefully I'll get some of those issues sorted next week.

  • Awesome! Enjoy your holiday! No rush on the fixes.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino, CLI, IDE, and Babel

Posted by Avatar for KevinJ @KevinJ

Actions