mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Chore: adjust stdout style
This commit is contained in:
parent
91df00f7f3
commit
1f2e2a655c
@ -1,8 +1,8 @@
|
||||
import path from 'path';
|
||||
import fsp from 'fs/promises';
|
||||
import { task } from './lib/trace-runner';
|
||||
import { listDir } from './lib/list-dir';
|
||||
import type { TreeType, TreeTypeArray } from './lib/list-dir';
|
||||
import { treeDir } from './lib/tree-dir';
|
||||
import type { TreeType, TreeTypeArray } from './lib/tree-dir';
|
||||
|
||||
const rootPath = path.resolve(import.meta.dir, '../');
|
||||
const publicPath = path.resolve(import.meta.dir, '../public');
|
||||
@ -24,9 +24,7 @@ export const buildPublic = task(import.meta.path, async () => {
|
||||
{ force: true, recursive: true }
|
||||
)));
|
||||
|
||||
const tree = await listDir(publicPath);
|
||||
|
||||
const html = generateHtml(tree);
|
||||
const html = generateHtml(await treeDir(publicPath));
|
||||
|
||||
return Bun.write(path.join(publicPath, 'index.html'), html);
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ import { processLine } from './process-line';
|
||||
import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
|
||||
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
|
||||
|
||||
import { traceAsync, traceSync } from './trace-runner';
|
||||
import { traceAsync } from './trace-runner';
|
||||
import picocolors from 'picocolors';
|
||||
import { normalizeDomain } from './normalize-domain';
|
||||
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
|
||||
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) {
|
||||
return traceAsync(`- processDomainLists: ${domainListsUrl}`, async () => {
|
||||
const domainSets = new Set<string>();
|
||||
@ -32,7 +22,7 @@ export function processDomainLists(domainListsUrl: string, includeAllSubDomain =
|
||||
if (!domainToAdd) continue;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -60,7 +50,7 @@ export function processHosts(hostsUrl: string, includeAllSubDomain = false, skip
|
||||
const _domain = domain.trim();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -111,7 +101,13 @@ export async function processFilterRules(
|
||||
|
||||
if (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;
|
||||
}
|
||||
}
|
||||
@ -585,7 +581,6 @@ function parse($line: string, gorhill: PublicSuffixList): null | [hostname: stri
|
||||
*/
|
||||
if (!suffix || !gorhill.suffixInPSL(suffix)) {
|
||||
// This exclude domain-like resource like `.gatracking.js`, `.beacon.min.js` and `.cookielaw.js`
|
||||
console.log({ line, suffix });
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ export type TreeTypeArray = TreeType[];
|
||||
|
||||
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 tree: TreeTypeArray = [];
|
||||
Loading…
x
Reference in New Issue
Block a user