mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Perf: use fdir for crawling
This commit is contained in:
parent
a6e421be42
commit
b820b4be1c
@ -1,7 +1,6 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { PathScurry } from 'path-scurry';
|
|
||||||
import { readFileByLine } from './lib/fetch-text-by-line';
|
import { readFileByLine } from './lib/fetch-text-by-line';
|
||||||
import { processLine } from './lib/process-line';
|
import { processLine } from './lib/process-line';
|
||||||
import { createRuleset } from './lib/create-file';
|
import { createRuleset } from './lib/create-file';
|
||||||
@ -10,6 +9,7 @@ import type { Span } from './trace';
|
|||||||
import { task } from './trace';
|
import { task } from './trace';
|
||||||
import { SHARED_DESCRIPTION } from './lib/constants';
|
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||||
import picocolors from 'picocolors';
|
import picocolors from 'picocolors';
|
||||||
|
import { fdir as Fdir } from 'fdir';
|
||||||
|
|
||||||
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
|
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
|
||||||
const MAGIC_COMMAND_TITLE = '# $ meta_title ';
|
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) => {
|
export const buildCommon = task(import.meta.path, async (span) => {
|
||||||
const promises: Array<Promise<unknown>> = [];
|
const promises: Array<Promise<unknown>> = [];
|
||||||
|
|
||||||
const pw = new PathScurry(sourceDir);
|
const paths = await new Fdir()
|
||||||
for await (const entry of pw) {
|
.withRelativePaths()
|
||||||
if (!entry.isFile()) {
|
.crawl(sourceDir)
|
||||||
continue;
|
.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') {
|
if (extname === '.js' || extname === '.ts') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
const fullPath = sourceDir + path.sep + relativePath;
|
||||||
|
|
||||||
const relativePath = entry.relative();
|
|
||||||
if (relativePath.startsWith('domainset/')) {
|
if (relativePath.startsWith('domainset/')) {
|
||||||
promises.push(transformDomainset(span, entry.fullpath(), relativePath));
|
promises.push(transformDomainset(span, fullPath, relativePath));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
relativePath.startsWith('ip/')
|
relativePath.startsWith('ip/')
|
||||||
|| relativePath.startsWith('non_ip/')
|
|| relativePath.startsWith('non_ip/')
|
||||||
) {
|
) {
|
||||||
promises.push(transformRuleset(span, entry.fullpath(), relativePath));
|
promises.push(transformRuleset(span, fullPath, relativePath));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
"ci-info": "^4.0.0",
|
"ci-info": "^4.0.0",
|
||||||
"csv-parse": "^5.5.6",
|
"csv-parse": "^5.5.6",
|
||||||
"fast-cidr-tools": "^0.2.5",
|
"fast-cidr-tools": "^0.2.5",
|
||||||
|
"fdir": "^6.1.1",
|
||||||
"mnemonist": "^0.39.8",
|
"mnemonist": "^0.39.8",
|
||||||
"path-scurry": "^1.11.1",
|
"path-scurry": "^1.11.1",
|
||||||
"picocolors": "^1.0.1",
|
"picocolors": "^1.0.1",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user