mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 01:30:37 +08:00
Chore: remove unused files
This commit is contained in:
parent
48e8808511
commit
32a5276ddb
@ -1,6 +1,7 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
|
import fsp from 'node:fs/promises';
|
||||||
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';
|
||||||
@ -12,6 +13,7 @@ import { fdir as Fdir } from 'fdir';
|
|||||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||||
|
|
||||||
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
|
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
|
||||||
|
const MAGIC_COMMAND_RM = '# $ custom_no_output';
|
||||||
const MAGIC_COMMAND_TITLE = '# $ meta_title ';
|
const MAGIC_COMMAND_TITLE = '# $ meta_title ';
|
||||||
const MAGIC_COMMAND_DESCRIPTION = '# $ meta_description ';
|
const MAGIC_COMMAND_DESCRIPTION = '# $ meta_description ';
|
||||||
|
|
||||||
@ -69,6 +71,9 @@ export const buildCommon = task(require.main === module, __filename)(async (span
|
|||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const $skip = Symbol('skip');
|
||||||
|
const $rm = Symbol('rm');
|
||||||
|
|
||||||
const processFile = (span: Span, sourcePath: string) => {
|
const processFile = (span: Span, sourcePath: string) => {
|
||||||
// console.log('Processing', sourcePath);
|
// console.log('Processing', sourcePath);
|
||||||
return span.traceChildAsync(`process file: ${sourcePath}`, async () => {
|
return span.traceChildAsync(`process file: ${sourcePath}`, async () => {
|
||||||
@ -79,8 +84,11 @@ const processFile = (span: Span, sourcePath: string) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for await (const line of readFileByLine(sourcePath)) {
|
for await (const line of readFileByLine(sourcePath)) {
|
||||||
|
if (line.startsWith(MAGIC_COMMAND_RM)) {
|
||||||
|
return $rm;
|
||||||
|
}
|
||||||
if (line.startsWith(MAGIC_COMMAND_SKIP)) {
|
if (line.startsWith(MAGIC_COMMAND_SKIP)) {
|
||||||
return null;
|
return $skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.startsWith(MAGIC_COMMAND_TITLE)) {
|
if (line.startsWith(MAGIC_COMMAND_TITLE)) {
|
||||||
@ -113,10 +121,19 @@ function transformDomainset(parentSpan: Span, sourcePath: string, relativePath:
|
|||||||
`transform domainset: ${path.basename(sourcePath, path.extname(sourcePath))}`,
|
`transform domainset: ${path.basename(sourcePath, path.extname(sourcePath))}`,
|
||||||
async (span) => {
|
async (span) => {
|
||||||
const res = await processFile(span, sourcePath);
|
const res = await processFile(span, sourcePath);
|
||||||
if (!res) return;
|
if (res === $skip) return;
|
||||||
|
|
||||||
|
const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length);
|
||||||
|
|
||||||
|
if (res === $rm) {
|
||||||
|
return Promise.all([
|
||||||
|
path.resolve(outputSurgeDir, relativePath),
|
||||||
|
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
|
||||||
|
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
|
||||||
|
].map(f => fsp.rm(f, { force: true })));
|
||||||
|
}
|
||||||
|
|
||||||
const [title, descriptions, lines] = res;
|
const [title, descriptions, lines] = res;
|
||||||
|
|
||||||
const deduped = domainDeduper(lines);
|
const deduped = domainDeduper(lines);
|
||||||
|
|
||||||
let description: string[];
|
let description: string[];
|
||||||
@ -128,8 +145,6 @@ function transformDomainset(parentSpan: Span, sourcePath: string, relativePath:
|
|||||||
description = SHARED_DESCRIPTION;
|
description = SHARED_DESCRIPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length);
|
|
||||||
|
|
||||||
return createRuleset(
|
return createRuleset(
|
||||||
span,
|
span,
|
||||||
title,
|
title,
|
||||||
@ -155,7 +170,17 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa
|
|||||||
.traceChild(`transform ruleset: ${path.basename(sourcePath, path.extname(sourcePath))}`)
|
.traceChild(`transform ruleset: ${path.basename(sourcePath, path.extname(sourcePath))}`)
|
||||||
.traceAsyncFn(async (span) => {
|
.traceAsyncFn(async (span) => {
|
||||||
const res = await processFile(span, sourcePath);
|
const res = await processFile(span, sourcePath);
|
||||||
if (!res) return null;
|
if (res === $skip) return;
|
||||||
|
|
||||||
|
const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length);
|
||||||
|
|
||||||
|
if (res === $rm) {
|
||||||
|
return Promise.all([
|
||||||
|
path.resolve(outputSurgeDir, relativePath),
|
||||||
|
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
|
||||||
|
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
|
||||||
|
].map(f => fsp.rm(f, { force: true })));
|
||||||
|
}
|
||||||
|
|
||||||
const [title, descriptions, lines] = res;
|
const [title, descriptions, lines] = res;
|
||||||
|
|
||||||
@ -168,8 +193,6 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa
|
|||||||
description = SHARED_DESCRIPTION;
|
description = SHARED_DESCRIPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length);
|
|
||||||
|
|
||||||
return createRuleset(
|
return createRuleset(
|
||||||
span,
|
span,
|
||||||
title,
|
title,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
# $ custom_no_output
|
||||||
# $ custom_build_script -- will be included in download.conf
|
# $ custom_build_script -- will be included in download.conf
|
||||||
|
|
||||||
# Steam
|
# Steam
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user