Skip to content
Merged
Show file tree
Hide file tree
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
77 changes: 3 additions & 74 deletions src/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,5 @@
import {isEmptyString} from '@dfinity/utils';
import {green} from 'kleur';
import {version as cliCurrentVersion} from '../../package.json';
import {githubCliLastRelease, githubJunoDockerLastRelease} from '../rest/github.rest';
import {findEmulatorVersion} from '../services/emulator/version.services';
import {
buildVersionFromGitHub,
checkVersion,
type CheckVersionResult
} from '../services/version/version.services';
import {pmInstallHint} from '../utils/pm.utils';
import {printVersion} from '../services/version/version.print.services';

export const version = async () => {
const check = await cliVersion();

if (check.diff === 'error') {
return;
}

await emulatorVersion();
};

const cliVersion = async (): Promise<CheckVersionResult> => {
const result = await buildVersionFromGitHub({
logReleaseOnError: () => 'CLI',
releaseFn: githubCliLastRelease
});

if (result.result === 'error') {
return {diff: 'error'};
}

const {latestVersion} = result;

return checkVersion({
currentVersion: cliCurrentVersion,
latestVersion,
displayHint: 'CLI',
commandLineHint: pmInstallHint()
});
};

const emulatorVersion = async () => {
const emulatorResult = await findEmulatorVersion();

if (emulatorResult.status !== 'success') {
return;
}

const {version: emulatorCurrentVersion} = emulatorResult;

const result = await buildVersionFromGitHub({
logReleaseOnError: () => 'Juno Docker',
releaseFn: githubJunoDockerLastRelease
});

if (result.result === 'error') {
return;
}

const {latestVersion} = result;

// Images prior to v0.6.3 lacked proper metadata in org.opencontainers.image.version.
// Earlier releases contained invalid values such as "0-arm64", while v0.6.2 returned an empty string.
// Note: sanitizing the version read via docker/podman inspect causes these cases to resolve to null.
if (isEmptyString(emulatorCurrentVersion)) {
console.log(`Your Emulator is behind the latest version (${green(`v${latestVersion}`)}).`);
return;
}

checkVersion({
currentVersion: emulatorCurrentVersion,
latestVersion,
displayHint: 'Emulator'
});
export const logVersion = async () => {
await printVersion();
};
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {helpSnapshot, snapshot} from './commands/snapshot';
import {startStop} from './commands/start-stop';
import {status} from './commands/status';
import {upgrade} from './commands/upgrade';
import {version as versionCommand} from './commands/version';
import {logVersion} from './commands/version';
import {whoami} from './commands/whoami';
import {help} from './help/help';
import {logHelpLogin} from './help/login.help';
Expand Down Expand Up @@ -55,7 +55,7 @@ export const run = async () => {

// Special use case if dev runs "juno --version"
if (['-v', '--version'].includes(cmd)) {
await versionCommand();
await logVersion();
return;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ export const run = async () => {
await clear();
break;
case 'version':
await versionCommand();
await logVersion();
break;
case 'status':
await status();
Expand Down
72 changes: 72 additions & 0 deletions src/services/version/version.print.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {isEmptyString} from '@dfinity/utils';
import {green} from 'kleur';
import {version as cliCurrentVersion} from '../../../package.json';
import {githubCliLastRelease, githubJunoDockerLastRelease} from '../../rest/github.rest';
import {pmInstallHint} from '../../utils/pm.utils';
import {findEmulatorVersion} from '../emulator/version.services';
import {buildVersionFromGitHub, checkVersion, type CheckVersionResult} from './version.services';

export const printVersion = async () => {
const check = await cliVersion();

if (check.diff === 'error') {
return;
}

await emulatorVersion();
};

const cliVersion = async (): Promise<CheckVersionResult> => {
const result = await buildVersionFromGitHub({
logReleaseOnError: () => 'CLI',
releaseFn: githubCliLastRelease
});

if (result.result === 'error') {
return {diff: 'error'};
}

const {latestVersion} = result;

return checkVersion({
currentVersion: cliCurrentVersion,
latestVersion,
displayHint: 'CLI',
commandLineHint: pmInstallHint()
});
};

const emulatorVersion = async () => {
const emulatorResult = await findEmulatorVersion();

if (emulatorResult.status !== 'success') {
return;
}

const {version: emulatorCurrentVersion} = emulatorResult;

const result = await buildVersionFromGitHub({
logReleaseOnError: () => 'Juno Docker',
releaseFn: githubJunoDockerLastRelease
});

if (result.result === 'error') {
return;
}

const {latestVersion} = result;

// Images prior to v0.6.3 lacked proper metadata in org.opencontainers.image.version.
// Earlier releases contained invalid values such as "0-arm64", while v0.6.2 returned an empty string.
// Note: sanitizing the version read via docker/podman inspect causes these cases to resolve to null.
if (isEmptyString(emulatorCurrentVersion)) {
console.log(`Your Emulator is behind the latest version (${green(`v${latestVersion}`)}).`);
return;
}

checkVersion({
currentVersion: emulatorCurrentVersion,
latestVersion,
displayHint: 'Emulator'
});
};
Loading