mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Chore: detail logging of time consumption
This commit is contained in:
parent
a8e09e24de
commit
dec8952226
@ -2,11 +2,16 @@
|
||||
import path from 'path';
|
||||
import { createRuleset } from './lib/create-file';
|
||||
import { parseFelixDnsmasq } from './lib/parse-dnsmasq';
|
||||
import { task } from './lib/trace-runner';
|
||||
import { task, traceAsync } from './lib/trace-runner';
|
||||
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||
import picocolors from 'picocolors';
|
||||
|
||||
export const buildAppleCdn = task(import.meta.path, async () => {
|
||||
const res = await parseFelixDnsmasq('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf');
|
||||
const res = await traceAsync(
|
||||
picocolors.gray('download dnsmasq-china-list apple.china.conf'),
|
||||
() => parseFelixDnsmasq('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf'),
|
||||
picocolors.gray
|
||||
);
|
||||
|
||||
const description = [
|
||||
...SHARED_DESCRIPTION,
|
||||
|
||||
@ -2,9 +2,10 @@ import { fetchRemoteTextAndReadByLine } from './lib/fetch-text-by-line';
|
||||
import { resolve as pathResolve } from 'path';
|
||||
import { compareAndWriteFile, withBannerArray } from './lib/create-file';
|
||||
import { processLineFromReadline } from './lib/process-line';
|
||||
import { task } from './lib/trace-runner';
|
||||
import { task, traceAsync, traceSync } from './lib/trace-runner';
|
||||
|
||||
import { exclude } from 'fast-cidr-tools';
|
||||
import picocolors from 'picocolors';
|
||||
|
||||
// https://github.com/misakaio/chnroutes2/issues/25
|
||||
const EXCLUDE_CIDRS = [
|
||||
@ -17,8 +18,16 @@ const INCLUDE_CIDRS = [
|
||||
];
|
||||
|
||||
export const buildChnCidr = task(import.meta.path, async () => {
|
||||
const cidr = await processLineFromReadline(await fetchRemoteTextAndReadByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt'));
|
||||
const filteredCidr = exclude([...cidr, ...INCLUDE_CIDRS], EXCLUDE_CIDRS, true);
|
||||
const cidr = await traceAsync(
|
||||
picocolors.gray('download chnroutes2'),
|
||||
async () => processLineFromReadline(await fetchRemoteTextAndReadByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt')),
|
||||
picocolors.gray
|
||||
);
|
||||
const filteredCidr = traceSync(
|
||||
picocolors.gray('processing chnroutes2'),
|
||||
() => exclude([...cidr, ...INCLUDE_CIDRS], EXCLUDE_CIDRS, true),
|
||||
picocolors.gray
|
||||
);
|
||||
|
||||
// Can not use SHARED_DESCRIPTION here as different license
|
||||
const description = [
|
||||
|
||||
@ -17,32 +17,38 @@ export async function compareAndWriteFile(linesA: string[], filePath: string) {
|
||||
console.log(`Nothing to write to ${filePath}...`);
|
||||
isEqual = false;
|
||||
} else {
|
||||
let index = 0;
|
||||
isEqual = await traceAsync(
|
||||
picocolors.gray(`Comparing ${filePath}`),
|
||||
async () => {
|
||||
let index = 0;
|
||||
|
||||
for await (const lineB of readFileByLine(file)) {
|
||||
const lineA = linesA[index];
|
||||
index++;
|
||||
for await (const lineB of readFileByLine(file)) {
|
||||
const lineA = linesA[index];
|
||||
index++;
|
||||
|
||||
if (lineA == null) {
|
||||
// The file becomes smaller
|
||||
isEqual = false;
|
||||
break;
|
||||
}
|
||||
if (lineA == null) {
|
||||
// The file becomes smaller
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lineA[0] === '#' && lineB[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
if (lineA[0] === '#' && lineB[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lineA !== lineB) {
|
||||
isEqual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lineA !== lineB) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isEqual && index !== linesALen) {
|
||||
// The file becomes larger
|
||||
isEqual = false;
|
||||
}
|
||||
if (index !== linesALen) {
|
||||
// The file becomes larger
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
picocolors.gray
|
||||
);
|
||||
}
|
||||
|
||||
if (isEqual) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user