import { dirname } from 'path' ; import { mkdirSync , statSync } from 'fs' ; export function createDirectory ( directoryPath ) { const parentPath = dirname ( directoryPath ) ; if ( ! directoryExists ( parentPath ) ) { createDirectory ( parentPath ) ; } if ( ! directoryExists ( directoryPath ) ) { mkdirSync ( directoryPath ) ; } } function directoryExists ( name ) { try { return statSync ( name ) . isDirectory ( ) ; } catch { return false ; } }