import { getFileInfoType } from "./utils.ts";const { lstat, lstatSync, mkdir, mkdirSync } = Deno;
export async function ensureDir(dir: string): Promise<void> { try { const fileInfo = await lstat(dir); if (!fileInfo.isDirectory()) { throw new Error( `Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'` ); } } catch (err) { if (err instanceof Deno.errors.NotFound) { await mkdir(dir, { recursive: true }); return; } throw err; }}
export function ensureDirSync(dir: string): void { try { const fileInfo = lstatSync(dir); if (!fileInfo.isDirectory()) { throw new Error( `Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'` ); } } catch (err) { if (err instanceof Deno.errors.NotFound) { mkdirSync(dir, { recursive: true }); return; } throw err; }}