Skip to content

Commit

Permalink
bugfix on restore command
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemkosk committed Dec 10, 2023
1 parent dab8e4f commit 5e187b4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/command/commandTypes/CompareCommand.ts
Expand Up @@ -4,13 +4,14 @@ import { getEnvFilesRecursively } from '../../handler/fileHandler'
import Table from 'cli-table3'
import chalk from 'chalk'
import inquirer from 'inquirer'
import { consola } from 'consola'

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

if (files.length < 2) {
console.log(`You must have a minimum of ${chalk.blue('2')} services registered to compare.`)
consola.error(`You must have a minimum of ${chalk.blue('2')} services registered to compare.`)
return
}

Expand Down
3 changes: 2 additions & 1 deletion lib/command/commandTypes/LsCommand.ts
Expand Up @@ -4,13 +4,14 @@ import { getEnvFilesRecursively } from '../../handler/fileHandler'
import Table from 'cli-table3'
import chalk from 'chalk'
import inquirer from 'inquirer'
import { consola } from 'consola'

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

if (files.length === 0) {
throw new 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.`)
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.`)
}

const { targetPath } = await inquirer.prompt({
Expand Down
5 changes: 3 additions & 2 deletions lib/command/commandTypes/RestoreCommand.ts
@@ -1,6 +1,7 @@
import { Command } from '../Command'
import { restoreEnvFile } from '../../handler/envHandler'
import chalk from 'chalk'
import { consola } from 'consola'

export class RestoreCommand extends Command {
protected async beforeExecute (): Promise<any> {
Expand All @@ -15,7 +16,7 @@ export class RestoreCommand extends Command {
const isSuccess = await restoreEnvFile()

isSuccess
? console.log('Reversion was successful. You are ready to go!')
: console.log('There was a problem reverting .env file.')
? consola.success('Reversion was successful. You are ready to go!')
: consola.error('There was a problem reverting .env file.')
}
}
7 changes: 4 additions & 3 deletions lib/command/commandTypes/RevertCommand.ts
Expand Up @@ -5,6 +5,7 @@ import { getEnvVersions } from '../../handler/historyHandler'
import chalk from 'chalk'
import inquirer from 'inquirer'
import { format } from 'date-fns'
import { consola } from 'consola'

export class RevertCommand extends Command {
protected async beforeExecute (): Promise<any> {
Expand Down Expand Up @@ -41,10 +42,10 @@ export class RevertCommand extends Command {
type: 'list',
name: 'version',
message: 'Select a version to restore:',
choices: versions.map((version: { timestamp: any, changes: Array<{ oldValue: any }> }) => {
choices: versions.map((version: { timestamp: any, changes: Array<{ oldValue: any, value: any }> }) => {
const formattedTimestamp = format(new Date(version.timestamp), 'yyyy-MM-dd HH:mm:ss')
return {
name: `Version ${formattedTimestamp} - ${version.changes[0].oldValue}`,
name: `Version ${formattedTimestamp} - ${version.changes[0].value}`,
value: version
}
})
Expand All @@ -57,6 +58,6 @@ export class RevertCommand extends Command {
const { targetPath, envValue, newValue } = beforeExecuteReturnValue

await updateEnvFile({ file: targetPath, envValue, newValue })
console.log(`Environment variables restored in "${chalk.blue(targetPath)}"`)
consola.start(`Environment variables restored in "${chalk.blue(targetPath)}"`)
}
}
5 changes: 3 additions & 2 deletions lib/command/commandTypes/SyncCommand.ts
@@ -1,6 +1,7 @@
import { Command } from '../Command'
import { syncEnvFile } from '../../handler/envHandler'
import chalk from 'chalk'
import { consola } from 'consola'

export class SyncCommand extends Command {
protected async beforeExecute (): Promise<any> {
Expand All @@ -11,7 +12,7 @@ export class SyncCommand extends Command {
const isSuccess: boolean = beforeExecuteReturnValue

;(isSuccess)
? console.log(`Synchronization was ${chalk.blue('successful')}. You are ready to go!`)
: console.log(`There was a ${chalk.red('problem')} synchronizing . Make sure you are on the correct file path and that your file contains an .env file`)
? consola.success(`Synchronization was ${chalk.blue('successful')}. You are ready to go!`)
: consola.error(`There was a ${chalk.red('problem')} synchronizing . Make sure you are on the correct file path and that your file contains an .env file`)
}
}
3 changes: 2 additions & 1 deletion lib/command/commandTypes/UpdateAllCommand.ts
Expand Up @@ -2,6 +2,7 @@ import { Command } from '../Command'
import { updateAllEnvFile, promptForEnvVariable } from '../../handler/envHandler'
import chalk from 'chalk'
import inquirer from 'inquirer'
import { consola } from 'consola'

export class UpdateAllCommand extends Command {
protected async beforeExecute (): Promise<any> {
Expand Down Expand Up @@ -41,7 +42,7 @@ export class UpdateAllCommand extends Command {
const effectedServices: [] = beforeExecuteReturnValue

effectedServices.forEach((service) => {
console.log(`Environment variables updated in "${chalk.blue(service)}"`)
consola.success(`Environment variables updated in "${chalk.blue(service)}"`)
})
}
}
3 changes: 2 additions & 1 deletion lib/command/commandTypes/UpdateCommand.ts
Expand Up @@ -3,6 +3,7 @@ import { getUniqueEnvNames, updateEnvFile } from '../../handler/envHandler'
import { getEnvFilesRecursively } from '../../handler/fileHandler'
import chalk from 'chalk'
import inquirer from 'inquirer'
import { consola } from 'consola'

export class UpdateCommand extends Command {
protected async beforeExecute (): Promise<any> {
Expand Down Expand Up @@ -44,6 +45,6 @@ export class UpdateCommand extends Command {
const { targetPath, envValue, newValue } = beforeExecuteReturnValue
await updateEnvFile({ file: targetPath, envValue, newValue })

console.log(`Environment variables updated in "${chalk.blue(targetPath)}"`)
consola.success(`Environment variables updated in "${chalk.blue(targetPath)}"`)
}
}
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "envolve",
"version": "1.1.3",
"version": "1.1.4",
"description": "Envolve CLI is a powerful tool for managing environment variables in your projects. It allows you to easily create, update, compare, and sync environment files across different services.",
"main": "bin/index.ts",
"type": "module",
Expand All @@ -27,6 +27,7 @@
"chalk": "4.0.0",
"cli-table3": "^0.6.3",
"commander": "^11.1.0",
"consola": "^3.2.3",
"date-fns": "^2.30.0",
"inquirer": "^8.2.6",
"inquirer-autocomplete-prompt": "^2.0.1",
Expand Down

0 comments on commit 5e187b4

Please sign in to comment.