-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathutils.js
More file actions
30 lines (27 loc) · 717 Bytes
/
Copy pathutils.js
File metadata and controls
30 lines (27 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"use strict";
const fs = require('fs');
const path = require('path');
function mkdirSyncRecursively(dir, mode) {
try {
var result = fs.mkdirSync(dir, mode);
}
catch(e) {
if(e.code === 'ENOENT') {
mkdirSyncRecursively(path.dirname(dir), mode); // if does not exists, create all parents recursively
mkdirSyncRecursively(dir, mode); // retry
}
}
}
function createDirectoryIfNotExists(dir) {
try {
fs.accessSync(dir, fs.F_OK);
}
catch(e) {
// create directory if not exists
mkdirSyncRecursively(dir, '0755');
}
}
module.exports = {
mkdirSyncRecursively: mkdirSyncRecursively,
createDirectoryIfNotExists: createDirectoryIfNotExists
};