forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs-utils.js
More file actions
35 lines (30 loc) · 722 Bytes
/
fs-utils.js
File metadata and controls
35 lines (30 loc) · 722 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
import path from 'path';
import fsp from 'fs-promise';
import fse from 'fs-extra';
export function copy(src, dest, options) {
options = options || {};
return Promise.all([
fsp.stat(src),
fsp.exists(dest)
.then(exists => {
if (!exists) {
return false;
}
return fsp.stat(dest);
})
])
.then(([srcStat, destStat]) => {
if (srcStat.isFile() && destStat && destStat.isDirectory()) {
let filename = path.basename(src);
dest = path.join(dest, filename);
}
return new Promise((resolve, reject) => {
fse.copy(src, dest, options, err => {
if (err) {
reject(err);
}
resolve();
});
});
});
}