Files
stats/apps/api/scripts/get-bots.ts
2024-10-05 23:49:03 +02:00

30 lines
825 B
TypeScript

import fs from 'node:fs';
import path from 'node:path';
import yaml from 'js-yaml';
async function main() {
// Get document, or throw exception on error
try {
const data = await fetch(
'https://raw.githubusercontent.com/matomo-org/device-detector/master/regexes/bots.yml',
).then((res) => res.text());
fs.writeFileSync(
path.resolve(__dirname, '../src/bots/bots.ts'),
[
'// This file is generated by the script get-bots.ts',
'',
'// The data is fetch from device-detector https://raw.githubusercontent.com/matomo-org/device-detector/master/regexes/bots.yml',
'',
`const bots = ${JSON.stringify(yaml.load(data))} as const;`,
'export default bots;',
].join('\n'),
'utf-8',
);
} catch (e) {
console.log(e);
}
}
main();