1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.walkStream = exports.walkSync = exports.walk = void 0;
|
4 | const providers_1 = require("./providers");
|
5 | const settings_1 = require("./settings");
|
6 | const readers_1 = require("./readers");
|
7 | const fs_1 = require("./adapters/fs");
|
8 | const fs = new fs_1.FileSystemAdapter();
|
9 | function walk(directory, options, callback) {
|
10 | const optionsIsCallback = typeof options === 'function';
|
11 | const callback_ = optionsIsCallback ? options : callback;
|
12 | const settings = optionsIsCallback ? getSettings() : getSettings(options);
|
13 | const reader = new readers_1.AsyncReader(fs, settings);
|
14 | const provider = new providers_1.AsyncProvider(reader);
|
15 | provider.read(directory, callback_);
|
16 | }
|
17 | exports.walk = walk;
|
18 | function walkSync(directory, optionsOrSettings) {
|
19 | const settings = getSettings(optionsOrSettings);
|
20 | const reader = new readers_1.SyncReader(fs, settings);
|
21 | const provider = new providers_1.SyncProvider(reader);
|
22 | return provider.read(directory);
|
23 | }
|
24 | exports.walkSync = walkSync;
|
25 | function walkStream(directory, optionsOrSettings) {
|
26 | const settings = getSettings(optionsOrSettings);
|
27 | const reader = new readers_1.AsyncReader(fs, settings);
|
28 | const provider = new providers_1.StreamProvider(reader);
|
29 | return provider.read(directory);
|
30 | }
|
31 | exports.walkStream = walkStream;
|
32 | function getSettings(settingsOrOptions = {}) {
|
33 | if (settingsOrOptions instanceof settings_1.Settings) {
|
34 | return settingsOrOptions;
|
35 | }
|
36 | return new settings_1.Settings(settingsOrOptions);
|
37 | }
|