From 6f105ca16098ba8de11f85ec0d092130b65293e4 Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Sun, 11 Apr 2021 15:47:02 +0200 Subject: [PATCH] feat: make result for `config --services` command type safe --- src/index.ts | 19 ++++++++++++++++--- test/index.test.ts | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 908fb80..c949b73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,6 +27,10 @@ export type DockerComposeConfigResult = { } } +export type DockerComposeConfigServicesResult = { + services: string[] +} + export interface IDockerComposeLogOptions extends IDockerComposeOptions { follow?: boolean } @@ -316,10 +320,19 @@ export const config = async function ( } } -export const configServices = function ( +export const configServices = async function ( options?: IDockerComposeOptions -): Promise { - return execCompose('config', ['--services'], options) +): Promise> { + try { + const result = await execCompose('config', ['--services'], options) + const services = result.out.split('\n') + return { + ...result, + data: { services } + } + } catch (error) { + return Promise.reject(error) + } } export const configVolumes = function ( diff --git a/test/index.test.ts b/test/index.test.ts index aa25ccb..19d145c 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -525,11 +525,12 @@ test('config show data for docker-compose files (services)', async (): Promise => {