Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Jul 30, 2024
1 parent cefd958 commit e646331
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
8 changes: 7 additions & 1 deletion scripts/check-solana-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`
Expand Down
33 changes: 13 additions & 20 deletions scripts/link-solana-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(
Expand Down
6 changes: 1 addition & 5 deletions scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
}

0 comments on commit e646331

Please sign in to comment.