mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-19 22:51:47 +00:00
feat: make result for config command type safe
This commit is contained in:
parent
a7da0380a8
commit
a2f5a4ec0e
4 changed files with 30 additions and 7 deletions
|
|
@ -111,5 +111,8 @@
|
||||||
"extends": [
|
"extends": [
|
||||||
"@commitlint/config-conventional"
|
"@commitlint/config-conventional"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"yaml": "^1.10.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
src/index.ts
24
src/index.ts
|
|
@ -1,4 +1,5 @@
|
||||||
import childProcess from 'child_process'
|
import childProcess from 'child_process'
|
||||||
|
import yaml from 'yaml'
|
||||||
export interface IDockerComposeOptions {
|
export interface IDockerComposeOptions {
|
||||||
cwd?: string
|
cwd?: string
|
||||||
config?: string | string[]
|
config?: string | string[]
|
||||||
|
|
@ -18,6 +19,14 @@ export type DockerComposeVersionResult = {
|
||||||
version: string
|
version: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DockerComposeConfigResult = {
|
||||||
|
config: {
|
||||||
|
version: Record<string, string>
|
||||||
|
services: Record<string, string | Record<string, string>>
|
||||||
|
volumes: Record<string, string>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
||||||
follow?: boolean
|
follow?: boolean
|
||||||
}
|
}
|
||||||
|
|
@ -292,10 +301,19 @@ export const pullOne = function (
|
||||||
return execCompose('pull', [service], options)
|
return execCompose('pull', [service], options)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = function (
|
export const config = async function (
|
||||||
options?: IDockerComposeOptions
|
options?: IDockerComposeOptions
|
||||||
): Promise<IDockerComposeResult> {
|
): Promise<TypedDockerComposeResult<DockerComposeConfigResult>> {
|
||||||
return execCompose('config', [], options)
|
try {
|
||||||
|
const result = await execCompose('config', [], options)
|
||||||
|
const config = yaml.parse(result.out)
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: { config }
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const configServices = function (
|
export const configServices = function (
|
||||||
|
|
|
||||||
|
|
@ -514,9 +514,11 @@ test('config show data for docker-compose files', async (): Promise<void> => {
|
||||||
config: 'docker-compose-42.yml'
|
config: 'docker-compose-42.yml'
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(std.err).toBeFalsy()
|
expect(std.data.config.version).toBe('3')
|
||||||
expect(std.out.includes('some-service')).toBeTruthy()
|
expect(std.data.config.services['some-service']['image']).toBe(
|
||||||
expect(std.out.includes('test/volume:/mountedvolume:rw')).toBeTruthy()
|
'nginx:1.19.9-alpine'
|
||||||
|
)
|
||||||
|
expect(std.data.config.volumes['db-data']).toEqual({})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('config show data for docker-compose files (services)', async (): Promise<void> => {
|
test('config show data for docker-compose files (services)', async (): Promise<void> => {
|
||||||
|
|
|
||||||
|
|
@ -8920,7 +8920,7 @@ yallist@^4.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
|
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
|
||||||
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==
|
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==
|
||||||
|
|
||||||
yaml@^1.10.0:
|
yaml@^1.10.0, yaml@^1.10.2:
|
||||||
version "1.10.2"
|
version "1.10.2"
|
||||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
|
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
|
||||||
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==
|
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue