function ensureFolderExists(file) {
  return new Promise((resolve, reject) => {
    let p = file;
    if (path.extname(p) !== "") {
      p = path.dirname(file);
    }

    promisify(mkdir, p)
      .then(() => resolve(p))
      .catch(err => {
        if (err.code === "ENOENT") {
          resolve(ensureFolderExists(path.dirname(p)));
        }

        return promisify(stat, p)
          .then(stats => {
            if (stats.isDirectory()) {
              resolve(p);
            }
            reject(err);
          })
          .catch(e => reject(e));
      });
  });
}
/**
 * Recursively makes directories until the given directory exists.
 * @todo: This is throwing an error on nested directories:
 *  Error: EISDIR: illegal operation on a directory, open 'output/assets'
 * @param {any} file The file or directory to check.
 * @return {Promise<string>} A promise resolving to the created directory.
 */
Recursively makes directories until the given directory exists.
@todo: This is throwing an error on nested directories:
Error: EISDIR: illegal operation on a directory, open 'output/assets'
@param {any} file The file or directory to check.
@return {Promise} A promise resolving to the created directory.
Recursively makes directories until the given directory exists . @todo : This is throwing an error on nested directories : Error : EISDIR : illegal operation on a directory open ' output / assets ' @param { any } file The file or directory to check . @return { Promise } A promise resolving to the created directory .
function ensureFolderExists(file) {
  return new Promise((resolve, reject) => {
    let p = file;
    if (path.extname(p) !== "") {
      p = path.dirname(file);
    }
    promisify(mkdir, p)
      .then(() => resolve(p))
      .catch(err => {
        if (err.code === "ENOENT") {
          resolve(ensureFolderExists(path.dirname(p)));
        }
        return promisify(stat, p)
          .then(stats => {
            if (stats.isDirectory()) {
              resolve(p);
            }
            reject(err);
          })
          .catch(e => reject(e));
      });
  });
}
function ensureFolderExists ( file ) { return new Promise ( ( resolve , reject ) => { let p = file ; if ( path . extname ( p ) !== "" ) { p = path . dirname ( file ) ; } promisify ( mkdir , p ) . then ( ( ) => resolve ( p ) ) . catch ( err => { if ( err . code === "ENOENT" ) { resolve ( ensureFolderExists ( path . dirname ( p ) ) ) ; } return promisify ( stat , p ) . then ( stats => { if ( stats . isDirectory ( ) ) { resolve ( p ) ; } reject ( err ) ; } ) . catch ( e => reject ( e ) ) ; } ) ; } ) ; }
Recursively makes directories until the given directory exists.
Recursively makes directories until the given directory exists .