@adonisjs/ace
Version:
Commandline apps framework used by AdonisJs
49 lines (48 loc) • 1.8 kB
JavaScript
;
/*
* @adonisjs/ace
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listDirectoryFiles = void 0;
const slash_1 = __importDefault(require("slash"));
const path_1 = require("path");
const helpers_1 = require("@poppinss/utils/build/helpers");
/**
* Checks if the file exists inside the array. Also an extension
* agnostic check is performed to handle `.ts` and `.js` files
* both
*/
function filesFilter(fileName, filesToIgnore) {
if (filesToIgnore.includes(fileName)) {
return true;
}
fileName = fileName.replace((0, path_1.extname)(fileName), '');
return filesToIgnore.includes(fileName);
}
/**
* Returns an array of Javascript files inside the current directory in
* relative to the application root.
*/
function listDirectoryFiles(scanDirectory, appRoot, filesToIgnore) {
return (0, helpers_1.fsReadAll)(scanDirectory)
.filter((name) => !name.endsWith('.json')) // remove .json files
.map((name) => {
const relativePath = (0, path_1.relative)(appRoot, (0, path_1.join)(scanDirectory, name));
return (0, slash_1.default)(relativePath.startsWith('../') ? relativePath : `./${relativePath}`);
})
.filter((name) => {
if (typeof filesToIgnore === 'function') {
return filesToIgnore(name);
}
return Array.isArray(filesToIgnore) ? !filesFilter(name, filesToIgnore) : true;
});
}
exports.listDirectoryFiles = listDirectoryFiles;