Chore: refactor output dir

This commit is contained in:
SukkaW
2024-09-06 19:49:17 +08:00
parent 5bc2e017df
commit 315b38b999
19 changed files with 117 additions and 172 deletions

View File

@@ -11,17 +11,13 @@ import { SHARED_DESCRIPTION } from './lib/constants';
import { fdir as Fdir } from 'fdir';
import { appendArrayInPlace } from './lib/append-array-in-place';
import { removeFiles } from './lib/misc';
import { OUTPUT_CLASH_DIR, OUTPUT_SINGBOX_DIR, OUTPUT_SURGE_DIR, SOURCE_DIR } from './constants/dir';
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 ';
const sourceDir = path.resolve(__dirname, '../Source');
const outputSurgeDir = path.resolve(__dirname, '../List');
const outputClashDir = path.resolve(__dirname, '../Clash');
const outputSingboxDir = path.resolve(__dirname, '../sing-box');
const domainsetSrcFolder = 'domainset' + path.sep;
export const buildCommon = task(require.main === module, __filename)(async (span) => {
@@ -46,12 +42,12 @@ export const buildCommon = task(require.main === module, __filename)(async (span
return true;
})
.crawl(sourceDir)
.crawl(SOURCE_DIR)
.withPromise();
for (let i = 0, len = paths.length; i < len; i++) {
const relativePath = paths[i];
const fullPath = sourceDir + path.sep + relativePath;
const fullPath = SOURCE_DIR + path.sep + relativePath;
if (relativePath.startsWith(domainsetSrcFolder)) {
promises.push(transformDomainset(span, fullPath, relativePath));
@@ -127,9 +123,9 @@ function transformDomainset(parentSpan: Span, sourcePath: string, relativePath:
if (res === $rm) {
return removeFiles([
path.resolve(outputSurgeDir, relativePath),
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
path.resolve(OUTPUT_SURGE_DIR, relativePath),
path.resolve(OUTPUT_CLASH_DIR, `${clashFileBasename}.txt`),
path.resolve(OUTPUT_SINGBOX_DIR, `${clashFileBasename}.json`)
]);
}
@@ -153,9 +149,9 @@ function transformDomainset(parentSpan: Span, sourcePath: string, relativePath:
deduped,
'domainset',
[
path.resolve(outputSurgeDir, relativePath),
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
path.resolve(OUTPUT_SURGE_DIR, relativePath),
path.resolve(OUTPUT_CLASH_DIR, `${clashFileBasename}.txt`),
path.resolve(OUTPUT_SINGBOX_DIR, `${clashFileBasename}.json`)
]
);
}
@@ -176,9 +172,9 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa
if (res === $rm) {
return removeFiles([
path.resolve(outputSurgeDir, relativePath),
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
path.resolve(OUTPUT_SURGE_DIR, relativePath),
path.resolve(OUTPUT_CLASH_DIR, `${clashFileBasename}.txt`),
path.resolve(OUTPUT_SINGBOX_DIR, `${clashFileBasename}.json`)
]);
}
@@ -201,9 +197,9 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa
lines,
'ruleset',
[
path.resolve(outputSurgeDir, relativePath),
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
path.resolve(OUTPUT_SURGE_DIR, relativePath),
path.resolve(OUTPUT_CLASH_DIR, `${clashFileBasename}.txt`),
path.resolve(OUTPUT_SINGBOX_DIR, `${clashFileBasename}.json`)
]
);
});