1 | const fs = require("fs-extra");
|
2 | const isFunction = require("lodash/isFunction");
|
3 | const log = require("./logger");
|
4 |
|
5 | function 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 |
|
16 | function isFile(path) {
|
17 | const stats = fs.statSync(path);
|
18 | return stats.isFile();
|
19 | }
|
20 |
|
21 | function isDir(path) {
|
22 | const stats = fs.statSync(path);
|
23 | return stats.isDirectory();
|
24 | }
|
25 |
|
26 | function handleError(err, type) {
|
27 | log.save(type ? `\n${type}:\n${err.message}` : err.message);
|
28 | this.emit("end");
|
29 | }
|
30 |
|
31 | module.exports = { handleError, matchFile, isFile, isDir, handleError };
|