Skip to content

Commit

Permalink
Merge pull request #219 from purduesigbots/release/0.7.2
Browse files Browse the repository at this point in the history
🔖 Release 0.7.2
  • Loading branch information
AndrewLuGit authored Apr 12, 2024
2 parents 9743cb0 + bb95a85 commit 326ad12
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 426 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"color": "#D6B872",
"theme": "dark"
},
"version": "0.7.1",
"version": "0.7.2",
"engines": {
"vscode": "^1.82.0"
},
Expand Down Expand Up @@ -161,6 +161,10 @@
"command": "pros.new",
"title": "PROS: Create New PROS Project"
},
{
"command": "pros.infoProject",
"title": "PROS: Project Information"
},
{
"command": "pros.welcome",
"title": "PROS: Welcome"
Expand Down
9 changes: 9 additions & 0 deletions src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type BaseCommandOptions = {
extraOutput?: boolean;
successMessage?: string;
optionalArgs?: (string | undefined)[];
errorCallback?: (error: string) => void;
};
export class BaseCommand {
command: string;
Expand All @@ -47,6 +48,7 @@ export class BaseCommand {
exited: boolean = false;
extraOutput?: string[];
progressWindow: BackgroundProgress;
errorCallback?: (error: string) => void;

constructor(options: BaseCommandOptions) {
// the constructor is what is called whenever a new instance of the class is created
Expand Down Expand Up @@ -89,6 +91,7 @@ export class BaseCommand {
this.requiresProsProject = options.requiresProsProject;
this.extraOutput = options.extraOutput ? [] : undefined;
this.successMessage = options.successMessage;
this.errorCallback = options.errorCallback;

this.progressWindow = new BackgroundProgress(this.message, true, false);
// As far as implementing this onto each command, there are two ways you can do this.
Expand Down Expand Up @@ -180,6 +183,9 @@ export class BaseCommand {
child.stdout.on("data", (data) => {
this.parseOutput(data.toString().split(/\r?\n/), child).catch((e) => {
hasError = true;
if (this.errorCallback) {
this.errorCallback(e);
}
vscode.window.showErrorMessage(e, "View Output").then((response) => {
if (response) {
output.show();
Expand All @@ -190,6 +196,9 @@ export class BaseCommand {
child.stderr.on("data", (data) => {
this.parseOutput(data.toString().split(/\r?\n/), child).catch((e) => {
hasError = true;
if (this.errorCallback) {
this.errorCallback(e);
}
vscode.window.showErrorMessage(e, "View Output").then((response) => {
if (response) {
output.show();
Expand Down
8 changes: 7 additions & 1 deletion src/commands/buildUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import { window } from "vscode";
import { upload } from "./upload";

export const buildUpload = async () => {
var buildFailed = false;
const buildCommandOptions: BaseCommandOptions = {
command: "pros",
args: ["make"],
message: "Building Project",
requiresProsProject: true,
successMessage: "hidden",
errorCallback: () => {
buildFailed = true;
},
};
const buildCommand: BaseCommand = new BaseCommand(buildCommandOptions);
try {
await buildCommand.runCommand();
} catch (err: any) {
await window.showErrorMessage(err.message);
}
await upload();
if (!buildFailed) {
await upload();
}
};
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from "./base-command";
export * from "./set-team-number";
export * from "./set-robot-name";
export * from "./runvision";
export * from "./info-project";
41 changes: 41 additions & 0 deletions src/commands/info-project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as vscode from "vscode";
import { BaseCommand, BaseCommandOptions } from "./base-command";
import { StringDecoder } from "string_decoder";
import { PREFIX } from "./cli-parsing";

export const infoProject = async () => {
const infoProjectCommandOptions: BaseCommandOptions = {
command: "pros",
args: ["c", "info-project", "--machine-output"],
message: undefined,
requiresProsProject: true,
extraOutput: true,
successMessage: "hidden",
};

const infoProjectCommand: BaseCommand = new BaseCommand(
infoProjectCommandOptions
);

try {
await infoProjectCommand.runCommand();
} catch (err: any) {
await vscode.window.showErrorMessage(err.message);
}

var output = "Installed Templates: ";
for (let e of infoProjectCommand.extraOutput!) {
if (e.startsWith(PREFIX)) {
let jdata = JSON.parse(e.substr(PREFIX.length));
if (jdata.type === "finalize") {
const target = jdata.data.project.target;
for (let t of jdata.data.project.templates) {
output += `${t.name}: ${t.version}, `;
}
}
}
}
// Remove trailing comma
output = output.slice(0, -2);
vscode.window.showInformationMessage(output);
};
43 changes: 22 additions & 21 deletions src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@ export type DeviceInfo = {
boot: string;
};

export enum DeviceType {
Motor = 2,
LED = 3,
Rotation = 4,
WorkcellMotor = 5,
Inertial = 6,
Distance = 7,
Radio = 8,
Controller = 9,
Brain = 10,
Vision = 11,
ADI = 12,
Partner = 13,
Battery = 14,
Solenoid = 15,
Optical = 16,
Magnet = 17,
RadioInternal = 22,
SerialDevice = -127,
}
const deviceTypeMap: Record<number, string> = {
2: "11W Motor",
3: "LED",
4: "Rotation Sensor",
5: "5.5W Motor",
6: "IMU",
7: "Distance Sensor",
8: "Radio",
9: "Controller",
10: "Brain",
11: "Vision Sensor",
12: "ADI Expander",
14: "Battery Sensor",
16: "Optical Sensor",
17: "Magnet",
"-128": "Generic Sensor",
"-127": "Generic Serial",
};

export type ProgramInfo = {
slot: number;
Expand Down Expand Up @@ -70,9 +68,12 @@ export class V5DeviceInfo {
element.slot = element.slot + 1;
});
rawJSON.v5.devices.items.forEach((element: any) => {
if (element.port > 21) {
return;
}
this.devices.push({
port: element.port,
type: DeviceType[element.type],
type: deviceTypeMap[element.type],
status: element.status,
version: formatVersion(element.version),
boot: formatVersion(element.boot),
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
stop,
createNewProject,
upgradeProject,
infoProject,
upload,
capture,
medic,
Expand Down Expand Up @@ -227,6 +228,7 @@ export async function activate(context: vscode.ExtensionContext) {

setupCommandBlocker("pros.upgrade", upgradeProject);
setupCommandBlocker("pros.new", createNewProject);
setupCommandBlocker("pros.infoProject", infoProject);

// Beta commands (notice the fourth argument is set to true for these)
setupCommandBlocker("pros.installVision", installVision, context, true);
Expand Down
92 changes: 2 additions & 90 deletions src/one-click/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function extract(
title: extractName,
cancellable: true,
},
async (progress, token) => {
async (_progress, token) => {
var read: fs.ReadStream;
var extract: fs.WriteStream;
token.onCancellationRequested((token) => {
Expand Down Expand Up @@ -213,98 +213,10 @@ export async function extract(
`Extracting ${readPath} to ${writePath}`
);
if (storagePath.includes("pros-toolchain-windows")) {
// create tmp folder
await fs.promises.mkdir(
path.join(globalPath, "install", "pros-toolchain-windows", "tmp")
);
await prosLogger.log("OneClick", `Creating tmp directory`);
// extract contents of gcc-arm-none-eabi-version folder

const files = await fs.promises.readdir(
path.join(globalPath, "install", "pros-toolchain-windows", "usr")
);
await prosLogger.log(
"OneClick",
`Finding gcc-arm-none-eabi-version folder`
);
for await (const dir of files) {
if (dir.includes("gcc-arm-none")) {
// iterate through each folder in gcc-arm-none-eabi-version
const folders = await fs.promises.readdir(
path.join(
globalPath,
"install",
"pros-toolchain-windows",
"usr",
dir
)
);
for await (const folder of folders) {
if (!folder.includes("arm-none")) {
await prosLogger.log(
"OneClick",
`Extracting ${folder} out of gcc-arm-none-eabi-version directory`
);

const subfiles = await fs.promises.readdir(
path.join(
globalPath,
"install",
"pros-toolchain-windows",
"usr",
dir,
folder
)
);

// extract everything back 1 level into their respective folder
for await (const subfile of subfiles) {
// The original file path
var originalPath = path.join(
globalPath,
"install",
"pros-toolchain-windows",
"usr",
dir,
folder,
subfile
);
// Path to move the file to
var newPath = path.join(
globalPath,
"install",
"pros-toolchain-windows",
"usr",
folder,
subfile
);
// Move the file
await fs.promises.rename(originalPath, newPath);
}
} else {
// move arm-none folder contents into a new directory under usr
var originalPath = path.join(
globalPath,
"install",
"pros-toolchain-windows",
"usr",
dir,
folder
);

var newPath = path.join(
globalPath,
"install",
"pros-toolchain-windows",
"usr",
folder
);
await fs.promises.rename(originalPath, newPath);
} // file in subfolder
} // folder in gcc-arm-none-eabiversion
} // if subfolder is gcc-arm-none-eabiversion
} // for usr folder's subdirectories
} // windows toolchain
}
} // not bz2
}
);
Expand Down
Loading

0 comments on commit 326ad12

Please sign in to comment.