-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish.ts
56 lines (48 loc) · 1.53 KB
/
publish.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
53
54
55
56
import { log, LogLevel } from './logging';
import {
AssetManifest,
AssetPublishing,
DefaultAwsClient,
DestinationPattern,
EventType,
IPublishProgress,
IPublishProgressListener,
} from '../lib';
export async function publish(args: { path: string; assets?: string[]; profile?: string }) {
let manifest = AssetManifest.fromPath(args.path);
log('verbose', `Loaded manifest from ${args.path}: ${manifest.entries.length} assets found`);
if (args.assets && args.assets.length > 0) {
const selection = args.assets.map((a) => DestinationPattern.parse(a));
manifest = manifest.select(selection);
log('verbose', `Applied selection: ${manifest.entries.length} assets selected.`);
}
const pub = new AssetPublishing(manifest, {
aws: new DefaultAwsClient(args.profile),
progressListener: new ConsoleProgress(),
throwOnError: false,
});
await pub.publish();
if (pub.hasFailures) {
for (const failure of pub.failures) {
// eslint-disable-next-line no-console
console.error('Failure:', failure.error.stack);
}
process.exitCode = 1;
}
}
const EVENT_TO_LEVEL: Record<EventType, LogLevel> = {
build: 'verbose',
cached: 'verbose',
check: 'verbose',
debug: 'verbose',
fail: 'error',
found: 'verbose',
start: 'info',
success: 'info',
upload: 'verbose',
};
class ConsoleProgress implements IPublishProgressListener {
public onPublishEvent(type: EventType, event: IPublishProgress): void {
log(EVENT_TO_LEVEL[type], `[${event.percentComplete}%] ${type}: ${event.message}`);
}
}