@bitloops/bl-transpiler
Version:
The one and only Bitloops Language transpiler
60 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRecursivelyFileInDirectory = void 0;
const tslib_1 = require("tslib");
/**
* Bitloops Language CLI
* Copyright (C) 2022 Bitloops S.A.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* For further information you can contact legal(at)bitloops.com.
*/
const fs = tslib_1.__importStar(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
const CWD = process.cwd();
const getRecursivelyFileInDirectory = (directoryPath, suffix) => {
let dirPath;
if (path_1.default.isAbsolute(directoryPath)) {
dirPath = directoryPath;
}
else {
dirPath = path_1.default.join(CWD, directoryPath);
}
// console.log('dirPath', directoryPath, dirPath, CWD);
const resultFiles = [];
fs.readdirSync(dirPath).forEach((file) => {
const filePath = path_1.default.join(dirPath, file);
const isDirectory = fs.statSync(filePath).isDirectory();
if (isDirectory) {
const files = getFiles(filePath);
resultFiles.push(...files);
}
else {
resultFiles.push(filePath);
}
});
const blFiles = resultFiles.filter((filePath) => filePath.split('.')[1] === suffix);
return blFiles;
};
exports.getRecursivelyFileInDirectory = getRecursivelyFileInDirectory;
const getFiles = (dir) => {
const dirents = fs.readdirSync(dir, { withFileTypes: true });
const files = dirents.map((dirent) => {
const currentPath = path_1.default.join(dir, dirent.name);
return dirent.isDirectory() ? getFiles(currentPath) : [currentPath];
});
return Array.prototype.concat(...files);
};
//# sourceMappingURL=getRecursivelyFileInDirectory.js.map