|
1 | 1 | import {nonNullish} from '@dfinity/utils'; |
2 | 2 | import {assertAnswerCtrlC, execute, spawn} from '@junobuild/cli-tools'; |
3 | 3 | import {type EmulatorPorts} from '@junobuild/config'; |
4 | | -import {red, yellow} from 'kleur'; |
| 4 | +import {green, red, yellow} from 'kleur'; |
5 | 5 | import {basename, join} from 'node:path'; |
| 6 | +import ora from 'ora'; |
6 | 7 | import prompts from 'prompts'; |
7 | 8 | import {readEmulatorConfig} from '../../configs/emulator.config'; |
8 | 9 | import {junoConfigExist, junoConfigFile} from '../../configs/juno.config'; |
@@ -55,6 +56,14 @@ export const clearContainerAndVolume = async () => { |
55 | 56 | await runWithConfig({fn}); |
56 | 57 | }; |
57 | 58 |
|
| 59 | +export const pullImage = async () => { |
| 60 | + const fn: RunWithConfigFn = async (args) => { |
| 61 | + await pullEmulator(args); |
| 62 | + }; |
| 63 | + |
| 64 | + await runWithConfig({fn}); |
| 65 | +}; |
| 66 | + |
58 | 67 | type RunWithConfigFn = (params: {config: CliEmulatorConfig}) => Promise<void>; |
59 | 68 |
|
60 | 69 | const runWithConfig = async ({fn}: {fn: RunWithConfigFn}) => { |
@@ -299,6 +308,39 @@ const clearEmulator = async ({config: {config, derivedConfig}}: {config: CliEmul |
299 | 308 | }); |
300 | 309 | }; |
301 | 310 |
|
| 311 | +const pullEmulator = async ({config: {derivedConfig}}: {config: CliEmulatorConfig}) => { |
| 312 | + const {runner, image} = derivedConfig; |
| 313 | + |
| 314 | + await confirmAndExit( |
| 315 | + `Are you sure you want to pull the emulator image "${image}"? You will need to ${yellow('clear')} the emulator afterward to apply the update.` |
| 316 | + ); |
| 317 | + |
| 318 | + const spinner = ora('Pulling...').start(); |
| 319 | + |
| 320 | + try { |
| 321 | + await spawn({ |
| 322 | + command: runner, |
| 323 | + args: ['pull', image], |
| 324 | + stdout: (o) => { |
| 325 | + // We print out to display some sort of progression |
| 326 | + console.log(o); |
| 327 | + }, |
| 328 | + silentOut: true |
| 329 | + }); |
| 330 | + |
| 331 | + spinner.stop(); |
| 332 | + |
| 333 | + console.log('\nDone ✅\n'); |
| 334 | + |
| 335 | + console.log( |
| 336 | + `Run ${yellow('juno emulator clear')} to reset the state, then ${green('juno emulator start')} to use the updated image.` |
| 337 | + ); |
| 338 | + } catch (error: unknown) { |
| 339 | + spinner.stop(); |
| 340 | + throw error; |
| 341 | + } |
| 342 | +}; |
| 343 | + |
302 | 344 | const assertContainerRunning = async ({ |
303 | 345 | containerName, |
304 | 346 | runner |
|
0 commit comments