From e646331f1dcf7e49d902a6c66182899d89dc83ae Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Tue, 30 Jul 2024 12:09:19 +0100 Subject: [PATCH] wip --- scripts/check-solana-version.mjs | 8 +++++++- scripts/link-solana-version.mjs | 33 +++++++++++++------------------- scripts/utils.mjs | 6 +----- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/scripts/check-solana-version.mjs b/scripts/check-solana-version.mjs index f0844be..28c1d19 100644 --- a/scripts/check-solana-version.mjs +++ b/scripts/check-solana-version.mjs @@ -5,7 +5,13 @@ import { getInstalledSolanaVersion, getSolanaVersion } from './utils.mjs'; const expectedVersion = getSolanaVersion(); const installedVersion = await getInstalledSolanaVersion(); -if (installedVersion !== expectedVersion) { +if (!installedVersion) { + echo( + chalk.red('[ ERROR ]'), + `No Solana installation found. Please install Solana ${expectedVersion} before proceeding.` + ); + process.exit(1); +} else if (installedVersion !== expectedVersion) { echo( chalk.yellow('[ WARNING ]'), `The installed Solana version ${installedVersion} does not match the expected version ${expectedVersion}.` diff --git a/scripts/link-solana-version.mjs b/scripts/link-solana-version.mjs index 29a1956..f92ae45 100644 --- a/scripts/link-solana-version.mjs +++ b/scripts/link-solana-version.mjs @@ -3,25 +3,7 @@ import 'zx/globals'; import { getInstalledSolanaVersion, getSolanaVersion } from './utils.mjs'; const expectedVersion = getSolanaVersion(); - -let installedVersion; -try { - installedVersion = await getInstalledSolanaVersion(); -} catch (error) { - echo( - chalk.red('[ ERROR ]'), - `No Solana installation found. Solana ${expectedVersion} is required for this project.` - ); - await askToInstallSolana(expectedVersion); -} - -if (installedVersion === expectedVersion) { - echo( - chalk.green('[ SUCCESS ]'), - `The expected Solana version ${expectedVersion} is installed.` - ); - process.exit(0); -} +const installedVersion = await getInstalledSolanaVersion(); const installPath = path.join( os.homedir(), @@ -39,7 +21,18 @@ const releasePath = path.join( const activeReleasePath = path.join(installPath, 'active_release'); const hasRelease = await fs.exists(releasePath); -if (hasRelease) { +if (!installedVersion) { + echo( + chalk.red('[ ERROR ]'), + `No Solana installation found. Solana ${expectedVersion} is required for this project.` + ); + await askToInstallSolana(expectedVersion); +} else if (installedVersion === expectedVersion) { + echo( + chalk.green('[ SUCCESS ]'), + `The expected Solana version ${expectedVersion} is installed.` + ); +} else if (hasRelease) { await $`rm -f "${activeReleasePath}"`; await $`ln -s "${releasePath}" "${activeReleasePath}"`; echo( diff --git a/scripts/utils.mjs b/scripts/utils.mjs index 274f217..44ee564 100644 --- a/scripts/utils.mjs +++ b/scripts/utils.mjs @@ -121,10 +121,6 @@ export async function getInstalledSolanaVersion() { const { stdout } = await $`solana --version`.quiet(); return stdout.match(/(\d+\.\d+\.\d+)/)?.[1]; } catch (error) { - echo( - chalk.red('[ ERROR ]'), - `No Solana installation found. Please install Solana ${getSolanaVersion()} before proceeding.` - ); - process.exit(1); + return ''; } }