From 32a5276ddbe6c6b6369272eea39f58bf778f3b49 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 6 Sep 2024 00:36:01 +0800 Subject: [PATCH] Chore: remove unused files --- Build/build-common.ts | 39 +++++++++++++++++++++++++++++-------- Source/domainset/steam.conf | 1 + 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Build/build-common.ts b/Build/build-common.ts index 4780e16b..cd485a6d 100644 --- a/Build/build-common.ts +++ b/Build/build-common.ts @@ -1,6 +1,7 @@ // @ts-check import * as path from 'node:path'; +import fsp from 'node:fs/promises'; import { readFileByLine } from './lib/fetch-text-by-line'; import { processLine } from './lib/process-line'; import { createRuleset } from './lib/create-file'; @@ -12,6 +13,7 @@ import { fdir as Fdir } from 'fdir'; import { appendArrayInPlace } from './lib/append-array-in-place'; const MAGIC_COMMAND_SKIP = '# $ custom_build_script'; +const MAGIC_COMMAND_RM = '# $ custom_no_output'; const MAGIC_COMMAND_TITLE = '# $ meta_title '; const MAGIC_COMMAND_DESCRIPTION = '# $ meta_description '; @@ -69,6 +71,9 @@ export const buildCommon = task(require.main === module, __filename)(async (span return Promise.all(promises); }); +const $skip = Symbol('skip'); +const $rm = Symbol('rm'); + const processFile = (span: Span, sourcePath: string) => { // console.log('Processing', sourcePath); return span.traceChildAsync(`process file: ${sourcePath}`, async () => { @@ -79,8 +84,11 @@ const processFile = (span: Span, sourcePath: string) => { try { for await (const line of readFileByLine(sourcePath)) { + if (line.startsWith(MAGIC_COMMAND_RM)) { + return $rm; + } if (line.startsWith(MAGIC_COMMAND_SKIP)) { - return null; + return $skip; } 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))}`, async (span) => { 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 deduped = domainDeduper(lines); let description: string[]; @@ -128,8 +145,6 @@ function transformDomainset(parentSpan: Span, sourcePath: string, relativePath: description = SHARED_DESCRIPTION; } - const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length); - return createRuleset( span, title, @@ -155,7 +170,17 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa .traceChild(`transform ruleset: ${path.basename(sourcePath, path.extname(sourcePath))}`) .traceAsyncFn(async (span) => { 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; @@ -168,8 +193,6 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa description = SHARED_DESCRIPTION; } - const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length); - return createRuleset( span, title, diff --git a/Source/domainset/steam.conf b/Source/domainset/steam.conf index d815df5f..05dfd700 100644 --- a/Source/domainset/steam.conf +++ b/Source/domainset/steam.conf @@ -1,3 +1,4 @@ +# $ custom_no_output # $ custom_build_script -- will be included in download.conf # Steam