diff --git a/package.json b/package.json index 4068d66..9113775 100644 --- a/package.json +++ b/package.json @@ -111,5 +111,8 @@ "extends": [ "@commitlint/config-conventional" ] + }, + "dependencies": { + "yaml": "^1.10.2" } } diff --git a/src/index.ts b/src/index.ts index efc0a51..908fb80 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import childProcess from 'child_process' +import yaml from 'yaml' export interface IDockerComposeOptions { cwd?: string config?: string | string[] @@ -18,6 +19,14 @@ export type DockerComposeVersionResult = { version: string } +export type DockerComposeConfigResult = { + config: { + version: Record + services: Record> + volumes: Record + } +} + export interface IDockerComposeLogOptions extends IDockerComposeOptions { follow?: boolean } @@ -292,10 +301,19 @@ export const pullOne = function ( return execCompose('pull', [service], options) } -export const config = function ( +export const config = async function ( options?: IDockerComposeOptions -): Promise { - return execCompose('config', [], options) +): Promise> { + 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 ( diff --git a/test/index.test.ts b/test/index.test.ts index 7d83e28..aa25ccb 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -514,9 +514,11 @@ test('config show data for docker-compose files', async (): Promise => { config: 'docker-compose-42.yml' }) - expect(std.err).toBeFalsy() - expect(std.out.includes('some-service')).toBeTruthy() - expect(std.out.includes('test/volume:/mountedvolume:rw')).toBeTruthy() + expect(std.data.config.version).toBe('3') + expect(std.data.config.services['some-service']['image']).toBe( + 'nginx:1.19.9-alpine' + ) + expect(std.data.config.volumes['db-data']).toEqual({}) }) test('config show data for docker-compose files (services)', async (): Promise => { diff --git a/yarn.lock b/yarn.lock index 7a621ef..0cf06b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8920,7 +8920,7 @@ yallist@^4.0.0: resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== -yaml@^1.10.0: +yaml@^1.10.0, yaml@^1.10.2: version "1.10.2" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b" integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==