lib/utils.js
function mkdir(dirPath, callback) {
  // Credits: https://github.com/substack/node-mkdirp

  // Recursively go through the parents.
  const recurse = () => {
    mkdir(path.dirname(dirPath), (error) => {
      if (error) {
        async.nextTick(callback, error);
        return;
      }

      // Try again.
      mkdir(dirPath, callback);
    });
  };

  // Plan B for when things seem to go wrong.
  const fallBack = () => {
    fs.stat(dirPath, (error, stat) => {
      if (error || !stat.isDirectory()) {
        async.nextTick(
          callback,
          new Error(`${dirPath}: Could not create the directory`)
        );
        return;
      }

      async.nextTick(callback, null);
    });
  };

  fs.mkdir(dirPath, (error) => {
    if (!error) {
      async.nextTick(callback, null);
      return;
    }

    switch (error.code) {
      case 'ENOENT':
        recurse();
        break;
      default:
        fallBack();
        break;
    }
  });
}
function mkdir(dirPath, callback) {
  // Credits: https://github.com/substack/node-mkdirp

  // Recursively go through the parents.
  const recurse = () => {
    mkdir(path.dirname(dirPath), (error) => {
      if (error) {
        async.nextTick(callback, error);
        return;
      }

      // Try again.
      mkdir(dirPath, callback);
    });
  };

  // Plan B for when things seem to go wrong.
  const fallBack = () => {
    fs.stat(dirPath, (error, stat) => {
      if (error || !stat.isDirectory()) {
        async.nextTick(
          callback,
          new Error(`${dirPath}: Could not create the directory`)
        );
        return;
      }

      async.nextTick(callback, null);
    });
  };

  fs.mkdir(dirPath, (error) => {
    if (!error) {
      async.nextTick(callback, null);
      return;
    }

    switch (error.code) {
      case 'ENOENT':
        recurse();
        break;
      default:
        fallBack();
        break;
    }
  });
}
function mkdir ( dirPath , callback ) { // Credits: https://github.com/substack/node-mkdirp // Recursively go through the parents. const recurse = ( ) => { mkdir ( path . dirname ( dirPath ) , ( error ) => { if ( error ) { async . nextTick ( callback , error ) ; return ; } // Try again. mkdir ( dirPath , callback ) ; } ) ; } ; // Plan B for when things seem to go wrong. const fallBack = ( ) => { fs . stat ( dirPath , ( error , stat ) => { if ( error || ! stat . isDirectory ( ) ) { async . nextTick ( callback , new Error ( ` ${ dirPath } ` ) ) ; return ; } async . nextTick ( callback , null ) ; } ) ; } ; fs . mkdir ( dirPath , ( error ) => { if ( ! error ) { async . nextTick ( callback , null ) ; return ; } switch ( error . code ) { case 'ENOENT' : recurse ( ) ; break ; default : fallBack ( ) ; break ; } } ) ; }
Create a directory and any missing parent directory.
Create a directory and any missing parent directory .