UNPKG

1.8 kBJavaScriptView Raw
1"use strict";
2/*
3 * @adonisjs/ace
4 *
5 * (c) Harminder Virk <virk@adonisjs.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10var __importDefault = (this && this.__importDefault) || function (mod) {
11 return (mod && mod.__esModule) ? mod : { "default": mod };
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.listDirectoryFiles = void 0;
15const slash_1 = __importDefault(require("slash"));
16const path_1 = require("path");
17const helpers_1 = require("@poppinss/utils/build/helpers");
18/**
19 * Checks if the file exists inside the array. Also an extension
20 * agnostic check is performed to handle `.ts` and `.js` files
21 * both
22 */
23function filesFilter(fileName, filesToIgnore) {
24 if (filesToIgnore.includes(fileName)) {
25 return true;
26 }
27 fileName = fileName.replace((0, path_1.extname)(fileName), '');
28 return filesToIgnore.includes(fileName);
29}
30/**
31 * Returns an array of Javascript files inside the current directory in
32 * relative to the application root.
33 */
34function listDirectoryFiles(scanDirectory, appRoot, filesToIgnore) {
35 return (0, helpers_1.fsReadAll)(scanDirectory)
36 .filter((name) => !name.endsWith('.json')) // remove .json files
37 .map((name) => {
38 const relativePath = (0, path_1.relative)(appRoot, (0, path_1.join)(scanDirectory, name));
39 return (0, slash_1.default)(relativePath.startsWith('../') ? relativePath : `./${relativePath}`);
40 })
41 .filter((name) => {
42 if (typeof filesToIgnore === 'function') {
43 return filesToIgnore(name);
44 }
45 return Array.isArray(filesToIgnore) ? !filesFilter(name, filesToIgnore) : true;
46 });
47}
48exports.listDirectoryFiles = listDirectoryFiles;