Skip to content

Commit

Permalink
fix(cli): Fixed missing module
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Jul 31, 2024
1 parent fedc43b commit 936d9d9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions apps/cli/src/util/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type {
ProjectRootConfig
} from '@/types/index.types'
import { existsSync } from 'fs'
import { readFile, readdir, writeFile } from 'fs/promises'
import { ensureDirectoryExists } from './fileUtils.ts';
import { readFile, readdir, writeFile, mkdir } from 'fs/promises'

export const getOsType = (): 'unix' | 'windows' => {
return process.platform === 'win32' ? 'windows' : 'unix'
Expand Down Expand Up @@ -60,15 +59,15 @@ export const writeProfileConfig = async (
config: ProfileConfig
): Promise<void> => {
const path = getProfileConfigurationFilePath()
await ensureDirectoryExists(path);
await ensureDirectoryExists(path)
await writeFile(path, JSON.stringify(config, null, 2), 'utf8')
}

export const writePrivateKeyConfig = async (
config: PrivateKeyConfig
): Promise<void> => {
const path = getPrivateKeyConfigurationFilePath()
await ensureDirectoryExists(path);
await ensureDirectoryExists(path)
await writeFile(path, JSON.stringify(config, null, 2), 'utf8')
}

Expand All @@ -84,4 +83,12 @@ export const fetchUserRootConfigurationFiles = async (): Promise<string> => {
const path = `${process.env[home]}/.keyshade`
const files = await readdir(path)
return `- ${files.join('\n- ')}`
}
}

const ensureDirectoryExists = async (path: string) => {
// Create the parent directory if it doesn't exist
const parentDirectory = path.split('/').slice(0, -1).join('/')
if (!existsSync(parentDirectory)) {
await mkdir(parentDirectory, { recursive: true })
}
}

0 comments on commit 936d9d9

Please sign in to comment.