diff --git a/src/commands/clean/index.ts b/src/commands/clean/index.ts index e3f625c..01d10b3 100644 --- a/src/commands/clean/index.ts +++ b/src/commands/clean/index.ts @@ -22,9 +22,18 @@ export const cleanCommand = () => { log.info('User interactivity disabled due to --force flag.'); } - await deletePath({ path: config.paths.repos_root, force: options.force }); - await deletePath({ path: config.paths.data, force: options.force }); - await deletePath({ path: config.paths.env_file, force: options.force }); + await deletePath({ + path: config.paths.repos_root, + force: options.force, + }); + await deletePath({ + path: config.paths.data, + force: options.force, + }); + await deletePath({ + path: config.paths.env_file, + force: options.force, + }); log.success('Clean completed for current project.'); }); diff --git a/src/commands/compose/index.ts b/src/commands/compose/index.ts new file mode 100644 index 0000000..e5d0047 --- /dev/null +++ b/src/commands/compose/index.ts @@ -0,0 +1,20 @@ +import { Command } from 'commander'; +import { projectConfig } from '../../config/project'; + +export const composeCommand = () => { + const command = new Command(); + const config = projectConfig(); + + command + .name('compose') + .summary('Container orchestration command for DEMS') + .description( + 'Aids in container orchestration for services in DEMS.\n' + + 'Uses Compose under the hood.', + ) + .action(async (options) => {}); + + return command; +}; + +export default composeCommand(); diff --git a/src/commands/config/index.ts b/src/commands/config/index.ts index 462d849..882040c 100644 --- a/src/commands/config/index.ts +++ b/src/commands/config/index.ts @@ -14,7 +14,7 @@ export const configCommand = () => { .addCommand(projectConfigCommand()) .action((options) => { if (options.generate) { - createPath(cliConfig.root); + createPath({ path: cliConfig.root }); createFile({ file: cliConfig.file, content: JSON.stringify(cliConfig, null, 2), diff --git a/src/utils/compose-spec.ts b/src/utils/compose-spec.ts new file mode 100644 index 0000000..3cbacc4 --- /dev/null +++ b/src/utils/compose-spec.ts @@ -0,0 +1,13 @@ +const COMPOSE_SPEC_JSON_FILE_RULE = + 'https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json'; + +const downloadComposeSpecJSON = ( + url: URL = new URL(COMPOSE_SPEC_JSON_FILE_RULE), +) => { + console.log(url.toString()); +}; + +// Execute script only if called directly +if (import.meta.path === Bun.main) { + downloadComposeSpecJSON(); +} diff --git a/src/utils/compose.ts b/src/utils/compose.ts index f720b03..bad3b7f 100644 --- a/src/utils/compose.ts +++ b/src/utils/compose.ts @@ -1,30 +1,34 @@ import fs from 'node:fs'; import path from 'path'; +import { projectConfig } from '../config/project'; import type { ComposeFilesParams } from './interfaces'; export const composeFiles = ({ + filesDir = '.dems', prefix = 'compose', - filesDir = 'src/compose', - dockerDir = '.docker', + repos = projectConfig().repositories, + reposRoot = projectConfig().paths.repos_root, }: ComposeFilesParams): string => { let composeFileString = ''; + const composeDirs = []; - const readFilesRecursively = (currentDir: string) => { - const files = fs.readdirSync(currentDir); + for (const dir of repos) { + composeDirs.push(`${reposRoot}/${dir}/${filesDir}`); + } + for (const dir of composeDirs) { + const files = fs.readdirSync(dir); for (const file of files) { - const filePath = path.join(currentDir, file); - const isDirectory = fs.statSync(filePath).isDirectory(); - - if (isDirectory && file === dockerDir) { - readFilesRecursively(filePath); - } else if (file.match(`${prefix}.*.yml`)) { - composeFileString += ` -f ${filePath}`; + if (file.match(`${prefix}*.yml`)) { + composeFileString += ` -f ${path.join(dir, file)}`; } } - }; - - readFilesRecursively(filesDir); + } return composeFileString; }; + +// Execute script only if called directly +if (import.meta.path === Bun.main) { + console.log(composeFiles({ prefix: 'compose', filesDir: '.dems' })); +} diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index cadc29b..39fd705 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -24,6 +24,8 @@ export interface GitParams { } export interface ComposeFilesParams { + reposRoot?: string; + repos?: Array; prefix?: string; filesDir?: string; dockerDir?: string;