Skip to content

Commit

Permalink
run prettier :)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLuGit committed Oct 14, 2024
1 parent 53a0286 commit c7d9322
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 43 deletions.
32 changes: 18 additions & 14 deletions src/one-click/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ async function download(
await prosLogger.log("OneClick", `Storage Path: ${storagePath}`);

downloadName =
"Downloading: " + (downloadName ??
(storagePath.includes("cli")
? "PROS CLI"
: storagePath.includes("toolchain")
? "PROS Toolchain"
: "VEX Vexcom"));
"Downloading: " +
(downloadName ??
(storagePath.includes("cli")
? "PROS CLI"
: storagePath.includes("toolchain")
? "PROS Toolchain"
: "VEX Vexcom"));

await window.withProgress(
{
Expand Down Expand Up @@ -84,12 +85,13 @@ export async function extract(
) {
await prosLogger.log("OneClick", `Extracting ${storagePath}`);
extractName =
"Installing: " + (extractName ??
(storagePath.includes("cli")
? "PROS CLI"
: storagePath.includes("toolchain")
? "PROS Toolchain"
: "VEX Vexcom"));
"Installing: " +
(extractName ??
(storagePath.includes("cli")
? "PROS CLI"
: storagePath.includes("toolchain")
? "PROS Toolchain"
: "VEX Vexcom"));
await window.withProgress(
{
location: ProgressLocation.Notification,
Expand All @@ -110,14 +112,16 @@ export async function extract(
await new Promise(function (resolve, reject) {
// Create our read stream
prosLogger.log("OneClick", `Creating read stream for ${storagePath}`);
const stats = fs.statSync(path.join(globalPath, "download", storagePath));
const stats = fs.statSync(
path.join(globalPath, "download", storagePath)
);
const totalSize = stats.size;
read = fs.createReadStream(
path.join(globalPath, "download", storagePath)
);
var decompress = new lzma.createDecompressor();
decompress.on("data", (chunk: Buffer | string | any) => {
_progress.report({ increment: (chunk.length * 100) / totalSize});
_progress.report({ increment: (chunk.length * 100) / totalSize });
});
// Remove tar from the filename
storagePath = storagePath.replace(".tar.xz", "");
Expand Down
60 changes: 43 additions & 17 deletions src/one-click/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import * as vscode from "vscode";
import * as path from "path";
import * as os from "os";
import { downloadextract, chmod } from "./download";
import { getCurrentVersion, getCurrentReleaseVersion, getToolchainVersion } from "./installed";
import {
getCurrentVersion,
getCurrentReleaseVersion,
getToolchainVersion,
} from "./installed";
import * as fs from "fs";
import { promisify } from "util";
import * as child_process from "child_process";
Expand Down Expand Up @@ -141,7 +145,7 @@ async function getUrls(
await prosLogger.log("OneClick", `MacOS detected, using MacOS URLS`);
// Set system, path seperator, and downloads to windows version
cliArch = "macos-64bit";
toolchainArch = (os.arch() === "x64") ? "darwin-x86_64" : "darwin-arm64";
toolchainArch = os.arch() === "x64" ? "darwin-x86_64" : "darwin-arm64";
vexcomArch = "osx";
} else {
await prosLogger.log("OneClick", `Linux detected, using Linux URLS`);
Expand All @@ -151,7 +155,7 @@ async function getUrls(
if (operatingSystem === "windows") {
var downloadToolchain = `https://github.com/purduesigbots/toolchain/releases/download/${toolchainVersion}/pros-toolchain-windows-formatted.zip`;
} else {
let toolchainSemver = semver.parse(toolchainVersion, {loose: true});
let toolchainSemver = semver.parse(toolchainVersion, { loose: true });
toolchainVersion = `${toolchainSemver?.major}.${toolchainSemver?.minor}.rel${toolchainSemver?.patch}`;
var downloadToolchain = `https://developer.arm.com/-/media/Files/downloads/gnu/${toolchainVersion}/binrel/arm-gnu-toolchain-${toolchainVersion}-${toolchainArch}-arm-none-eabi.tar.xz`;
}
Expand Down Expand Up @@ -281,13 +285,14 @@ export async function install(context: vscode.ExtensionContext) {
"pros"
)
);
let [currentToolchainVersion, isToolchainOneClickInstall] = await getToolchainVersion(
path.join(
`${addQuotes ? `"` : ""}${toolchainExecPath}${addQuotes ? `"` : ""}`,
"bin",
"arm-none-eabi-g++"
)
);
let [currentToolchainVersion, isToolchainOneClickInstall] =
await getToolchainVersion(
path.join(
`${addQuotes ? `"` : ""}${toolchainExecPath}${addQuotes ? `"` : ""}`,
"bin",
"arm-none-eabi-g++"
)
);
const cliWorking = currentCliVersion !== "0.0.0";
const toolchainWorking = currentToolchainVersion !== "0.0.0";
const vexcomWorking = await verifyVexcom();
Expand Down Expand Up @@ -326,8 +331,12 @@ export async function install(context: vscode.ExtensionContext) {
console.log("Vexcom Working: " + vexcomWorking);

// Does the user's CLI have an update or does the user need to install/update
const cliUpToDate = cliWorking ? semver.gte(currentCliVersion, cliVersion) : false;
const toolchainUpToDate = toolchainWorking ? semver.gte(currentToolchainVersion, toolchainVersion, {loose: true}) : false;
const cliUpToDate = cliWorking
? semver.gte(currentCliVersion, cliVersion)
: false;
const toolchainUpToDate = toolchainWorking
? semver.gte(currentToolchainVersion, toolchainVersion, { loose: true })
: false;
await prosLogger.log(
"OneClick",
`${cliUpToDate ? "CLI is up to date" : "CLI is not up to date"}`,
Expand All @@ -344,7 +353,11 @@ export async function install(context: vscode.ExtensionContext) {
);
await prosLogger.log(
"OneClick",
`${toolchainUpToDate ? "Toolchain is up to date" : "To0lchain is not up to date"}`,
`${
toolchainUpToDate
? "Toolchain is up to date"
: "To0lchain is not up to date"
}`,
toolchainUpToDate ? "INFO" : "WARNING"
);
await prosLogger.log(
Expand Down Expand Up @@ -375,7 +388,13 @@ export async function install(context: vscode.ExtensionContext) {
await preparingInstall.stop();

//if everything works and cli is up to date, do nothing
if (cliWorking && toolchainWorking && cliUpToDate && toolchainUpToDate && vexcomWorking) {
if (
cliWorking &&
toolchainWorking &&
cliUpToDate &&
toolchainUpToDate &&
vexcomWorking
) {
return;
}

Expand Down Expand Up @@ -475,7 +494,13 @@ async function promptInstall(
toolchainUpToDate: boolean,
vexcomWorking: boolean
) {
if (cliWorking && cliUpToDate && toolchainWorking && toolchainUpToDate && vexcomWorking) {
if (
cliWorking &&
cliUpToDate &&
toolchainWorking &&
toolchainUpToDate &&
vexcomWorking
) {
vscode.window.showInformationMessage(
"Everything is currently working and up to date."
);
Expand Down Expand Up @@ -627,8 +652,9 @@ export async function configurePaths(
"pros"
)
);
process.env["PROS_VSCODE_FLAGS"] =
semver.gte(version, "3.2.4") ? "--no-sentry --no-analytics" : "";
process.env["PROS_VSCODE_FLAGS"] = semver.gte(version, "3.2.4")
? "--no-sentry --no-analytics"
: "";
await prosLogger.log(
"OneClick",
`CLI is installed through ${
Expand Down
27 changes: 15 additions & 12 deletions src/one-click/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export async function getCurrentVersion(
},
}
);
const version = stdout
.replace("pros, version ", "");
const version = stdout.replace("pros, version ", "");
return [version, true];
} catch {
try {
Expand All @@ -53,8 +52,7 @@ export async function getCurrentVersion(
PATH: getChildProcessPath(),
},
});
const version = stdout
.replace("pros, version ", "");
const version = stdout.replace("pros, version ", "");
return [version, false];
} catch (err) {
console.log(`Error fetching PROS CLI version: ${err}`);
Expand All @@ -68,7 +66,9 @@ export async function getCurrentVersion(
}
}

export async function getToolchainVersion(oneClickPath: string): Promise<[string, boolean]> {
export async function getToolchainVersion(
oneClickPath: string
): Promise<[string, boolean]> {
try {
console.log(oneClickPath);
prosLogger.log(
Expand All @@ -88,13 +88,16 @@ export async function getToolchainVersion(oneClickPath: string): Promise<[string
return [stdout, true];
} catch {
try {
const { stdout } = await promisify(child_process.exec)(`arm-none-eabi-g++ --version`, {
env: {
...process.env,
// eslint-disable-next-line @typescript-eslint/naming-convention
PATH: getChildProcessPath(),
},
});
const { stdout } = await promisify(child_process.exec)(
`arm-none-eabi-g++ --version`,
{
env: {
...process.env,
// eslint-disable-next-line @typescript-eslint/naming-convention
PATH: getChildProcessPath(),
},
}
);
return [stdout, false];
} catch (err) {
console.log(`Error fetching PROS toolchain version: ${err}`);
Expand Down

0 comments on commit c7d9322

Please sign in to comment.