download-mock-assets.ts 1.1 KB

12345678910111213141516171819202122
  1. import { task } from './trace';
  2. import path from 'path';
  3. import { fetchWithRetry } from './lib/fetch-retry';
  4. const ASSETS_LIST = {
  5. 'www-google-analytics-com_ga.js': 'https://raw.githubusercontent.com/AdguardTeam/Scriptlets/master/dist/redirect-files/google-analytics-ga.js',
  6. 'www-googletagservices-com_gpt.js': 'https://raw.githubusercontent.com/AdguardTeam/Scriptlets/master/dist/redirect-files/googletagservices-gpt.js',
  7. 'www-google-analytics-com_analytics.js': 'https://raw.githubusercontent.com/AdguardTeam/Scriptlets/master/dist/redirect-files/google-analytics.js',
  8. 'www-googlesyndication-com_adsbygoogle.js': 'https://raw.githubusercontent.com/AdguardTeam/Scriptlets/master/dist/redirect-files/googlesyndication-adsbygoogle.js'
  9. } as const;
  10. const mockDir = path.resolve(import.meta.dir, '../Mock');
  11. export const downloadMockAssets = task(import.meta.path, (span) => Promise.all(Object.entries(ASSETS_LIST).map(
  12. ([filename, url]) => span
  13. .traceChild(url)
  14. .traceAsyncFn(() => fetchWithRetry(url).then(res => Bun.write(path.join(mockDir, filename), res)))
  15. )));
  16. if (import.meta.main) {
  17. downloadMockAssets();
  18. }