()
| 60 | } |
| 61 | |
| 62 | async function main() { |
| 63 | // Get document, or throw exception on error |
| 64 | try { |
| 65 | const data = await fetch( |
| 66 | 'https://raw.githubusercontent.com/matomo-org/device-detector/master/regexes/bots.yml', |
| 67 | ).then((res) => res.text()); |
| 68 | |
| 69 | const parsedData = yaml.load(data) as any[]; |
| 70 | const transformedBots = transformBots(parsedData); |
| 71 | |
| 72 | fs.writeFileSync( |
| 73 | path.resolve(__dirname, '../src/bots/bots.ts'), |
| 74 | [ |
| 75 | '// This file is generated by the script get-bots.ts', |
| 76 | '', |
| 77 | '// The data is fetch from device-detector https://raw.githubusercontent.com/matomo-org/device-detector/master/regexes/bots.yml', |
| 78 | '', |
| 79 | `const bots = ${JSON.stringify(transformedBots, null, 2)} as const;`, |
| 80 | 'export default bots;', |
| 81 | '', |
| 82 | ].join('\n'), |
| 83 | 'utf-8', |
| 84 | ); |
| 85 | |
| 86 | console.log( |
| 87 | `✅ Generated bots.ts with ${transformedBots.length} bot entries`, |
| 88 | ); |
| 89 | const regexCount = transformedBots.filter((b) => 'regex' in b).length; |
| 90 | const includesCount = transformedBots.filter((b) => 'includes' in b).length; |
| 91 | console.log(` - ${includesCount} simple string matches (includes)`); |
| 92 | console.log(` - ${regexCount} regex patterns`); |
| 93 | } catch (e) { |
| 94 | console.log(e); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // Only fetch + regenerate when run directly (e.g. `pnpm gen:bots`), so the |
| 99 | // transformation helpers can be imported and unit-tested without a network call. |
no test coverage detected