Skip to content

Commit

Permalink
Chore: download mock assets
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 19, 2023
1 parent 7a6363d commit c36e79c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 394 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ List/
Clash/
Modules/sukka_local_dns_mapping.sgmodule
Modules/sukka_url_redirect.sgmodule
Mock/www-google-analytics-com_ga.js
Mock/www-googletagservices-com_gpt.js
Mock/www-google-analytics-com_analytics.js
Mock/www-googlesyndication-com_adsbygoogle.js
26 changes: 26 additions & 0 deletions Build/download-mock-assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import picocolors from 'picocolors';
import { task } from './lib/trace-runner';
import path from 'path';

const ASSETS_LIST = {
'www-google-analytics-com_ga.js': 'https://unpkg.com/@adguard/scriptlets@1/dist/redirect-files/google-analytics-ga.js',
'www-googletagservices-com_gpt.js': 'https://unpkg.com/@adguard/scriptlets@1/dist/redirect-files/googletagservices-gpt.js',
'www-google-analytics-com_analytics.js': 'https://unpkg.com/@adguard/scriptlets@1/dist/redirect-files/google-analytics.js',
'www-googlesyndication-com_adsbygoogle.js': 'https://unpkg.com/@adguard/scriptlets@1/dist/redirect-files/googlesyndication-adsbygoogle.js'
} as const;

const mockDir = path.resolve(import.meta.dir, '../Mock');

export const downloadMockAssets = task(import.meta.path, () => Promise.all(Object.entries(ASSETS_LIST).map(async ([filename, url]) => {
const targetPath = path.join(mockDir, filename);

const key = picocolors.gray(`Download ${filename}`);
console.time(key);
const res = await fetch(url);
await Bun.write(targetPath, res as Response);
console.timeEnd(key);
})));

if (import.meta.main) {
downloadMockAssets();
}
7 changes: 6 additions & 1 deletion Build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { validate } from './validate-domainset';
import { buildSSPanelUIMAppProfile } from './build-sspanel-appprofile';

import { buildPublic } from './build-public';
import { downloadMockAssets } from './download-mock-assets';
// import type { TaskResult } from './lib/trace-runner';

(async () => {
Expand Down Expand Up @@ -70,6 +71,8 @@ import { buildPublic } from './build-public';
downloadPreviousBuildPromise
]).then(() => buildSSPanelUIMAppProfile());

const downloadMockAssetsPromise = downloadMockAssets();

const stats = await Promise.all([
downloadPreviousBuildPromise,
downloadPublicSuffixListPromise,
Expand All @@ -87,7 +90,9 @@ import { buildPublic } from './build-public';
buildDomesticRulesetPromise,
buildRedirectModulePromise,
buildStreamServicePromise,
buildSSPanelUIMAppProfilePromise
buildSSPanelUIMAppProfilePromise,

downloadMockAssetsPromise
]);

await Promise.all([
Expand Down
89 changes: 0 additions & 89 deletions Mock/www-google-analytics-com_analytics.js

This file was deleted.

109 changes: 0 additions & 109 deletions Mock/www-google-analytics-com_ga.js

This file was deleted.

32 changes: 0 additions & 32 deletions Mock/www-googlesyndication-com_adsbygoogle.js

This file was deleted.

24 changes: 0 additions & 24 deletions Mock/www-googletagmanager-com_gtm.js

This file was deleted.

Loading

0 comments on commit c36e79c

Please sign in to comment.