30 lines
1.1 KiB
TypeScript
Vendored
30 lines
1.1 KiB
TypeScript
Vendored
import shelljs from 'shelljs';
|
|
|
|
import { getSpinner } from "@/utils/info";
|
|
import { IS_WIN } from '@/utils/platform';
|
|
import { shellExec } from '@/utils/shell';
|
|
import { isChinaDomain } from '@/utils/ip';
|
|
|
|
export async function installRust() {
|
|
const isInChina = await isChinaDomain("sh.rustup.rs");
|
|
const rustInstallScriptForMac = isInChina
|
|
? 'export RUSTUP_DIST_SERVER="https://rsproxy.cn" && export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" && curl --proto "=https" --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh'
|
|
: "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
|
|
const rustInstallScriptForWindows = 'winget install --id Rustlang.Rustup';
|
|
|
|
const spinner = getSpinner('Downloading Rust.');
|
|
|
|
try {
|
|
await shellExec(IS_WIN ? rustInstallScriptForWindows : rustInstallScriptForMac);
|
|
spinner.succeed('Rust installed successfully.');
|
|
} catch (error) {
|
|
console.error('Error installing Rust:', error.message);
|
|
spinner.fail('Rust installation failed.');
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
export function checkRustInstalled() {
|
|
return shelljs.exec('rustc --version', { silent: true }).code === 0;
|
|
}
|