mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-06 16:21:49 +00:00
feat: make result for config --services command type safe
This commit is contained in:
parent
a2f5a4ec0e
commit
6f105ca160
2 changed files with 19 additions and 5 deletions
19
src/index.ts
19
src/index.ts
|
|
@ -27,6 +27,10 @@ export type DockerComposeConfigResult = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DockerComposeConfigServicesResult = {
|
||||||
|
services: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
||||||
follow?: boolean
|
follow?: boolean
|
||||||
}
|
}
|
||||||
|
|
@ -316,10 +320,19 @@ export const config = async function (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const configServices = function (
|
export const configServices = async function (
|
||||||
options?: IDockerComposeOptions
|
options?: IDockerComposeOptions
|
||||||
): Promise<IDockerComposeResult> {
|
): Promise<TypedDockerComposeResult<DockerComposeConfigServicesResult>> {
|
||||||
return execCompose('config', ['--services'], options)
|
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 (
|
export const configVolumes = function (
|
||||||
|
|
|
||||||
|
|
@ -525,11 +525,12 @@ test('config show data for docker-compose files (services)', async (): Promise<v
|
||||||
const std = await compose.configServices({
|
const std = await compose.configServices({
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
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.err).toBeFalsy()
|
||||||
expect(std.out.includes('some-service')).toBeTruthy()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('config show data for docker-compose files (volumes)', async (): Promise<void> => {
|
test('config show data for docker-compose files (volumes)', async (): Promise<void> => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue