Perf: use fdir for crawling

This commit is contained in:
SukkaW 2024-06-01 18:26:34 +08:00
parent a6e421be42
commit b820b4be1c
3 changed files with 13 additions and 10 deletions

View File

@ -1,7 +1,6 @@
// @ts-check
import * as path from 'path';
import { PathScurry } from 'path-scurry';
import { readFileByLine } from './lib/fetch-text-by-line';
import { processLine } from './lib/process-line';
import { createRuleset } from './lib/create-file';
@ -10,6 +9,7 @@ import type { Span } from './trace';
import { task } from './trace';
import { SHARED_DESCRIPTION } from './lib/constants';
import picocolors from 'picocolors';
import { fdir as Fdir } from 'fdir';
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
const MAGIC_COMMAND_TITLE = '# $ meta_title ';
@ -22,27 +22,29 @@ const outputClashDir = path.resolve(import.meta.dir, '../Clash');
export const buildCommon = task(import.meta.path, async (span) => {
const promises: Array<Promise<unknown>> = [];
const pw = new PathScurry(sourceDir);
for await (const entry of pw) {
if (!entry.isFile()) {
continue;
}
const paths = await new Fdir()
.withRelativePaths()
.crawl(sourceDir)
.withPromise();
const extname = path.extname(entry.name);
for (let i = 0, len = paths.length; i < len; i++) {
const relativePath = paths[i];
const extname = path.extname(relativePath);
if (extname === '.js' || extname === '.ts') {
continue;
}
const fullPath = sourceDir + path.sep + relativePath;
const relativePath = entry.relative();
if (relativePath.startsWith('domainset/')) {
promises.push(transformDomainset(span, entry.fullpath(), relativePath));
promises.push(transformDomainset(span, fullPath, relativePath));
continue;
}
if (
relativePath.startsWith('ip/')
|| relativePath.startsWith('non_ip/')
) {
promises.push(transformRuleset(span, entry.fullpath(), relativePath));
promises.push(transformRuleset(span, fullPath, relativePath));
continue;
}

BIN
bun.lockb

Binary file not shown.

View File

@ -23,6 +23,7 @@
"ci-info": "^4.0.0",
"csv-parse": "^5.5.6",
"fast-cidr-tools": "^0.2.5",
"fdir": "^6.1.1",
"mnemonist": "^0.39.8",
"path-scurry": "^1.11.1",
"picocolors": "^1.0.1",