mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: download mock assets
This commit is contained in:
27
Build/download-mock-assets.ts
Normal file
27
Build/download-mock-assets.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import picocolors from 'picocolors';
|
||||
import { task } from './lib/trace-runner';
|
||||
import path from 'path';
|
||||
import { fetchWithRetry } from './lib/fetch-retry';
|
||||
|
||||
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 fetchWithRetry(url);
|
||||
await Bun.write(targetPath, res as Response);
|
||||
console.timeEnd(key);
|
||||
})));
|
||||
|
||||
if (import.meta.main) {
|
||||
downloadMockAssets();
|
||||
}
|
||||
@@ -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 () => {
|
||||
@@ -70,6 +71,8 @@ import { buildPublic } from './build-public';
|
||||
downloadPreviousBuildPromise
|
||||
]).then(() => buildSSPanelUIMAppProfile());
|
||||
|
||||
const downloadMockAssetsPromise = downloadMockAssets();
|
||||
|
||||
const stats = await Promise.all([
|
||||
downloadPreviousBuildPromise,
|
||||
downloadPublicSuffixListPromise,
|
||||
@@ -87,7 +90,9 @@ import { buildPublic } from './build-public';
|
||||
buildDomesticRulesetPromise,
|
||||
buildRedirectModulePromise,
|
||||
buildStreamServicePromise,
|
||||
buildSSPanelUIMAppProfilePromise
|
||||
buildSSPanelUIMAppProfilePromise,
|
||||
|
||||
downloadMockAssetsPromise
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user