-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcopy.js
27 lines (22 loc) · 845 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
const fs = require('fs');
const glob = require("glob");
const path = require('path');
function copy(base, dest, assets, force) {
assets.forEach(asset => {
glob(asset, { cwd: base, strict: true }, function (error, files) {
files.forEach(file => {
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;
}
fs.createReadStream(src).pipe(fs.createWriteStream(dst));
console.log('emitted:', dst);
});
});
});
}
module.exports = copy;