Chore: remove unused files

This commit is contained in:
SukkaW 2024-09-06 00:36:01 +08:00
parent 48e8808511
commit 32a5276ddb
2 changed files with 32 additions and 8 deletions

View File

@ -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,

View File

@ -1,3 +1,4 @@
# $ custom_no_output
# $ custom_build_script -- will be included in download.conf
# Steam