Skip to content

Commit

Permalink
chore: Add composeSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Feb 19, 2024
1 parent 79a8ced commit ae1e304
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/commands/compose/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from 'commander';
import { projectConfig } from '../../config/project';
import { composeFiles } from '../../utils/compose';
import { composeFiles, composeSettings } from '../../utils/compose';

export const composeCommand = () => {
const command = new Command();
Expand All @@ -15,8 +15,13 @@ export const composeCommand = () => {
)
.option('-z, --show-compose-string', 'Shows the Composo files string')
.action(async (options) => {
if (options.showComposeString)
console.log(composeFiles({ prefix: 'compose', filesDir: '.dems' }));
const composeFilesString = composeFiles({
prefix: 'compose',
filesDir: '.dems',
});
const composeString = composeFilesString.concat(composeSettings());

if (options.showComposeString) console.log(composeString);
});

return command;
Expand Down
12 changes: 11 additions & 1 deletion src/utils/compose.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'node:fs';
import path from 'path';
import { projectConfig } from '../config/project';
import type { ComposeFilesParams } from './interfaces';
import { validateLocalGitRepo } from './git';
import type { ComposeFilesParams } from './interfaces';

export const composeFiles = ({
filesDir = '.dems',
Expand Down Expand Up @@ -30,6 +30,16 @@ export const composeFiles = ({
return composeFileString;
};

export const composeSettings = (
projectName: string = projectConfig().compose.project_name,
envFile: string = projectConfig().paths.env_file,
) => {
let composeSettingString = '';
composeSettingString += `-p ${projectName} `;
composeSettingString += `--env-file ${envFile}`;
return composeSettingString;
};

// Execute script only if called directly
if (import.meta.path === Bun.main) {
console.log(composeFiles({ prefix: 'compose', filesDir: '.dems' }));
Expand Down
23 changes: 23 additions & 0 deletions test/commands/compose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, test } from 'bun:test';
import { projectConfig } from '../../src/config/project';
import { composeFiles, composeSettings } 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();

expect(composeFileString).toBeString();
expect(composeSettingsString).toContain(
`--env-file ${projectConfig().paths.env_file}`,
);
expect(composeSettingsString).toContain(
`-p ${projectConfig().compose.project_name}`,
);
});
});

0 comments on commit ae1e304

Please sign in to comment.