* Recursively creates a directory and any ancestors that do not yet exist. * * @param {string} dir The directory path to create. * @return {!Promise } A promise that will resolve with the path of the * created directory.
(dir)
| 278 | * created directory. |
| 279 | */ |
| 280 | function mkdirp(dir) { |
| 281 | return checkedCall((callback) => { |
| 282 | fs.mkdir(dir, undefined, (err) => { |
| 283 | if (!err) { |
| 284 | callback(null, dir) |
| 285 | return |
| 286 | } |
| 287 | |
| 288 | switch (err.code) { |
| 289 | case 'EEXIST': |
| 290 | callback(null, dir) |
| 291 | return |
| 292 | case 'ENOENT': |
| 293 | return mkdirp(path.dirname(dir)) |
| 294 | .then(() => mkdirp(dir)) |
| 295 | .then( |
| 296 | () => callback(null, dir), |
| 297 | (err) => callback(err), |
| 298 | ) |
| 299 | default: |
| 300 | callback(err) |
| 301 | return |
| 302 | } |
| 303 | }) |
| 304 | }) |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Recursively walks a directory, returning a promise that will resolve with |
nothing calls this directly
no test coverage detected