Support Clash Fake IP Filter Ruleset

This commit is contained in:
SukkaW
2024-10-16 14:36:59 +08:00
parent 973d2ce3d1
commit a5a3e061f6
6 changed files with 159 additions and 108 deletions

View File

@@ -65,10 +65,7 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
return result;
};
constructor(
protected readonly span: Span,
protected readonly id: string
) { }
constructor(protected readonly span: Span, protected readonly id: string) { }
protected title: string | null = null;
withTitle(title: string) {
@@ -245,7 +242,6 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
}
private $$preprocessed: TPreprocessed | null = null;
get $preprocessed() {
if (this.$$preprocessed === null) {
this.$$preprocessed = this.span.traceChildSync('RuleOutput#preprocess: ' + this.id, () => this.preprocess());
@@ -253,6 +249,24 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
return this.$$preprocessed;
}
async writeClash(outputDir?: null | string) {
await this.done();
invariant(this.title, 'Missing title');
invariant(this.description, 'Missing description');
return compareAndWriteFile(
this.span,
withBannerArray(
this.title,
this.description,
this.date,
this.clash()
),
path.join(outputDir ?? OUTPUT_CLASH_DIR, this.type, this.id + '.txt')
);
}
async write(): Promise<void> {
await this.done();