-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgatherFiles.js
42 lines (36 loc) · 1008 Bytes
/
gatherFiles.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
41
42
import { basename, join } from 'path';
import { cwd } from 'process';
import glob from 'glob';
import { statSync } from 'fs';
import { handleFileError } from './errorTypes';
export async function gatherFiles(paths, { globString = '**/*.{js,jsx,map,bundle}' } = {}) {
const map = [];
await Promise.all(paths.map((path) => {
const realPath = join(cwd(), path);
let isFile;
try {
isFile = statSync(realPath).isFile();
} catch (err) {
handleFileError(`Error accessing stats for ${path}`, err);
}
if (isFile) {
map.push({
path: realPath,
name: basename(realPath),
});
} else {
try {
glob(globString, { cwd: realPath, sync: true }).forEach(async file => {
map.push({
path: join(realPath, file),
name: file,
});
});
} catch (err) {
handleFileError(`Error scanning ${path} for files`, err);
}
}
return Promise.resolve();
}));
return map;
}