mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Refactor: rework tracer
This commit is contained in:
parent
f5863d82d1
commit
9a0113bf69
@ -17,7 +17,7 @@ export const getAppleCdnDomainsPromise = createMemoizedPromise(() => fsFetchCach
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
export const buildAppleCdn = task(import.meta.path, async (span) => {
|
export const buildAppleCdn = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const promise = getAppleCdnDomainsPromise();
|
const promise = getAppleCdnDomainsPromise();
|
||||||
const res: string[] = await span.traceChildPromise('get apple cdn domains', promise);
|
const res: string[] = await span.traceChildPromise('get apple cdn domains', promise);
|
||||||
|
|
||||||
@ -56,7 +56,3 @@ export const buildAppleCdn = task(import.meta.path, async (span) => {
|
|||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildAppleCdn();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -48,7 +48,7 @@ const getS3OSSDomainsPromise = (async (): Promise<Set<string>> => {
|
|||||||
return S3OSSDomains;
|
return S3OSSDomains;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
export const buildCdnDownloadConf = task(import.meta.path, async (span) => {
|
export const buildCdnDownloadConf = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const [
|
const [
|
||||||
S3OSSDomains,
|
S3OSSDomains,
|
||||||
|
|
||||||
@ -98,7 +98,3 @@ export const buildCdnDownloadConf = task(import.meta.path, async (span) => {
|
|||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildCdnDownloadConf();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export const getChnCidrPromise = createMemoizedPromise(async () => {
|
|||||||
return exclude([...cidr, ...CN_CIDR_NOT_INCLUDED_IN_CHNROUTE], NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true);
|
return exclude([...cidr, ...CN_CIDR_NOT_INCLUDED_IN_CHNROUTE], NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const buildChnCidr = task(import.meta.path, async (span) => {
|
export const buildChnCidr = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const filteredCidr = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|
const filteredCidr = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|
||||||
|
|
||||||
// Can not use SHARED_DESCRIPTION here as different license
|
// Can not use SHARED_DESCRIPTION here as different license
|
||||||
@ -49,7 +49,3 @@ export const buildChnCidr = task(import.meta.path, async (span) => {
|
|||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildChnCidr();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { task } from './trace';
|
|||||||
const outputSurgeDir = path.resolve(import.meta.dir, '../List');
|
const outputSurgeDir = path.resolve(import.meta.dir, '../List');
|
||||||
const outputClashDir = path.resolve(import.meta.dir, '../Clash');
|
const outputClashDir = path.resolve(import.meta.dir, '../Clash');
|
||||||
|
|
||||||
export const buildCloudMounterRules = task(import.meta.path, async (span) => {
|
export const buildCloudMounterRules = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
// AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com))
|
// AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com))
|
||||||
|
|
||||||
const results = DOMAINS.flatMap(domain => {
|
const results = DOMAINS.flatMap(domain => {
|
||||||
@ -29,7 +29,3 @@ export const buildCloudMounterRules = task(import.meta.path, async (span) => {
|
|||||||
path.resolve(outputClashDir, 'non_ip', 'cloudmounter.txt')
|
path.resolve(outputClashDir, 'non_ip', 'cloudmounter.txt')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildCloudMounterRules();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ const sourceDir = path.resolve(import.meta.dir, '../Source');
|
|||||||
const outputSurgeDir = path.resolve(import.meta.dir, '../List');
|
const outputSurgeDir = path.resolve(import.meta.dir, '../List');
|
||||||
const outputClashDir = path.resolve(import.meta.dir, '../Clash');
|
const outputClashDir = path.resolve(import.meta.dir, '../Clash');
|
||||||
|
|
||||||
export const buildCommon = task(import.meta.path, async (span) => {
|
export const buildCommon = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const promises: Array<Promise<unknown>> = [];
|
const promises: Array<Promise<unknown>> = [];
|
||||||
|
|
||||||
const paths = await new Fdir()
|
const paths = await new Fdir()
|
||||||
@ -54,10 +54,6 @@ export const buildCommon = task(import.meta.path, async (span) => {
|
|||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildCommon();
|
|
||||||
}
|
|
||||||
|
|
||||||
const processFile = (span: Span, sourcePath: string) => {
|
const processFile = (span: Span, sourcePath: string) => {
|
||||||
// console.log('Processing', sourcePath);
|
// console.log('Processing', sourcePath);
|
||||||
return span.traceChildAsync(`process file: ${sourcePath}`, async () => {
|
return span.traceChildAsync(`process file: ${sourcePath}`, async () => {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ const DEPRECATED_FILES = [
|
|||||||
const outputSurgeDir = path.resolve(import.meta.dir, '../List');
|
const outputSurgeDir = path.resolve(import.meta.dir, '../List');
|
||||||
const outputClashDir = path.resolve(import.meta.dir, '../Clash');
|
const outputClashDir = path.resolve(import.meta.dir, '../Clash');
|
||||||
|
|
||||||
export const buildDeprecateFiles = task(import.meta.path, (span) => span.traceChildAsync('create deprecated files', async (childSpan) => {
|
export const buildDeprecateFiles = task(import.meta.main, import.meta.path)((span) => span.traceChildAsync('create deprecated files', async (childSpan) => {
|
||||||
const promises: Array<Promise<unknown>> = [];
|
const promises: Array<Promise<unknown>> = [];
|
||||||
|
|
||||||
for (const [filePath, description] of DEPRECATED_FILES) {
|
for (const [filePath, description] of DEPRECATED_FILES) {
|
||||||
@ -33,7 +33,3 @@ export const buildDeprecateFiles = task(import.meta.path, (span) => span.traceCh
|
|||||||
|
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildDeprecateFiles();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export const getDomesticDomainsRulesetPromise = createMemoizedPromise(async () =
|
|||||||
return results;
|
return results;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const buildDomesticRuleset = task(import.meta.path, async (span) => {
|
export const buildDomesticRuleset = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const rulesetDescription = [
|
const rulesetDescription = [
|
||||||
...SHARED_DESCRIPTION,
|
...SHARED_DESCRIPTION,
|
||||||
'',
|
'',
|
||||||
@ -66,7 +66,3 @@ export const buildDomesticRuleset = task(import.meta.path, async (span) => {
|
|||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildDomesticRuleset();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { exclude, merge } from 'fast-cidr-tools';
|
|||||||
import { getChnCidrPromise } from './build-chn-cidr';
|
import { getChnCidrPromise } from './build-chn-cidr';
|
||||||
import { NON_CN_CIDR_INCLUDED_IN_CHNROUTE, RESERVED_IPV4_CIDR } from './constants/cidr';
|
import { NON_CN_CIDR_INCLUDED_IN_CHNROUTE, RESERVED_IPV4_CIDR } from './constants/cidr';
|
||||||
|
|
||||||
export const buildInternalReverseChnCIDR = task(import.meta.path, async () => {
|
export const buildInternalReverseChnCIDR = task(import.meta.main, import.meta.path)(async () => {
|
||||||
const cidrPromise = getChnCidrPromise();
|
const cidrPromise = getChnCidrPromise();
|
||||||
const peeked = Bun.peek(cidrPromise);
|
const peeked = Bun.peek(cidrPromise);
|
||||||
const cidr: string[] = peeked === cidrPromise
|
const cidr: string[] = peeked === cidrPromise
|
||||||
@ -25,7 +25,3 @@ export const buildInternalReverseChnCIDR = task(import.meta.path, async () => {
|
|||||||
|
|
||||||
return Bun.write(path.resolve(import.meta.dir, '../Internal/reversed-chn-cidr.txt'), `${reversedCidr.join('\n')}\n`);
|
return Bun.write(path.resolve(import.meta.dir, '../Internal/reversed-chn-cidr.txt'), `${reversedCidr.join('\n')}\n`);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildInternalReverseChnCIDR();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ export const getMicrosoftCdnRulesetPromise = createMemoizedPromise(async () => {
|
|||||||
.concat(WHITELIST);
|
.concat(WHITELIST);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const buildMicrosoftCdn = task(import.meta.path, async (span) => {
|
export const buildMicrosoftCdn = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const description = [
|
const description = [
|
||||||
...SHARED_DESCRIPTION,
|
...SHARED_DESCRIPTION,
|
||||||
'',
|
'',
|
||||||
@ -67,7 +67,3 @@ export const buildMicrosoftCdn = task(import.meta.path, async (span) => {
|
|||||||
path.resolve(import.meta.dir, '../Clash/non_ip/microsoft_cdn.txt')
|
path.resolve(import.meta.dir, '../Clash/non_ip/microsoft_cdn.txt')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildMicrosoftCdn();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ const folderAndFilesToBeDeployed = [
|
|||||||
'LICENSE'
|
'LICENSE'
|
||||||
];
|
];
|
||||||
|
|
||||||
export const buildPublic = task(import.meta.path, async (span) => {
|
export const buildPublic = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
await span
|
await span
|
||||||
.traceChild('copy public files')
|
.traceChild('copy public files')
|
||||||
.traceAsyncFn(async () => {
|
.traceAsyncFn(async () => {
|
||||||
@ -45,10 +45,6 @@ export const buildPublic = task(import.meta.path, async (span) => {
|
|||||||
return Bun.write(path.join(publicPath, 'index.html'), html);
|
return Bun.write(path.join(publicPath, 'index.html'), html);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildPublic();
|
|
||||||
}
|
|
||||||
|
|
||||||
const priorityOrder: Record<'default' | string & {}, number> = {
|
const priorityOrder: Record<'default' | string & {}, number> = {
|
||||||
domainset: 1,
|
domainset: 1,
|
||||||
non_ip: 2,
|
non_ip: 2,
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import { sort } from './lib/timsort';
|
|||||||
|
|
||||||
const getRejectSukkaConfPromise = readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/domainset/reject_sukka.conf'));
|
const getRejectSukkaConfPromise = readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/domainset/reject_sukka.conf'));
|
||||||
|
|
||||||
export const buildRejectDomainSet = task(import.meta.path, async (span) => {
|
export const buildRejectDomainSet = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
/** Whitelists */
|
/** Whitelists */
|
||||||
const filterRuleWhitelistDomainSets = new Set(PREDEFINED_WHITELIST);
|
const filterRuleWhitelistDomainSets = new Set(PREDEFINED_WHITELIST);
|
||||||
|
|
||||||
@ -167,7 +167,3 @@ export const buildRejectDomainSet = task(import.meta.path, async (span) => {
|
|||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildRejectDomainSet();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -67,7 +67,7 @@ const getBotNetFilterIPsPromise = fsFetchCache.apply(
|
|||||||
|
|
||||||
const localRejectIPSourcesPromise = readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/ip/reject.conf'));
|
const localRejectIPSourcesPromise = readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/ip/reject.conf'));
|
||||||
|
|
||||||
export const buildRejectIPList = task(import.meta.path, async (span) => {
|
export const buildRejectIPList = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const result = await localRejectIPSourcesPromise;
|
const result = await localRejectIPSourcesPromise;
|
||||||
|
|
||||||
const bogusNxDomainIPs = await span.traceChildPromise('get bogus nxdomain ips', getBogusNxDomainIPsPromise);
|
const bogusNxDomainIPs = await span.traceChildPromise('get bogus nxdomain ips', getBogusNxDomainIPsPromise);
|
||||||
@ -97,7 +97,3 @@ export const buildRejectIPList = task(import.meta.path, async (span) => {
|
|||||||
path.resolve(import.meta.dir, '../Clash/ip/reject.txt')
|
path.resolve(import.meta.dir, '../Clash/ip/reject.txt')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildRejectIPList();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -49,7 +49,7 @@ const HOSTNAMES = [
|
|||||||
'*.battlenet.com'
|
'*.battlenet.com'
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const buildAlwaysRealIPModule = task(import.meta.path, async (span) => {
|
export const buildAlwaysRealIPModule = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
return compareAndWriteFile(
|
return compareAndWriteFile(
|
||||||
span,
|
span,
|
||||||
[
|
[
|
||||||
@ -62,7 +62,3 @@ export const buildAlwaysRealIPModule = task(import.meta.path, async (span) => {
|
|||||||
path.resolve(import.meta.dir, '../Modules/sukka_common_always_realip.sgmodule')
|
path.resolve(import.meta.dir, '../Modules/sukka_common_always_realip.sgmodule')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildAlwaysRealIPModule();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -118,7 +118,7 @@ const REDIRECT_FAKEWEBSITES = [
|
|||||||
['zbrushcn.com', 'https://www.maxon.net/en/zbrush']
|
['zbrushcn.com', 'https://www.maxon.net/en/zbrush']
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const buildRedirectModule = task(import.meta.path, async (span) => {
|
export const buildRedirectModule = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const domains = Array.from(
|
const domains = Array.from(
|
||||||
new Set(
|
new Set(
|
||||||
[
|
[
|
||||||
@ -144,7 +144,3 @@ export const buildRedirectModule = task(import.meta.path, async (span) => {
|
|||||||
path.resolve(import.meta.dir, '../Modules/sukka_url_redirect.sgmodule')
|
path.resolve(import.meta.dir, '../Modules/sukka_url_redirect.sgmodule')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildRedirectModule();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -93,7 +93,7 @@ const getPreviousSpeedtestDomainsPromise = createMemoizedPromise(async () => {
|
|||||||
return domains;
|
return domains;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const buildSpeedtestDomainSet = task(import.meta.path, async (span) => {
|
export const buildSpeedtestDomainSet = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
// Predefined domainset
|
// Predefined domainset
|
||||||
/** @type {Set<string>} */
|
/** @type {Set<string>} */
|
||||||
const domains = new Set<string>([
|
const domains = new Set<string>([
|
||||||
@ -267,7 +267,3 @@ export const buildSpeedtestDomainSet = task(import.meta.path, async (span) => {
|
|||||||
path.resolve(import.meta.dir, '../Clash/domainset/speedtest.txt')
|
path.resolve(import.meta.dir, '../Clash/domainset/speedtest.txt')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildSpeedtestDomainSet();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ const removeNoResolved = (line: string) => line.replace(',no-resolve', '');
|
|||||||
/**
|
/**
|
||||||
* This only generates a simplified version, for under-used users only.
|
* This only generates a simplified version, for under-used users only.
|
||||||
*/
|
*/
|
||||||
export const buildSSPanelUIMAppProfile = task(import.meta.path, async (span) => {
|
export const buildSSPanelUIMAppProfile = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const [
|
const [
|
||||||
domesticDomains,
|
domesticDomains,
|
||||||
appleCdnDomains,
|
appleCdnDomains,
|
||||||
@ -115,10 +115,6 @@ export const buildSSPanelUIMAppProfile = task(import.meta.path, async (span) =>
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildSSPanelUIMAppProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
|
const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
|
||||||
|
|
||||||
function generateAppProfile(
|
function generateAppProfile(
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export const createRulesetForStreamService = (span: Span, fileId: string, title:
|
|||||||
]));
|
]));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buildStreamService = task(import.meta.path, async (span) => {
|
export const buildStreamService = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
createRulesetForStreamService(span, 'stream', 'All', ALL),
|
createRulesetForStreamService(span, 'stream', 'All', ALL),
|
||||||
createRulesetForStreamService(span, 'stream_us', 'North America', NORTH_AMERICA),
|
createRulesetForStreamService(span, 'stream_us', 'North America', NORTH_AMERICA),
|
||||||
@ -63,7 +63,3 @@ export const buildStreamService = task(import.meta.path, async (span) => {
|
|||||||
// createRulesetForStreamService('stream_south_east_asia', 'South East Asia', SOUTH_EAST_ASIA)
|
// createRulesetForStreamService('stream_south_east_asia', 'South East Asia', SOUTH_EAST_ASIA)
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildStreamService();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ export const getTelegramCIDRPromise = createMemoizedPromise(async () => {
|
|||||||
return { date, results };
|
return { date, results };
|
||||||
});
|
});
|
||||||
|
|
||||||
export const buildTelegramCIDR = task(import.meta.path, async (span) => {
|
export const buildTelegramCIDR = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const { date, results } = await span.traceChildAsync('get telegram cidr', getTelegramCIDRPromise);
|
const { date, results } = await span.traceChildAsync('get telegram cidr', getTelegramCIDRPromise);
|
||||||
|
|
||||||
if (results.length === 0) {
|
if (results.length === 0) {
|
||||||
@ -56,7 +56,3 @@ export const buildTelegramCIDR = task(import.meta.path, async (span) => {
|
|||||||
path.resolve(import.meta.dir, '../Clash/ip/telegram.txt')
|
path.resolve(import.meta.dir, '../Clash/ip/telegram.txt')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildTelegramCIDR();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -12,12 +12,8 @@ const ASSETS_LIST = {
|
|||||||
|
|
||||||
const mockDir = path.resolve(import.meta.dir, '../Mock');
|
const mockDir = path.resolve(import.meta.dir, '../Mock');
|
||||||
|
|
||||||
export const downloadMockAssets = task(import.meta.path, (span) => Promise.all(Object.entries(ASSETS_LIST).map(
|
export const downloadMockAssets = task(import.meta.main, import.meta.path)((span) => Promise.all(Object.entries(ASSETS_LIST).map(
|
||||||
([filename, url]) => span
|
([filename, url]) => span
|
||||||
.traceChild(url)
|
.traceChild(url)
|
||||||
.traceAsyncFn(() => fetchWithRetry(url).then(res => Bun.write(path.join(mockDir, filename), res)))
|
.traceAsyncFn(() => fetchWithRetry(url).then(res => Bun.write(path.join(mockDir, filename), res)))
|
||||||
)));
|
)));
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
downloadMockAssets();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import { Readable } from 'stream';
|
|||||||
const IS_READING_BUILD_OUTPUT = 1 << 2;
|
const IS_READING_BUILD_OUTPUT = 1 << 2;
|
||||||
const ALL_FILES_EXISTS = 1 << 3;
|
const ALL_FILES_EXISTS = 1 << 3;
|
||||||
|
|
||||||
export const downloadPreviousBuild = task(import.meta.path, async (span) => {
|
export const downloadPreviousBuild = task(import.meta.main, import.meta.path)(async (span) => {
|
||||||
const buildOutputList: string[] = [];
|
const buildOutputList: string[] = [];
|
||||||
|
|
||||||
let flag = 1 | ALL_FILES_EXISTS;
|
let flag = 1 | ALL_FILES_EXISTS;
|
||||||
@ -91,7 +91,3 @@ export const downloadPreviousBuild = task(import.meta.path, async (span) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
downloadPreviousBuild();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ export interface Span {
|
|||||||
readonly traceAsyncFn: <T>(fn: (span: Span) => T | Promise<T>) => Promise<T>,
|
readonly traceAsyncFn: <T>(fn: (span: Span) => T | Promise<T>) => Promise<T>,
|
||||||
readonly tracePromise: <T>(promise: Promise<T>) => Promise<T>,
|
readonly tracePromise: <T>(promise: Promise<T>) => Promise<T>,
|
||||||
readonly traceChildSync: <T>(name: string, fn: (span: Span) => T) => T,
|
readonly traceChildSync: <T>(name: string, fn: (span: Span) => T) => T,
|
||||||
readonly traceChildAsync: <T>(name: string, fn: (span: Span) => T | Promise<T>) => Promise<T>,
|
readonly traceChildAsync: <T>(name: string, fn: (span: Span) => Promise<T>) => Promise<T>,
|
||||||
readonly traceChildPromise: <T>(name: string, promise: Promise<T>) => Promise<T>,
|
readonly traceChildPromise: <T>(name: string, promise: Promise<T>) => Promise<T>,
|
||||||
readonly traceResult: TraceResult
|
readonly traceResult: TraceResult
|
||||||
}
|
}
|
||||||
@ -85,9 +85,7 @@ export const createSpan = (name: string, parentTraceResult?: TraceResult): Span
|
|||||||
span.stop();
|
span.stop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get traceResult() {
|
traceResult: curTraceResult,
|
||||||
return curTraceResult;
|
|
||||||
},
|
|
||||||
async tracePromise<T>(promise: Promise<T>): Promise<T> {
|
async tracePromise<T>(promise: Promise<T>): Promise<T> {
|
||||||
try {
|
try {
|
||||||
return await promise;
|
return await promise;
|
||||||
@ -95,44 +93,44 @@ export const createSpan = (name: string, parentTraceResult?: TraceResult): Span
|
|||||||
span.stop();
|
span.stop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
traceChildSync<T>(name: string, fn: (span: Span) => T): T {
|
traceChildSync: <T>(name: string, fn: (span: Span) => T): T => traceChild(name).traceSyncFn(fn),
|
||||||
return traceChild(name).traceSyncFn(fn);
|
traceChildAsync: <T>(name: string, fn: (span: Span) => T | Promise<T>): Promise<T> => traceChild(name).traceAsyncFn(fn),
|
||||||
},
|
traceChildPromise: <T>(name: string, promise: Promise<T>): Promise<T> => traceChild(name).tracePromise(promise)
|
||||||
traceChildAsync<T>(name: string, fn: (span: Span) => T | Promise<T>): Promise<T> {
|
|
||||||
return traceChild(name).traceAsyncFn(fn);
|
|
||||||
},
|
|
||||||
traceChildPromise<T>(name: string, promise: Promise<T>): Promise<T> {
|
|
||||||
return traceChild(name).tracePromise(promise);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line sukka/no-redundant-variable -- self reference
|
// eslint-disable-next-line sukka/no-redundant-variable -- self reference
|
||||||
return span;
|
return span;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const task = <T>(importMetaPath: string, fn: (span: Span) => T, customname?: string) => {
|
export const task = (importMetaMain: boolean, importMetaPath: string) => <T>(fn: (span: Span) => Promise<T>, customName?: string) => {
|
||||||
const taskName = customname ?? path.basename(importMetaPath, path.extname(importMetaPath));
|
const taskName = customName ?? path.basename(importMetaPath, path.extname(importMetaPath));
|
||||||
|
|
||||||
|
const dummySpan = createSpan(taskName);
|
||||||
|
|
||||||
|
if (importMetaMain) {
|
||||||
|
fn(dummySpan);
|
||||||
|
}
|
||||||
|
|
||||||
return async (span?: Span) => {
|
return async (span?: Span) => {
|
||||||
if (span) {
|
if (span) {
|
||||||
return span.traceChildAsync(taskName, fn);
|
return span.traceChildAsync(taskName, fn);
|
||||||
}
|
}
|
||||||
return fn(createSpan(taskName));
|
return fn(dummySpan);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const isSpan = (obj: any): obj is Span => {
|
// const isSpan = (obj: any): obj is Span => {
|
||||||
return typeof obj === 'object' && obj && spanTag in obj;
|
// return typeof obj === 'object' && obj && spanTag in obj;
|
||||||
};
|
// };
|
||||||
|
// export const universalify = <A extends any[], R>(taskname: string, fn: (this: void, ...args: A) => R) => {
|
||||||
export const universalify = <A extends any[], R>(taskname: string, fn: (this: void, ...args: A) => R) => {
|
// return (...args: A) => {
|
||||||
return (...args: A) => {
|
// const lastArg = args[args.length - 1];
|
||||||
const lastArg = args[args.length - 1];
|
// if (isSpan(lastArg)) {
|
||||||
if (isSpan(lastArg)) {
|
// return lastArg.traceChild(taskname).traceSyncFn(() => fn(...args));
|
||||||
return lastArg.traceChild(taskname).traceSyncFn(() => fn(...args));
|
// }
|
||||||
}
|
// return fn(...args);
|
||||||
return fn(...args);
|
// };
|
||||||
};
|
// };
|
||||||
};
|
|
||||||
|
|
||||||
export const printTraceResult = (traceResult: TraceResult = rootTraceResult) => {
|
export const printTraceResult = (traceResult: TraceResult = rootTraceResult) => {
|
||||||
printStats(traceResult.children);
|
printStats(traceResult.children);
|
||||||
@ -140,8 +138,7 @@ export const printTraceResult = (traceResult: TraceResult = rootTraceResult) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
function printTree(initialTree: TraceResult, printNode: (node: TraceResult, branch: string) => string) {
|
function printTree(initialTree: TraceResult, printNode: (node: TraceResult, branch: string) => string) {
|
||||||
function printBranch(tree: TraceResult, branch: string) {
|
function printBranch(tree: TraceResult, branch: string, isGraphHead: boolean, isChildOfLastBranch: boolean) {
|
||||||
const isGraphHead = branch.length === 0;
|
|
||||||
const children = tree.children;
|
const children = tree.children;
|
||||||
|
|
||||||
let branchHead = '';
|
let branchHead = '';
|
||||||
@ -159,7 +156,6 @@ function printTree(initialTree: TraceResult, printNode: (node: TraceResult, bran
|
|||||||
let baseBranch = branch;
|
let baseBranch = branch;
|
||||||
|
|
||||||
if (!isGraphHead) {
|
if (!isGraphHead) {
|
||||||
const isChildOfLastBranch = branch.endsWith('└─');
|
|
||||||
baseBranch = branch.slice(0, -2) + (isChildOfLastBranch ? ' ' : '│ ');
|
baseBranch = branch.slice(0, -2) + (isChildOfLastBranch ? ' ' : '│ ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,11 +163,12 @@ function printTree(initialTree: TraceResult, printNode: (node: TraceResult, bran
|
|||||||
const lastBranch = `${baseBranch}└─`;
|
const lastBranch = `${baseBranch}└─`;
|
||||||
|
|
||||||
children.forEach((child, index) => {
|
children.forEach((child, index) => {
|
||||||
printBranch(child, children.length - 1 === index ? lastBranch : nextBranch);
|
const last = children.length - 1 === index;
|
||||||
|
printBranch(child, last ? lastBranch : nextBranch, false, last);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
printBranch(initialTree, '');
|
printBranch(initialTree, '', true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function printStats(stats: TraceResult[]): void {
|
function printStats(stats: TraceResult[]): void {
|
||||||
|
|||||||
@ -67,7 +67,3 @@ export const parseDomesticList = async () => {
|
|||||||
|
|
||||||
console.log(notIncludedDomestic.size, notIncludedDomestic);
|
console.log(notIncludedDomestic.size, notIncludedDomestic);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
parseDomesticList();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -119,7 +119,3 @@ export const parseGfwList = async () => {
|
|||||||
top500Gfwed
|
top500Gfwed
|
||||||
] as const;
|
] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
parseGfwList();
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user