-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublisher.ts
52 lines (47 loc) · 1.52 KB
/
publisher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import FilePublisher = require('./filepublisher');
import GitPublisher = require('./gitpublisher');
import S3Publisher = require('./s3publisher');
import MirrorPublisher = require('./mirrorpublisher');
// type Config = {
// type: "file";
// root: string;
// } |
// {
// type: "git";
// root: string;
// push: boolean;
// } |
// {
// type: "s3";
// region: string;
// bucket: string;
// } |
// {
// type: 'mirror';
// primary: Config;
// secondary: Config;
// };
abstract class Publisher {
abstract put(path: string, obj: string | NodeJS.ReadableStream, contentType?: string): Promise<void>;
abstract delete(path: string, contentType: string): Promise<void>;
abstract get(path: string): Promise<{Body: Buffer, ContentType: string}>;
abstract exists(path: string): Promise<boolean>;
abstract list(): Promise<string[]>;
abstract rollback(): Promise<void>;
abstract commit(msg: string): Promise<void>;
static getInstance(config): Publisher {
switch(config.type) {
case 'file':
return new FilePublisher(config);
case 'git':
return new GitPublisher(config);
case 's3':
return new S3Publisher(config);
case 'mirror':
return new MirrorPublisher(config);
default:
throw new Error('Unknown publisher type ' + config.type);
}
}
}
export default Publisher;