mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Made base class for publishers
This commit is contained in:
parent
27004e5242
commit
59eb2bc7e7
2 changed files with 37 additions and 0 deletions
17
src/publishing/publisher-target.ts
Normal file
17
src/publishing/publisher-target.ts
Normal 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;
|
20
src/publishing/publisher.ts
Normal file
20
src/publishing/publisher.ts
Normal 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>;
|
||||
}
|
Loading…
Reference in a new issue