mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-22 22:09:12 +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 {
|
||||
follow?: boolean
|
||||
}
|
||||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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> => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue