Skip to content

Commit

Permalink
Refactoring on functions
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemkosk committed Jan 22, 2024
1 parent 73d8449 commit 5da4e6c
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 191 deletions.
4 changes: 2 additions & 2 deletions lib/command/command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getBaseFolder } from '../handler/fileHandler'
import { getEnvolveHomePath } from '../handler/fileHandler'
import inquirer from 'inquirer'

export default abstract class Command {
protected readonly baseFolder: string
protected readonly params: any []

constructor (...params: any[]) {
this.baseFolder = getBaseFolder()
this.baseFolder = getEnvolveHomePath()
this.params = params
}

Expand Down
4 changes: 2 additions & 2 deletions lib/command/commandTypes/compareCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { consola } from 'consola'

export default class CompareCommand extends Command {
protected async beforeExecute (): Promise<any> {
const files: string [] = await getEnvFilesRecursively({ directory: this.baseFolder })
const files: string [] = await getEnvFilesRecursively(this.baseFolder)

if (files.length < 2) {
consola.error(`You must have a minimum of ${chalk.blue('2')} services registered to compare.`)
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class CompareCommand extends Command {
differentVariables,
sourceServiceName,
destinationServiceName
} = await compareEnvFiles({ source, destination })
} = await compareEnvFiles(source, destination)

const table = new Table({
head: ['VALUES', sourceServiceName, destinationServiceName],
Expand Down
2 changes: 1 addition & 1 deletion lib/command/commandTypes/lsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { consola } from 'consola'

export default class LsCommand extends Command {
protected async beforeExecute (): Promise<any> {
const files = await getEnvFilesRecursively({ directory: this.baseFolder })
const files = await getEnvFilesRecursively(this.baseFolder)

if (files.length === 0) {
consola.error(`You have not registered any service yet. Go to the file path of the request with your ${chalk.blue('.env')} file in it and run the ${chalk.blue('sync')} command.`)
Expand Down
4 changes: 2 additions & 2 deletions lib/command/commandTypes/revertCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { consola } from 'consola'

export default class RevertCommand extends Command {
protected async beforeExecute (): Promise<any> {
const files = await getEnvFilesRecursively({ directory: this.baseFolder })
const files = await getEnvFilesRecursively(this.baseFolder)

const { targetPath } = await inquirer.prompt({
type: 'list',
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class RevertCommand extends Command {
protected async onExecute (beforeExecuteReturnValue: any): Promise<void> {
const { targetPath, envValue, newValue } = beforeExecuteReturnValue

await updateEnvFile({ file: targetPath, envValue, newValue })
await updateEnvFile(targetPath, envValue, newValue)
consola.start(`Environment variables restored in "${chalk.blue(targetPath)}"`)
}
}
2 changes: 1 addition & 1 deletion lib/command/commandTypes/updateAllCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class UpdateAllCommand extends Command {
return
}

return await updateAllEnvFile({ envValue, newValue })
return await updateAllEnvFile(envValue, newValue)
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/command/commandTypes/updateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { consola } from 'consola'

export default class UpdateCommand extends Command {
protected async beforeExecute (): Promise<any> {
const files = await getEnvFilesRecursively({ directory: this.baseFolder })
const files = await getEnvFilesRecursively(this.baseFolder)

const { targetPath } = await inquirer.prompt({
type: 'list',
Expand Down Expand Up @@ -43,7 +43,7 @@ export default class UpdateCommand extends Command {

protected async onExecute (beforeExecuteReturnValue: any): Promise<void> {
const { targetPath, envValue, newValue } = beforeExecuteReturnValue
await updateEnvFile({ file: targetPath, envValue, newValue })
await updateEnvFile(targetPath, envValue, newValue)

consola.success(`Environment variables updated in "${chalk.blue(targetPath)}"`)
}
Expand Down
Loading

0 comments on commit 5da4e6c

Please sign in to comment.