diff --git a/src/services/emulator/_runner.services.ts b/src/services/emulator/_runner.services.ts index 81948f2a..0749ca9b 100644 --- a/src/services/emulator/_runner.services.ts +++ b/src/services/emulator/_runner.services.ts @@ -31,27 +31,24 @@ import {createDeployTargetDir} from './_fs.services'; export const startContainer = async () => { await assertAndInitConfig(); - const parsedResult = await readEmulatorConfig(); - - if (!parsedResult.success) { - return; - } - - const {config} = parsedResult; - - const {valid} = - config.derivedConfig.runner === 'docker' ? await checkDockerVersion() : {valid: true}; + const fn: RunWithConfigFn = async (args) => { + await startEmulator(args); + }; - if (valid === 'error' || !valid) { - return; - } + await runWithConfig({fn}); +}; - await assertContainerRunnerRunning({runner: config.derivedConfig.runner}); +export const stopContainer = async () => { + const fn: RunWithConfigFn = async (args) => { + await stopEmulator(args); + }; - await startEmulator({config}); + await runWithConfig({fn}); }; -export const stopContainer = async () => { +type RunWithConfigFn = (params: {config: CliEmulatorConfig}) => Promise; + +const runWithConfig = async ({fn}: {fn: RunWithConfigFn}) => { const parsedResult = await readEmulatorConfig(); if (!parsedResult.success) { @@ -69,7 +66,7 @@ export const stopContainer = async () => { await assertContainerRunnerRunning({runner: config.derivedConfig.runner}); - await stopEmulator({config}); + await fn({config}); }; const promptEmulatorType = async (): Promise<{emulatorType: Exclude}> => {