Skip to content

Commit 5346e4f

Browse files
authored
Fixed file extension calculation for ESP32 boards. (#554)
This commit fixes a bug introduced with 2.9.1 (which will be deprecated). Now the file extension of the sketch is retrieved using a regular expression, not by position.
1 parent 1cb467d commit 5346e4f

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ lib
33
dist
44
es
55
.tmp
6+
misc

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [2.9.1] - 2022-09-06
4+
## [2.10.0] - 2022-09-08
5+
6+
### Changed
7+
- Fixed a bug released in 2.9.1 caused by the wrong assumption that the build filename is always at the end of the command line. This fix makes the library backward compatible with older ESP boards.
8+
9+
## *DEPRECATED* [2.9.1] - 2022-09-06
510
### Added
611
- Added support for ESP32 boards
712

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
JS module providing discovery of the [Arduino Create Agent](https://github.com/arduino/arduino-create-agent) and communication with it
66

77
## Changelog
8-
See [CHANGELOG.MD](CHANGELOG.MD) for more details.
8+
See [CHANGELOG.md](https://github.com/arduino/arduino-create-agent-js-client/blob/HEAD/CHANGELOG.md) for more details.
99

1010
## Installation
1111

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arduino-create-agent-js-client",
3-
"version": "2.9.1",
3+
"version": "2.10.0",
44
"description": "JS module providing discovery of the Arduino Create Plugin and communication with it",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/daemon.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ export default class Daemon {
130130
})
131131
.then(result => result.json())
132132
.then(uploadCommandInfo => {
133-
const projectNameIndex = uploadCommandInfo.commandline.lastIndexOf('{build.project_name}');
134-
let ext = uploadCommandInfo.commandline.substring(projectNameIndex + 21, projectNameIndex + 24);
133+
let ext = this._extractExtensionFromCommandline(uploadCommandInfo.commandline);
135134
const data = compilationResult[ext] || compilationResult.bin;
136135
if (!ext || !data) {
137136
console.log('we received a faulty ext property, defaulting to .bin');
@@ -211,4 +210,13 @@ export default class Daemon {
211210
});
212211
this.openSerialMonitor(port, 1200);
213212
}
213+
214+
static _extractExtensionFromCommandline(commandline) {
215+
const rx = /\{build\.project_name\}\.(\w\w\w)\b/g;
216+
const arr = rx.exec(commandline);
217+
if (arr && arr.length) {
218+
return arr[1];
219+
}
220+
return null;
221+
}
214222
}

0 commit comments

Comments
 (0)