-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathsync.ts
More file actions
41 lines (33 loc) · 1.18 KB
/
sync.ts
File metadata and controls
41 lines (33 loc) · 1.18 KB
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
import { Task } from '../managers/tasks';
import ReaderSync from '../readers/sync';
import { Entry, EntryItem, ReaderOptions } from '../types';
import Provider from './provider';
export default class ProviderSync extends Provider<EntryItem[]> {
protected _reader: ReaderSync = new ReaderSync(this._settings);
public read(task: Task): EntryItem[] {
const root = this._getRootDirectory(task);
const options = this._getReaderOptions(task);
return ([] as Entry[])
.concat(this._readBasePatternDirectory(task, options))
.concat(this._readTask(root, task, options))
.map(options.transform);
}
private _readBasePatternDirectory(task: Task, options: ReaderOptions): Entry[] {
/**
* Currently, the micromatch package cannot match the input string `.` when the '**' pattern is used.
*/
if (task.base === '.') {
return [];
}
if (task.dynamic && this._settings.includePatternBaseDirectory) {
return this._reader.static([task.base], options);
}
return [];
}
private _readTask(root: string, task: Task, options: ReaderOptions): Entry[] {
if (task.dynamic) {
return this._reader.dynamic(root, options);
}
return this._reader.static(task.patterns, options);
}
}