Created
May 6, 2018 10:41
-
-
Save d0whc3r/219c6f46b03d73b35c1b74dc31349092 to your computer and use it in GitHub Desktop.
simple recursive mkdir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const fs = require('fs'); | |
function mkdirp(targetDir) { | |
const sep = path.sep; | |
const initDir = path.isAbsolute(targetDir) ? sep : ''; | |
targetDir.split(sep).reduce((parentDir, childDir) => { | |
const curDir = path.resolve(parentDir, childDir); | |
if (!fs.existsSync(curDir)) { | |
fs.mkdirSync(curDir); | |
} | |
return curDir; | |
}, initDir); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment