You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
476 B

  1. import * as fs from 'fs/promises';
  2. import * as p from 'path';
  3. export const mkdirp = (path: string) => {
  4. const pathFragments = path.replaceAll('\\', '/').split('/');
  5. const directoriesToCheck = pathFragments.reduce(
  6. (theDirectories, fragment, i) => [
  7. ...theDirectories,
  8. theDirectories.length > 0 ? p.join(theDirectories[i - 1], fragment) : fragment,
  9. ],
  10. [] as string[],
  11. )
  12. return Promise.allSettled(directoriesToCheck.map((d) => fs.mkdir(d)));
  13. }