1 | ;
|
2 | /**
|
3 | * @module SlimRunner
|
4 | */
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.Loader = void 0;
|
7 | /*
|
8 | * japa
|
9 | *
|
10 | * (c) Harminder Virk <virk@adonisjs.com>
|
11 | *
|
12 | * For the full copyright and license information, please view the LICENSE
|
13 | * file that was distributed with this source code.
|
14 | */
|
15 | /**
|
16 | * Loads files using the glob patterns.
|
17 | *
|
18 | * @class Loader
|
19 | */
|
20 | class Loader {
|
21 | /**
|
22 | * Define the glob for the files
|
23 | */
|
24 | files(glob) {
|
25 | this._glob = glob;
|
26 | }
|
27 | /**
|
28 | * Define a custom filter function to filter files
|
29 | */
|
30 | filter(cb) {
|
31 | this._filterFn = cb;
|
32 | }
|
33 | /**
|
34 | * Returns an array of sorted files based on the glob
|
35 | * pattern.
|
36 | */
|
37 | async loadFiles() {
|
38 | if (!this._glob) {
|
39 | return [];
|
40 | }
|
41 | const fg = await import('fast-glob');
|
42 | let filesPaths = await fg.default(this._glob, {
|
43 | absolute: true,
|
44 | onlyFiles: false,
|
45 | });
|
46 | /**
|
47 | * If filterFn is defined, then filter the files
|
48 | */
|
49 | if (typeof (this._filterFn) === 'function') {
|
50 | filesPaths = filesPaths.filter((file) => this._filterFn(file));
|
51 | }
|
52 | return filesPaths.sort();
|
53 | }
|
54 | }
|
55 | exports.Loader = Loader;
|