Skip to content

Commit

Permalink
chore: Updates to compose and file-system utils
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Jul 23, 2024
1 parent 3c11b7d commit 128bf8e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/commands/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export function composeCommand() {
process.exit(1)
}

composeExec({
command: composeArgs,
})
composeExec({ command: composeArgs })
})
}
28 changes: 14 additions & 14 deletions src/utils/compose.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'node:fs'
import { join } from 'node:path'
import { cliConfig } from '../config/cli.config'
import { projectConfig } from '../config/project.config'
import cmd from './cmd'
import { isFile } from './file-system'
Expand All @@ -18,34 +17,35 @@ export function composeExec({ command }: ComposeExecParams) {
}

export function composeFiles({ prefix = 'compose' }: ComposeFilesParams) {
const { repositories, filesPath } = projectConfig.load()
const { reposPath } = cliConfig.load()
const { filesPath } = projectConfig.load()
const reposPath = projectConfig.reposPaths()

const composeFiles = []
const files = []

for (const repo in repositories) {
const files = fs.readdirSync(join(reposPath, repo, filesPath))
for (const file of files) {
if (file.match(`^.*${prefix}.*\.yml$`)) {
composeFiles.push(`--file ${join(reposPath, repo, filesPath, file)}`)
for (const repo of reposPath) {
const paths = fs.readdirSync(join(repo, filesPath))

for (const path of paths) {
if (path.match(`^.*${prefix}.*\.yml$`)) {
files.push(`--file ${join(repo, filesPath, path)}`)
}
}
}

return composeFiles
return files
}

export function composeExecParams() {
const { projectName, envFile, repositories } = projectConfig.load()
const { reposPath } = cliConfig.load()
const { projectName, envFile } = projectConfig.load()
const reposPath = projectConfig.reposPaths()

const params = []

params.push(`--project-name ${projectName}`)
params.push(`--env-file ${envFile}`)

for (const repo in repositories) {
const envFile = join(reposPath, repo, '.env')
for (const repo of reposPath) {
const envFile = join(repo, '.env')
if (isFile(envFile)) {
params.push(`--env-file ${envFile}`)
}
Expand Down
12 changes: 6 additions & 6 deletions src/utils/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import type {
} from './interfaces'
import logger from './log'

export async function isFile(path: string) {
export function isFile(path: string) {
return fs.existsSync(path) && fs.lstatSync(path).isFile()
}

export async function isDirectory(path: string) {
export function isDirectory(path: string) {
return fs.existsSync(path) && fs.lstatSync(path).isDirectory()
}

export async function copyFile({ source, target }: SourceTargetOperation) {
if (await isFile(target)) {
export function copyFile({ source, target }: SourceTargetOperation) {
if (isFile(target)) {
logger.warn(`Path: ${target} already exists.`)
return
}

if (await isFile(source)) {
if (isFile(source)) {
fs.copyFileSync(source, target, 0)
logger.info(`File: ${source} copied to ${target}.`)
} else {
Expand Down Expand Up @@ -69,7 +69,7 @@ export async function deletePath({
}
}

if (await isFile(path)) {
if (isFile(path)) {
if (
force ||
(await confirm({
Expand Down

0 comments on commit 128bf8e

Please sign in to comment.