Skip to content

Commit

Permalink
feat: make result for config --services command type safe
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZeitler committed Apr 14, 2021
1 parent a2f5a4e commit 6f105ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export type DockerComposeConfigResult = {
}
}

export type DockerComposeConfigServicesResult = {
services: string[]
}

export interface IDockerComposeLogOptions extends IDockerComposeOptions {
follow?: boolean
}
Expand Down Expand Up @@ -316,10 +320,19 @@ export const config = async function (
}
}

export const configServices = function (
export const configServices = async function (
options?: IDockerComposeOptions
): Promise<IDockerComposeResult> {
return execCompose('config', ['--services'], options)
): Promise<TypedDockerComposeResult<DockerComposeConfigServicesResult>> {
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 (
Expand Down
5 changes: 3 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,12 @@ test('config show data for docker-compose files (services)', async (): Promise<v
const std = await compose.configServices({
cwd: path.join(__dirname),
log: logOutput,
config: 'docker-compose-42.yml'
config: 'docker-compose-build.yml'
})

expect(std.data.services.length).toBe(6)
expect(std.data.services[0]).toBe('build_test_1')
expect(std.err).toBeFalsy()
expect(std.out.includes('some-service')).toBeTruthy()
})

test('config show data for docker-compose files (volumes)', async (): Promise<void> => {
Expand Down

0 comments on commit 6f105ca

Please sign in to comment.