Skip to content

Commit

Permalink
fix: moved function to common utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Princeyadav05 committed Jul 16, 2024
1 parent 6febde3 commit b51c6a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 2 additions & 5 deletions apps/cli/src/util/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -83,8 +84,4 @@ export const fetchUserRootConfigurationFiles = async (): Promise<string> => {
const path = `${process.env[home]}/.keyshade`
const files = await readdir(path)
return `- ${files.join('\n- ')}`
}

async function ensureDirectoryExists(path: string): Promise<void> {
await mkdir(dirname(path), { recursive: true })
}
}
14 changes: 14 additions & 0 deletions apps/cli/src/util/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { existsSync, mkdir } from 'fs';
import { dirname, resolve } from 'path';

export async function ensureDirectoryExists(path: string): Promise<void> {
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
}
}
}

0 comments on commit b51c6a1

Please sign in to comment.