From 0c91bc004405d3a227b7b88acab34adac6427fdf Mon Sep 17 00:00:00 2001 From: yadneshgit2000 Date: Tue, 19 Mar 2024 01:47:50 +0530 Subject: [PATCH] code fix on createIfNot method --- src/utils/fileUtils.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils/fileUtils.ts b/src/utils/fileUtils.ts index 7b08ad0..b408b2b 100644 --- a/src/utils/fileUtils.ts +++ b/src/utils/fileUtils.ts @@ -1,6 +1,11 @@ import * as fs from "node:fs" -export function createIfNot(dir:string) { - if (!fs.existsSync(dir)) { - fs.mkdirSync(dir, { recursive: true }) - } +import * as path from "path" +export function createIfNot(filePath:string) { + const dir = path.dirname(filePath); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + + // create a file + fs.closeSync(fs.openSync(filePath, 'w')); + } }