Made base class for publishers

This commit is contained in:
Kir_Antipov 2021-09-24 14:53:46 +03:00
parent 27004e5242
commit 59eb2bc7e7
2 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,17 @@
enum PublisherTarget {
GitHub,
Modrinth,
CurseForge,
}
namespace PublisherTarget {
export function getValues(): PublisherTarget[] {
return <PublisherTarget[]>Object.values(PublisherTarget).filter(x => !isNaN(+x));
}
export function toString(target: PublisherTarget): string {
return PublisherTarget[target] || target.toString();
}
}
export default PublisherTarget;

View file

@ -0,0 +1,20 @@
import Logger from "../utils/logger";
import { getEmptyLogger } from "../utils/logger-utils";
import PublisherTarget from "./publisher-target";
export default abstract class Publisher<TOptions> {
protected readonly options: TOptions;
protected readonly logger: Logger;
public constructor(options: TOptions, logger?: Logger) {
if (!options || typeof options !== "object") {
throw new Error(`Expected options to be an object, got ${options ? typeof options : options}`);
}
this.options = options;
this.logger = logger || getEmptyLogger();
}
public abstract get target(): PublisherTarget;
public abstract publish(): Promise<void>;
}