UNPKG

710 BJavaScriptView Raw
1const fs = require("fs-extra");
2const isFunction = require("lodash/isFunction");
3const log = require("./logger");
4
5function matchFile(file, regexps) {
6 if (!regexps) return false;
7
8 if (isFunction(regexps)) {
9 return isFunction(file);
10 }
11
12 regexps = Array.isArray(regexps) ? regexps : [regexps];
13 return regexps.some(reg => reg.test(file));
14}
15
16function isFile(path) {
17 const stats = fs.statSync(path);
18 return stats.isFile();
19}
20
21function isDir(path) {
22 const stats = fs.statSync(path);
23 return stats.isDirectory();
24}
25
26function handleError(err, type) {
27 log.save(type ? `\n${type}:\n${err.message}` : err.message);
28 this.emit("end");
29}
30
31module.exports = { handleError, matchFile, isFile, isDir, handleError };