Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/services/version.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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;
Expand Down