Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 53aa9c7

Browse files
authored
add install board command (#518)
* add install board command * add install board command to test * only install board when not installed * fix package name check issue * fix tslint issue * revert settings.json
1 parent d5151ea commit 53aa9c7

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/extension.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Uuid from "uuid/v4";
66
import * as vscode from "vscode";
77

88
import { ArduinoContentProvider } from "./arduino/arduinoContentProvider";
9+
import { IBoard } from "./arduino/package";
910
import ArduinoActivator from "./arduinoActivator";
1011
import ArduinoContext from "./arduinoContext";
1112
import {
@@ -157,13 +158,28 @@ export async function activate(context: vscode.ExtensionContext) {
157158
}
158159
delete status.compile;
159160
}
160-
},
161-
() => {
162-
return { board: ArduinoContext.boardManager.currentBoard.name };
163-
});
161+
}, () => {
162+
return { board: ArduinoContext.boardManager.currentBoard.name };
163+
});
164164

165165
registerArduinoCommand("arduino.addLibPath", (path) => ArduinoContext.arduinoApp.addLibPath(path));
166166
registerArduinoCommand("arduino.openExample", (path) => ArduinoContext.arduinoApp.openExample(path));
167+
registerArduinoCommand("arduino.installBoard", async (packageName, arch, version: string = "") => {
168+
let installed = false;
169+
const installedBoards = ArduinoContext.boardManager.installedBoards;
170+
installedBoards.forEach((board: IBoard, key: string) => {
171+
if (packageName === board.platform.package.name &&
172+
arch === board.platform.architecture &&
173+
(!version || version === board.platform.installedVersion)) {
174+
installed = true;
175+
}
176+
});
177+
178+
if (!installed) {
179+
await ArduinoContext.arduinoApp.installBoard(packageName, arch, version);
180+
}
181+
return;
182+
});
167183

168184
// serial monitor commands
169185
const serialMonitor = SerialMonitor.getInstance();

test/extension.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ suite("Arduino: Extension Tests", () => {
4949
"arduino.closeSerialMonitor",
5050
"arduino.reloadExample",
5151
"arduino.showExampleExplorer",
52+
"arduino.installBoard",
5253
];
5354

5455
const foundArduinoCommands = commands.filter((value) => {

0 commit comments

Comments
 (0)