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
4 changes: 4 additions & 0 deletions src/commands/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {logHelpEmulator} from '../help/emulator.help';
import {logHelpEmulatorStart} from '../help/emulator.start.help';
import {logHelpEmulatorWait} from '../help/emulator.wait.help';
import {clear} from '../services/emulator/clear.services';
import {pull} from '../services/emulator/pull.services';
import {start} from '../services/emulator/start.services';
import {stop} from '../services/emulator/stop.services';
import {wait} from '../services/emulator/wait.services';
Expand All @@ -23,6 +24,9 @@ export const emulator = async (args?: string[]) => {
case 'clear':
await clear();
break;
case 'pull':
await pull();
break;
default:
console.log(red('Unknown subcommand.'));
logHelpEmulator(args);
Expand Down
1 change: 1 addition & 0 deletions src/constants/help.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const HOSTING_PRUNE_DESCRIPTION =
export const EMULATOR_START_DESCRIPTION = 'Start the emulator for local development.';
export const EMULATOR_WAIT_DESCRIPTION = 'Wait until the emulator is ready.';
export const EMULATOR_CLEAR_DESCRIPTION = 'Clear the local emulator state (volume and container).';
export const EMULATOR_PULL_DESCRIPTION = 'Pull the latest emulator image.';

export const FUNCTIONS_PUBLISH_DESCRIPTION = 'Publish a new version of your serverless functions.';
export const FUNCTIONS_UPGRADE_DESCRIPTION = 'Upgrade your serverless functions.';
Expand Down
2 changes: 2 additions & 0 deletions src/help/emulator.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {cyan, green, magenta, yellow} from 'kleur';
import {
EMULATOR_CLEAR_DESCRIPTION,
EMULATOR_DESCRIPTION,
EMULATOR_PULL_DESCRIPTION,
EMULATOR_START_DESCRIPTION,
EMULATOR_WAIT_DESCRIPTION
} from '../constants/help.constants';
Expand All @@ -12,6 +13,7 @@ const usage = `Usage: ${green('juno')} ${cyan('emulator')} ${magenta('<subcomman

Subcommands:
${magenta('clear')} ${EMULATOR_CLEAR_DESCRIPTION}
${magenta('pull')} ${EMULATOR_PULL_DESCRIPTION}
${magenta('start')} ${EMULATOR_START_DESCRIPTION}
${magenta('stop')} Stop the local network.
${magenta('wait')} ${EMULATOR_WAIT_DESCRIPTION}`;
Expand Down
44 changes: 43 additions & 1 deletion src/services/emulator/_runner.services.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {nonNullish} from '@dfinity/utils';
import {assertAnswerCtrlC, execute, spawn} from '@junobuild/cli-tools';
import {type EmulatorPorts} from '@junobuild/config';
import {red, yellow} from 'kleur';
import {green, red, yellow} from 'kleur';
import {basename, join} from 'node:path';
import ora from 'ora';
import prompts from 'prompts';
import {readEmulatorConfig} from '../../configs/emulator.config';
import {junoConfigExist, junoConfigFile} from '../../configs/juno.config';
Expand Down Expand Up @@ -55,6 +56,14 @@ export const clearContainerAndVolume = async () => {
await runWithConfig({fn});
};

export const pullImage = async () => {
const fn: RunWithConfigFn = async (args) => {
await pullEmulator(args);
};

await runWithConfig({fn});
};

type RunWithConfigFn = (params: {config: CliEmulatorConfig}) => Promise<void>;

const runWithConfig = async ({fn}: {fn: RunWithConfigFn}) => {
Expand Down Expand Up @@ -299,6 +308,39 @@ const clearEmulator = async ({config: {config, derivedConfig}}: {config: CliEmul
});
};

const pullEmulator = async ({config: {derivedConfig}}: {config: CliEmulatorConfig}) => {
const {runner, image} = derivedConfig;

await confirmAndExit(
`Are you sure you want to pull the emulator image "${image}"? You will need to ${yellow('clear')} the emulator afterward to apply the update.`
);

const spinner = ora('Pulling...').start();

try {
await spawn({
command: runner,
args: ['pull', image],
stdout: (o) => {
// We print out to display some sort of progression
console.log(o);
},
silentOut: true
});

spinner.stop();

console.log('\nDone ✅\n');

console.log(
`Run ${yellow('juno emulator clear')} to reset the state, then ${green('juno emulator start')} to use the updated image.`
);
} catch (error: unknown) {
spinner.stop();
throw error;
}
};

const assertContainerRunning = async ({
containerName,
runner
Expand Down
5 changes: 5 additions & 0 deletions src/services/emulator/pull.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {pullImage} from './_runner.services';

export const pull = async () => {
await pullImage();
};
Loading