mirror of
https://github.com/ivabus/gui
synced 2025-04-24 22:47:14 +03:00

* #433 install tea binary * #433 check tea cli * #433 install tea on install package --------- Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import fs from "fs";
|
|
import { getGuiPath } from "./tea-dir";
|
|
import * as log from "electron-log";
|
|
import semver from "semver";
|
|
import { cliBinPath, asyncExec } from "./cli";
|
|
|
|
const destinationDirectory = getGuiPath();
|
|
|
|
// TODO: move device_id generation here
|
|
|
|
// Get the binary path from the current app directory
|
|
const binaryUrl = "https://tea.xyz/$(uname)/$(uname -m)";
|
|
|
|
export default async function initializeTeaCli(): Promise<string> {
|
|
let version = "";
|
|
let binCheck = "";
|
|
// Create the destination directory if it doesn't exist
|
|
if (!fs.existsSync(destinationDirectory)) {
|
|
fs.mkdirSync(destinationDirectory, { recursive: true });
|
|
}
|
|
|
|
const curlCommand = `curl -L -o "${cliBinPath}" "${binaryUrl}"`;
|
|
|
|
if (fs.existsSync(cliBinPath)) {
|
|
log.info("binary tea already exists at", cliBinPath);
|
|
binCheck = await asyncExec(`cd ${destinationDirectory} && ./tea --version`);
|
|
} else {
|
|
try {
|
|
await asyncExec(curlCommand);
|
|
log.info("Binary downloaded and saved to", cliBinPath);
|
|
await asyncExec("chmod u+x " + cliBinPath);
|
|
log.info("Binary is now ready for use at", cliBinPath);
|
|
binCheck = await asyncExec(`cd ${destinationDirectory} && ./tea --version`);
|
|
} catch (error) {
|
|
log.error("Error setting-up tea binary:", error);
|
|
}
|
|
}
|
|
version = binCheck.toString().split(" ")[1];
|
|
log.info("binary tea version:", version);
|
|
return semver.valid(version.trim()) ? version : "";
|
|
}
|