const path = require('path'); function getCadType(filename) { const baseName = path.basename(filename).toLowerCase(); const match = baseName.match(/\.(prt|asm|drw|dwr)(?:\.\d+)?$/); return match ? match[1] : null; } function findDestination(filename, config) { const cadType = getCadType(filename); const globalDestination = typeof config?.destination === 'string' ? config.destination.trim() : ''; if (globalDestination && cadType) { return globalDestination; } for (const rule of config.rules || []) { if ((rule.ext || '').toLowerCase() !== cadType) { continue; } if (!rule.pattern) { return rule.destination; } const regex = new RegExp(rule.pattern); if (regex.test(path.basename(filename))) { return rule.destination; } } return null; } function isCadFile(filename) { return Boolean(getCadType(filename)); } module.exports = { findDestination, isCadFile };