From 1225eddaed38489fa12722fa0be35e4ce9111089 Mon Sep 17 00:00:00 2001 From: "Angel M. Adames" Date: Tue, 20 Feb 2024 11:47:15 -0400 Subject: [PATCH] chore: Update Compose command to parse args directly --- .tool-versions | 2 +- src/commands/compose/index.ts | 11 ++++++----- src/utils/compose.ts | 6 +++--- test/commands/compose.test.ts | 13 +++++-------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.tool-versions b/.tool-versions index 2a6295c..c7f772f 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -bun 1.0.26 +bun 1.0.28 diff --git a/src/commands/compose/index.ts b/src/commands/compose/index.ts index c060c96..d913fcb 100644 --- a/src/commands/compose/index.ts +++ b/src/commands/compose/index.ts @@ -2,6 +2,7 @@ import { Command } from 'commander'; import { projectConfig } from '../../config/project'; import { composeExec } from '../../utils/compose'; import { composeShowArgsCommand } from './show-args'; +import log from '../../utils/log'; export const composeCommand = () => { const command = new Command(); @@ -19,13 +20,13 @@ export const composeCommand = () => { const config = projectConfig(); const args = process.argv.slice(3); - // if (args.length === 0) { - // log.error('A Compose command needs to be specified.'); - // process.exit(1); - // } + if (args.length === 0) { + log.error('A Compose command needs to be specified.'); + process.exit(1); + } const result = composeExec({ - cmd: ['build'], + cmd: args, }); console.log(result.exitCode); console.log(result.stdout.toString()); diff --git a/src/utils/compose.ts b/src/utils/compose.ts index 702d3fe..6ef838f 100644 --- a/src/utils/compose.ts +++ b/src/utils/compose.ts @@ -10,10 +10,10 @@ export const composeExec = ({ files = composeFiles({}), cmd, }: ComposeExecParams) => { - const command = ['docker', 'compose']; - command.concat(envFiles).concat(files).concat(cmd); + let command = ['docker', 'compose']; + command = command.concat(envFiles).concat(files).concat(cmd); console.log(command); - const result = Bun.spawnSync(command); + const result = Bun.spawnSync(command.join(' ').split(' ')); return result; }; diff --git a/test/commands/compose.test.ts b/test/commands/compose.test.ts index f1971e8..2e0b5ba 100644 --- a/test/commands/compose.test.ts +++ b/test/commands/compose.test.ts @@ -1,23 +1,20 @@ import { describe, expect, test } from 'bun:test'; import { projectConfig } from '../../src/config/project'; -import { composeFiles, composeSettings } from '../../src/utils/compose'; +import { composeExecParams, composeFiles } from '../../src/utils/compose'; describe("Command: 'compose'", () => { const config = projectConfig(); test('Returns compose files string', () => { - const composeFileString = composeFiles({ - prefix: 'compose', - filesDir: '.dems', - }); - const composeSettingsString = composeSettings(); + const composeFileString = composeFiles({}); + const composeSettingsString = composeExecParams(); - expect(composeFileString).toBeString(); + expect(composeFileString).toBeArray(); expect(composeSettingsString).toContain( `--env-file ${projectConfig().paths.env_file}`, ); expect(composeSettingsString).toContain( - `-p ${projectConfig().compose.project_name}`, + `--project-name ${projectConfig().compose.project_name}`, ); });