-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.ts
75 lines (71 loc) · 2.01 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { default as cache } from './lib/commands/cache';
import { default as calculate } from './lib/commands/calculate';
import { default as clean } from './lib/commands/clean';
import { default as download } from './lib/commands/download';
import { default as history } from './lib/commands/history';
import { default as success } from './lib/commands/success';
import { flagsEnum, MainTypes } from './types';
import pick from 'lodash.pick';
export const SUPPORTED_COMMANDS = ['cache', 'calculate', 'clean', 'download', 'history', 'success'];
export default async function main({ command, repoSlug, flags, cwd }: MainTypes) {
let [host, user, repo]: string[] = repoSlug;
switch (command) {
case 'download':
await download({
cwd,
host,
user,
repo,
...pick(flags, [flagsEnum.auth, flagsEnum.concurrency, flagsEnum.since]),
});
break;
case 'calculate':
await calculate({
cwd,
host,
user,
repo,
...pick(flags, [
flagsEnum.branch,
flagsEnum.result,
flagsEnum.period,
flagsEnum.last,
flagsEnum.threshold,
flagsEnum.json,
]),
});
break;
case 'history':
await history({
cwd,
host,
user,
repo,
...pick(flags, [flagsEnum.branch, flagsEnum.result, flagsEnum.threshold, flagsEnum.json]),
});
break;
case 'success':
await success({
cwd,
host,
user,
repo,
...pick(flags, [flagsEnum.branch, flagsEnum.result, flagsEnum.period, flagsEnum.last, flagsEnum.json]),
});
break;
case 'clean':
await clean({
cwd,
host,
user,
repo,
});
break;
case 'cache':
await cache({ cwd, host, user, repo });
break;
default:
throw new Error(`Unknown command "${command}", should be ${SUPPORTED_COMMANDS.join(', ')}.`);
}
}
export { cache, calculate, clean, download, history, success };