Skip to content

Commit

Permalink
chore: Update Compose command to parse args directly
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Feb 20, 2024
1 parent f46bcfb commit 1225edd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bun 1.0.26
bun 1.0.28
11 changes: 6 additions & 5 deletions src/commands/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions src/utils/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
13 changes: 5 additions & 8 deletions test/commands/compose.test.ts
Original file line number Diff line number Diff line change
@@ -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}`,
);
});

Expand Down

0 comments on commit 1225edd

Please sign in to comment.