diff --git a/src/services/version.services.ts b/src/services/version.services.ts index d940b6c1..19c9f4ce 100644 --- a/src/services/version.services.ts +++ b/src/services/version.services.ts @@ -6,12 +6,39 @@ import { } from '@junobuild/admin'; import {JUNO_PACKAGE_SATELLITE_ID} from '@junobuild/config'; import {red} from 'kleur'; +import ora from 'ora'; +import type {SatelliteParametersWithId} from '../types/satellite'; import {assertConfigAndLoadSatelliteContext} from '../utils/satellite.utils'; export const getSatelliteVersion = async (): Promise< {result: 'success'; version: string} | {result: 'error'} > => { + // Read parameters first to not display the loading spinner while accessing the config const {satellite} = await assertConfigAndLoadSatelliteContext(); + + const spinner = ora('Loading version...').start(); + + try { + const result = await loadSatelliteVersion({satellite}); + + spinner.stop(); + + if (result.result === 'error') { + console.log(red(result.reason)); + } + + return result; + } catch (err: unknown) { + spinner.stop(); + throw err; + } +}; + +const loadSatelliteVersion = async ({ + satellite +}: { + satellite: SatelliteParametersWithId; +}): Promise<{result: 'success'; version: string} | {result: 'error'; reason: string}> => { const {satelliteId, ...actorParams} = satellite; const pkg = await getJunoPackage({ @@ -34,8 +61,7 @@ export const getSatelliteVersion = async (): Promise< }); if (isNullish(satelliteDependency)) { - console.log(red(`Cannot retrieve the current version of your Satellite 😢.`)); - return {result: 'error'}; + return {result: 'error', reason: 'Cannot retrieve the current version of your Satellite 😢.'}; } const [_, versionSatellite] = satelliteDependency;