Chore: adjust stdout style

This commit is contained in:
SukkaW 2023-12-18 00:40:49 +08:00
parent 91df00f7f3
commit 1f2e2a655c
3 changed files with 14 additions and 21 deletions

View File

@ -1,8 +1,8 @@
import path from 'path'; import path from 'path';
import fsp from 'fs/promises'; import fsp from 'fs/promises';
import { task } from './lib/trace-runner'; import { task } from './lib/trace-runner';
import { listDir } from './lib/list-dir'; import { treeDir } from './lib/tree-dir';
import type { TreeType, TreeTypeArray } from './lib/list-dir'; import type { TreeType, TreeTypeArray } from './lib/tree-dir';
const rootPath = path.resolve(import.meta.dir, '../'); const rootPath = path.resolve(import.meta.dir, '../');
const publicPath = path.resolve(import.meta.dir, '../public'); const publicPath = path.resolve(import.meta.dir, '../public');
@ -24,9 +24,7 @@ export const buildPublic = task(import.meta.path, async () => {
{ force: true, recursive: true } { force: true, recursive: true }
))); )));
const tree = await listDir(publicPath); const html = generateHtml(await treeDir(publicPath));
const html = generateHtml(tree);
return Bun.write(path.join(publicPath, 'index.html'), html); return Bun.write(path.join(publicPath, 'index.html'), html);
}); });

View File

@ -5,7 +5,7 @@ import { processLine } from './process-line';
import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix'; import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
import type { PublicSuffixList } from '@gorhill/publicsuffixlist'; import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
import { traceAsync, traceSync } from './trace-runner'; import { traceAsync } from './trace-runner';
import picocolors from 'picocolors'; import picocolors from 'picocolors';
import { normalizeDomain } from './normalize-domain'; import { normalizeDomain } from './normalize-domain';
import { fetchAssets } from './fetch-assets'; import { fetchAssets } from './fetch-assets';
@ -13,16 +13,6 @@ import { fetchAssets } from './fetch-assets';
const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null
let foundDebugDomain = false; let foundDebugDomain = false;
const warnOnceUrl = new Set<string>();
const warnOnce = (url: string, isWhite: boolean, ...message: string[]) => {
const key = `${url}${isWhite ? 'white' : 'black'}`;
if (warnOnceUrl.has(key)) {
return;
}
warnOnceUrl.add(key);
console.warn(url, isWhite ? '(white)' : '(black)', ...message);
};
export function processDomainLists(domainListsUrl: string, includeAllSubDomain = false) { export function processDomainLists(domainListsUrl: string, includeAllSubDomain = false) {
return traceAsync(`- processDomainLists: ${domainListsUrl}`, async () => { return traceAsync(`- processDomainLists: ${domainListsUrl}`, async () => {
const domainSets = new Set<string>(); const domainSets = new Set<string>();
@ -32,7 +22,7 @@ export function processDomainLists(domainListsUrl: string, includeAllSubDomain =
if (!domainToAdd) continue; if (!domainToAdd) continue;
if (DEBUG_DOMAIN_TO_FIND && domainToAdd.includes(DEBUG_DOMAIN_TO_FIND)) { if (DEBUG_DOMAIN_TO_FIND && domainToAdd.includes(DEBUG_DOMAIN_TO_FIND)) {
warnOnce(domainListsUrl, false, DEBUG_DOMAIN_TO_FIND); console.warn(picocolors.red(domainListsUrl), '(black)', picocolors.bold(DEBUG_DOMAIN_TO_FIND));
foundDebugDomain = true; foundDebugDomain = true;
} }
@ -60,7 +50,7 @@ export function processHosts(hostsUrl: string, includeAllSubDomain = false, skip
const _domain = domain.trim(); const _domain = domain.trim();
if (DEBUG_DOMAIN_TO_FIND && _domain.includes(DEBUG_DOMAIN_TO_FIND)) { if (DEBUG_DOMAIN_TO_FIND && _domain.includes(DEBUG_DOMAIN_TO_FIND)) {
warnOnce(hostsUrl, false, DEBUG_DOMAIN_TO_FIND); console.warn(picocolors.red(hostsUrl), '(black)', picocolors.bold(DEBUG_DOMAIN_TO_FIND));
foundDebugDomain = true; foundDebugDomain = true;
} }
@ -111,7 +101,13 @@ export async function processFilterRules(
if (DEBUG_DOMAIN_TO_FIND) { if (DEBUG_DOMAIN_TO_FIND) {
if (hostname.includes(DEBUG_DOMAIN_TO_FIND)) { if (hostname.includes(DEBUG_DOMAIN_TO_FIND)) {
warnOnce(filterRulesUrl, flag === ParseType.WhiteIncludeSubdomain || flag === ParseType.WhiteAbsolute, DEBUG_DOMAIN_TO_FIND); console.warn(
picocolors.red(filterRulesUrl),
flag === ParseType.WhiteIncludeSubdomain || flag === ParseType.WhiteAbsolute
? '(white)'
: '(black)',
picocolors.bold(DEBUG_DOMAIN_TO_FIND)
);
foundDebugDomain = true; foundDebugDomain = true;
} }
} }
@ -585,7 +581,6 @@ function parse($line: string, gorhill: PublicSuffixList): null | [hostname: stri
*/ */
if (!suffix || !gorhill.suffixInPSL(suffix)) { if (!suffix || !gorhill.suffixInPSL(suffix)) {
// This exclude domain-like resource like `.gatracking.js`, `.beacon.min.js` and `.cookielaw.js` // This exclude domain-like resource like `.gatracking.js`, `.beacon.min.js` and `.cookielaw.js`
console.log({ line, suffix });
return null; return null;
} }

View File

@ -19,7 +19,7 @@ export type TreeTypeArray = TreeType[];
type VoidOrVoidArray = void | VoidOrVoidArray[]; type VoidOrVoidArray = void | VoidOrVoidArray[];
export const listDir = async (path: string): Promise<TreeTypeArray> => { export const treeDir = async (path: string): Promise<TreeTypeArray> => {
const pw = new PathScurry(path); const pw = new PathScurry(path);
const tree: TreeTypeArray = []; const tree: TreeTypeArray = [];