JSFiddle - React, Tailwind, and code Playground

by himel023

JavaScript

isDirExist = dirPath => {
    if (fs.existsSync(dirPath)) {
      return true;
    } else return false;
  },

   addFolderToStorage =  (folderName, dirPath) => {
    if (!fs.existsSync(`./public/${dirPath}${folderName}`)) {
      let folderDirArr = dirPath.split("/");
      let currentDir = `./public`;
      for (let i = 0; i < folderDirArr.length; i++) {
        currentDir += `/${folderDirArr[i]}`;
        console.log(currentDir);
        console.log(utilFunctions);
        console.log(!utilFunctions.isDirExist(currentDir));
        if (!utilFunctions.isDirExist(currentDir)) {
          fs.mkdirSync(`${currentDir}`);
        }
      }
      if(!utilFunctions.isDirExist(`${currentDir}${folderName}`)){
        fs.mkdirSync(`${currentDir}${folderName}`);
      }
      return true;
    } else {
      return false;
    }
  }