Refactor: adjust write strategy usage

This commit is contained in:
SukkaW
2025-01-29 21:24:00 +08:00
parent 956d98d7dc
commit f9163db26c
9 changed files with 365 additions and 209 deletions

View File

@@ -57,7 +57,7 @@ export class FileOutput {
return this;
}
replaceStrategies(strategies: Array<BaseWriteStrategy | false>) {
public withStrategies(strategies: Array<BaseWriteStrategy | false>) {
this.strategies = strategies;
return this;
}
@@ -444,7 +444,7 @@ export class FileOutput {
});
}
async output(): Promise<Array<string[] | null>> {
async compile(): Promise<Array<string[] | null>> {
await this.writeToStrategies();
return this.strategies.reduce<Array<string[] | null>>((acc, strategy) => {

View File

@@ -1,3 +1,5 @@
import type { Span } from '../../trace';
import { AdGuardHome } from '../writing-strategy/adguardhome';
import type { BaseWriteStrategy } from '../writing-strategy/base';
import { ClashDomainSet } from '../writing-strategy/clash';
import { SingboxSource } from '../writing-strategy/singbox';
@@ -13,3 +15,19 @@ export class DomainsetOutput extends FileOutput {
new SingboxSource(this.type)
];
}
export class AdGuardHomeOutput extends FileOutput {
strategies: Array<false | BaseWriteStrategy>;
constructor(
span: Span,
id: string,
outputDir: string
) {
super(span, id);
this.strategies = [
new AdGuardHome(outputDir)
];
}
}

View File

@@ -15,3 +15,32 @@ export class RulesetOutput extends FileOutput {
];
}
}
export class SurgeOnlyRulesetOutput extends FileOutput {
constructor(
span: Span,
id: string,
protected type: 'non_ip' | 'ip' | (string & {}),
overrideOutputDir?: string
) {
super(span, id);
this.strategies = [
new SurgeRuleSet(this.type, overrideOutputDir)
];
}
}
export class ClashOnlyRulesetOutput extends FileOutput {
constructor(
span: Span,
id: string,
protected type: 'non_ip' | 'ip' | (string & {})
) {
super(span, id);
this.strategies = [
new ClashClassicRuleSet(this.type)
];
}
}