From 936d9d9d283b91fb7ce2b56f3804e6455eade7e4 Mon Sep 17 00:00:00 2001 From: rajdip-b Date: Wed, 31 Jul 2024 11:11:06 +0530 Subject: [PATCH] fix(cli): Fixed missing module --- apps/cli/src/util/configuration.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/cli/src/util/configuration.ts b/apps/cli/src/util/configuration.ts index 59c2ef62..241667ee 100644 --- a/apps/cli/src/util/configuration.ts +++ b/apps/cli/src/util/configuration.ts @@ -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' @@ -60,7 +59,7 @@ export const writeProfileConfig = async ( config: ProfileConfig ): Promise => { const path = getProfileConfigurationFilePath() - await ensureDirectoryExists(path); + await ensureDirectoryExists(path) await writeFile(path, JSON.stringify(config, null, 2), 'utf8') } @@ -68,7 +67,7 @@ export const writePrivateKeyConfig = async ( config: PrivateKeyConfig ): Promise => { const path = getPrivateKeyConfigurationFilePath() - await ensureDirectoryExists(path); + await ensureDirectoryExists(path) await writeFile(path, JSON.stringify(config, null, 2), 'utf8') } @@ -84,4 +83,12 @@ export const fetchUserRootConfigurationFiles = async (): Promise => { const path = `${process.env[home]}/.keyshade` const files = await readdir(path) return `- ${files.join('\n- ')}` -} \ No newline at end of file +} + +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 }) + } +}