forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
50 lines (42 loc) · 902 Bytes
/
utils.js
File metadata and controls
50 lines (42 loc) · 902 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
let fs = require('fs');
let rimraf = require('rimraf');
function fileExists(path) {
let exists = false;
try {
let lstat = fs.lstatSync(path);
exists = lstat.isFile();
} catch (e) { }
return exists;
}
function directoryExists(path) {
let exists = false;
try {
let lstat = fs.lstatSync(path);
exists = lstat.isDirectory();
} catch (e) { }
return exists;
}
function deleteFile(filePath) {
if (fileExists(filePath)) {
console.log(`Deleting: ${filePath}`);
fs.unlinkSync(filePath);
}
return Promise.resolve();
}
function deleteDirectory(directoryPath) {
return new Promise(done => {
if (directoryExists(directoryPath)) {
console.log(`Deleting: ${directoryPath}`);
rimraf(directoryPath, done);
} else {
done();
}
});
}
module.exports = {
fileExists,
directoryExists,
deleteFile,
deleteDirectory
};