| 64 | } |
| 65 | |
| 66 | async function main() { |
| 67 | // Get document, or throw exception on error |
| 68 | try { |
| 69 | const data = await fetch( |
| 70 | 'https://s3-eu-west-1.amazonaws.com/snowplow-hosted-assets/third-party/referer-parser/referers-latest.json', |
| 71 | ).then((res) => res.json()); |
| 72 | |
| 73 | fs.writeFileSync( |
| 74 | path.resolve(__dirname, '../../worker/src/referrers/index.ts'), |
| 75 | [ |
| 76 | '// This file is generated by the script get-referrers.ts', |
| 77 | '', |
| 78 | '// The data is fetch from snowplow-referer-parser https://github.com/snowplow-referer-parser/referer-parser', |
| 79 | `// The orginal referers.yml is based on Piwik's SearchEngines.php and Socials.php, copyright 2012 Matthieu Aubry and available under the GNU General Public License v3.`, |
| 80 | '', |
| 81 | `const referrers: Record<string, { type: string, name: string }> = ${JSON.stringify( |
| 82 | { |
| 83 | ...transform(data), |
| 84 | ...extraReferrers, |
| 85 | }, |
| 86 | )} as const;`, |
| 87 | 'export default referrers;', |
| 88 | ].join('\n'), |
| 89 | 'utf-8', |
| 90 | ); |
| 91 | } catch (e) { |
| 92 | console.log(e); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | main(); |