|
1 | | -import {isEmptyString} from '@dfinity/utils'; |
2 | | -import {green} from 'kleur'; |
3 | | -import {version as cliCurrentVersion} from '../../package.json'; |
4 | | -import {githubCliLastRelease, githubJunoDockerLastRelease} from '../rest/github.rest'; |
5 | | -import {findEmulatorVersion} from '../services/emulator/version.services'; |
6 | | -import { |
7 | | - buildVersionFromGitHub, |
8 | | - checkVersion, |
9 | | - type CheckVersionResult |
10 | | -} from '../services/version/version.services'; |
11 | | -import {pmInstallHint} from '../utils/pm.utils'; |
| 1 | +import {printVersion} from '../services/version/version.print.services'; |
12 | 2 |
|
13 | | -export const version = async () => { |
14 | | - const check = await cliVersion(); |
15 | | - |
16 | | - if (check.diff === 'error') { |
17 | | - return; |
18 | | - } |
19 | | - |
20 | | - await emulatorVersion(); |
21 | | -}; |
22 | | - |
23 | | -const cliVersion = async (): Promise<CheckVersionResult> => { |
24 | | - const result = await buildVersionFromGitHub({ |
25 | | - logReleaseOnError: () => 'CLI', |
26 | | - releaseFn: githubCliLastRelease |
27 | | - }); |
28 | | - |
29 | | - if (result.result === 'error') { |
30 | | - return {diff: 'error'}; |
31 | | - } |
32 | | - |
33 | | - const {latestVersion} = result; |
34 | | - |
35 | | - return checkVersion({ |
36 | | - currentVersion: cliCurrentVersion, |
37 | | - latestVersion, |
38 | | - displayHint: 'CLI', |
39 | | - commandLineHint: pmInstallHint() |
40 | | - }); |
41 | | -}; |
42 | | - |
43 | | -const emulatorVersion = async () => { |
44 | | - const emulatorResult = await findEmulatorVersion(); |
45 | | - |
46 | | - if (emulatorResult.status !== 'success') { |
47 | | - return; |
48 | | - } |
49 | | - |
50 | | - const {version: emulatorCurrentVersion} = emulatorResult; |
51 | | - |
52 | | - const result = await buildVersionFromGitHub({ |
53 | | - logReleaseOnError: () => 'Juno Docker', |
54 | | - releaseFn: githubJunoDockerLastRelease |
55 | | - }); |
56 | | - |
57 | | - if (result.result === 'error') { |
58 | | - return; |
59 | | - } |
60 | | - |
61 | | - const {latestVersion} = result; |
62 | | - |
63 | | - // Images prior to v0.6.3 lacked proper metadata in org.opencontainers.image.version. |
64 | | - // Earlier releases contained invalid values such as "0-arm64", while v0.6.2 returned an empty string. |
65 | | - // Note: sanitizing the version read via docker/podman inspect causes these cases to resolve to null. |
66 | | - if (isEmptyString(emulatorCurrentVersion)) { |
67 | | - console.log(`Your Emulator is behind the latest version (${green(`v${latestVersion}`)}).`); |
68 | | - return; |
69 | | - } |
70 | | - |
71 | | - checkVersion({ |
72 | | - currentVersion: emulatorCurrentVersion, |
73 | | - latestVersion, |
74 | | - displayHint: 'Emulator' |
75 | | - }); |
| 3 | +export const logVersion = async () => { |
| 4 | + await printVersion(); |
76 | 5 | }; |
0 commit comments