mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-09 17:53:16 +00:00
feat: make result for version command type safe
This commit is contained in:
parent
90421b7eb2
commit
a7da0380a8
2 changed files with 18 additions and 5 deletions
19
src/index.ts
19
src/index.ts
|
|
@ -14,6 +14,10 @@ export type DockerComposePortResult = {
|
||||||
port: number
|
port: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DockerComposeVersionResult = {
|
||||||
|
version: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
||||||
follow?: boolean
|
follow?: boolean
|
||||||
}
|
}
|
||||||
|
|
@ -377,8 +381,17 @@ export const port = async function (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const version = function (
|
export const version = async function (
|
||||||
options?: IDockerComposeOptions
|
options?: IDockerComposeOptions
|
||||||
): Promise<IDockerComposeResult> {
|
): Promise<TypedDockerComposeResult<DockerComposeVersionResult>> {
|
||||||
return execCompose('version', ['--short'], options)
|
try {
|
||||||
|
const result = await execCompose('version', ['--short'], options)
|
||||||
|
const version = result.out.replace('\n', '')
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: { version }
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -641,7 +641,7 @@ test('removes container', async (): Promise<void> => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('returns version information', async (): Promise<void> => {
|
test('returns version information', async (): Promise<void> => {
|
||||||
const version = await compose.version()
|
const version = await (await compose.version()).data.version
|
||||||
|
|
||||||
expect(version.out).toBeTruthy()
|
expect(version).toMatch(/^(\d+\.)?(\d+\.)?(\*|\d+)$/)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue