mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Chore: refactor output dir
This commit is contained in:
@@ -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`)
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user