forked from vladshcherbin/rollup-plugin-copy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (30 loc) · 1.01 KB
/
index.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
var fse = require("fs-extra");
var colors = require("colors");
function success(name, src, dest) {
console.log("(" + name + ") '" + src.green + "' -> '" + dest.green + "' (" + "\u2714".green + ")");
}
function fatal(name, src, dest, err) {
console.error("(" + name + ") '" + src.red + "' -> '" + dest.red + "' (" + "\u2718".red + ")");
console.error();
console.error(" " + err);
process.exit(err.errno);
}
module.exports = function(options={}) {
const { verbose=false } = options;
const name = "rollup-plugin-copy";
return {
name: name,
ongenerate: function(object) {
for (key in options) {
if (key == "verbose") continue;
const src = key;
const dest = options[key];
fse.copy(src, dest).then( () => {
if (verbose) success(name, src, dest);
}).catch( (err) => {
fatal(name, src, dest, err);
});
}
}
}
};