All files / src/modules mkdirp.ts

16.67% Statements 3/18
0% Branches 0/4
0% Functions 0/1
18.75% Lines 3/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x 1x   1x                                        
import * as fs from 'fs';
import * as path from 'path';
 
export default function mkdirp(target: string) {
  const directories: string[] = target.split(path.sep);
  const makingDirectories: string[] = [];
 
  let tempRoot = target;
 
  while (!fs.existsSync(tempRoot)) {
    const dir = directories.pop();
    if (!dir) break;
    makingDirectories.push(dir);
    tempRoot = directories.join(path.sep);
  }
 
  while (makingDirectories.length > 0) {
    const dir = makingDirectories.pop();
    if (!dir) break;
    tempRoot = path.join(tempRoot, dir);
    fs.mkdirSync(tempRoot);
  }
}