myst-cli
Version:
Command line tools for MyST
30 lines (29 loc) • 1.03 kB
JavaScript
import fs from 'node:fs';
import path from 'node:path';
import { isDirectory } from 'myst-cli-utils';
import { shouldIgnoreFile } from './shouldIgnoreFile.js';
export function getAllBibTexFilesOnPath(session, dir, ignore) {
let bibFiles = [];
const content = fs.readdirSync(dir);
content
.map((file) => path.join(dir, file))
.filter((file) => {
const isDir = isDirectory(file);
if (ignore === null || ignore === void 0 ? void 0 : ignore.includes(file))
return false;
if (!isDir && path.extname(file) === '.bib') {
// Push the bibtex file to a list!
bibFiles.push(file);
}
// If it is in a list or is hidden
if (shouldIgnoreFile(session, path.basename(file))) {
return false;
}
return isDir;
})
.forEach((subdir) => {
// Now recurse into each directory
bibFiles = bibFiles.concat(getAllBibTexFilesOnPath(session, subdir, ignore));
});
return bibFiles;
}