MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / main

Function main

apps/api/scripts/get-bots.ts:62–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60}
61
62async 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.

Callers 1

get-bots.tsFile · 0.70

Calls 6

transformBotsFunction · 0.85
joinMethod · 0.80
fetchFunction · 0.50
thenMethod · 0.45
stringifyMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected