Skip to content

Commit

Permalink
Ensure -o outputs as binary (not UTF8), and that pretokenise works
Browse files Browse the repository at this point in the history
Allow forcing of pretokenise via the CLI where we may not know the version
  • Loading branch information
gfwilliams committed Aug 28, 2024
1 parent f58798f commit 8eb606c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion bin/espruino-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ function sendCode(callback) {
}
if (!args.outputHEX) {
// if we're supposed to upload code somewhere ensure we do that properly
if (args.outputJS)
Espruino.Config.SAVE_ON_SEND = -1; // force tools not to mess with the file
for (var storageName in args.storageContents) {
var storageContent = args.storageContents[storageName];
if (storageContent.code) {
Expand Down Expand Up @@ -497,7 +499,7 @@ function sendCode(callback) {
}
if (args.outputJS) {
log("Writing output to "+args.outputJS);
require("fs").writeFileSync(args.outputJS, code);
require("fs").writeFileSync(args.outputJS, code, "binary");
}
if (!args.nosend)
Espruino.Core.CodeWriter.writeToEspruino(code, function() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "espruino",
"version": "0.1.55",
"version": "0.1.56",
"description": "Command Line Interface and library for Communications with Espruino JavaScript Microcontrollers",
"main": "index.js",
"files": [
Expand Down
14 changes: 10 additions & 4 deletions plugins/pretokenise.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
function init() {
Espruino.Core.Config.add("PRETOKENISE", {
section : "Minification",
name : "Pretokenise code before upload (BETA)",
name : "Pretokenise code before upload",
description : "All whitespace and comments are removed and all reserved words are converted to tokens before upload. This means a faster upload, less memory used, and increased performance (+10%) at the expense of code readability.",
type : "boolean",
defaultValue : false
type : {
0: "Never",
1: "Auto (tokenise Strings on 2v20.48 or later)",
2: "Yes (always tokenise everything, regardless of version)"
},
defaultValue : 0
});

// When code is sent to Espruino, search it for modules and add extra code required to load them
Expand Down Expand Up @@ -120,7 +124,9 @@
function pretokenise(code, callback) {
var pretokeniseStrings = false; // only works on 2v20.48 and later
var boardData = Espruino.Core.Env.getBoardData();
if (boardData && boardData.VERSION) {
if (Espruino.Config.PRETOKENISE==2) {
pretokeniseStrings = true; // always
} else if (boardData && boardData.VERSION) {
var v = parseFloat(boardData.VERSION.replace("v","0"));
if (v >= 2020.48)
pretokeniseStrings = true;
Expand Down

0 comments on commit 8eb606c

Please sign in to comment.