diff --git a/apps/cli/src/util/configuration.ts b/apps/cli/src/util/configuration.ts index 7182aeea..72ff64de 100644 --- a/apps/cli/src/util/configuration.ts +++ b/apps/cli/src/util/configuration.ts @@ -5,6 +5,7 @@ import { } from '../types/index.types' import { existsSync } from 'fs' import { readFile, readdir, writeFile } from 'fs/promises' +import { ensureDirectoryExists } from './fileUtils.ts'; export const getOsType = (): 'unix' | 'windows' => { return process.platform === 'win32' ? 'windows' : 'unix' @@ -83,8 +84,4 @@ export const fetchUserRootConfigurationFiles = async (): Promise => { const path = `${process.env[home]}/.keyshade` const files = await readdir(path) return `- ${files.join('\n- ')}` -} - -async function ensureDirectoryExists(path: string): Promise { - await mkdir(dirname(path), { recursive: true }) -} +} \ No newline at end of file diff --git a/apps/cli/src/util/fileUtils.ts b/apps/cli/src/util/fileUtils.ts new file mode 100644 index 00000000..a63e349b --- /dev/null +++ b/apps/cli/src/util/fileUtils.ts @@ -0,0 +1,14 @@ +import { existsSync, mkdir } from 'fs'; +import { dirname, resolve } from 'path'; + +export async function ensureDirectoryExists(path: string): Promise { + const dir = dirname(resolve(path)); + if (!existsSync(dir)) { + try { + await mkdir(dir, { recursive: true }); + } catch (error) { + console.error('Failed to create directory:', error); + throw error; // Re-throw the error to be handled by the caller + } + } +} \ No newline at end of file