const FONT_EXT = /\.(ttf|otf|ttc|woff|woff2)$/i;
function scanFontsDir(dir, system = true, seen = new Set()) {
const fonts = [];
if (!fs.existsSync(dir)) return fonts;
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
fonts.push(...scanFontsDir(fullPath, system, seen));
} else if (entry.isFile() && FONT_EXT.test(entry.name)) {
if (!seen.has(fullPath)) {
fonts.push({
name: path.parse(entry.name).name,
path: fullPath,
system,
ext: path.extname(entry.name).slice(1).toLowerCase(),
});
seen.add(fullPath);
}
}
}
return fonts;
}