-
Notifications
You must be signed in to change notification settings - Fork 24
/
copy.js
40 lines (29 loc) · 1016 Bytes
/
copy.js
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
const fs = require('fs');
const glob = require('glob');
const path = require('path');
function copy(base, dest, assets, ignore, force) {
assets.forEach(asset => {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
var files = glob.sync(asset, { cwd: base, strict: true });
files.forEach(file => {
if (ignore.indexOf(file) > -1) {
return;
}
const src = path.join(base, file);
const dst = path.join(dest, file);
if (!fs.existsSync(path.dirname(dst))) {
fs.mkdirSync(path.dirname(dst));
}
if (force === false && fs.existsSync(dst) && fs.statSync(dst).mtime >= fs.statSync(src).mtime) {
return;
}
if (!fs.lstatSync(src).isDirectory()) {
fs.copyFileSync(src, dst);
console.log('emitted:', dst);
}
});
});
}
module.exports = copy;