diff --git a/Build/build-apple-cdn.ts b/Build/build-apple-cdn.ts index 5ae8eb0b..edb022da 100644 --- a/Build/build-apple-cdn.ts +++ b/Build/build-apple-cdn.ts @@ -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, diff --git a/Build/build-chn-cidr.ts b/Build/build-chn-cidr.ts index 5c938766..487a2e75 100644 --- a/Build/build-chn-cidr.ts +++ b/Build/build-chn-cidr.ts @@ -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 = [ diff --git a/Build/lib/create-file.ts b/Build/lib/create-file.ts index c294ca53..31468d61 100644 --- a/Build/lib/create-file.ts +++ b/Build/lib/create-file.ts @@ -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) {