/
listStates.ts
44 lines (38 loc) · 1.08 KB
/
listStates.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
import { WithActionReporter } from "./ActionReporter";
import { getBluehawk } from "../../bluehawk";
import { ActionArgs } from "./ActionArgs";
import { printJsonResult } from "./printJsonResult";
export interface ListStatesArgs extends ActionArgs {
paths: string[];
json?: boolean;
ignore?: string | string[];
}
export const listStates = async (
args: WithActionReporter<ListStatesArgs>
): Promise<void> => {
const { ignore, json, paths, waitForListeners, reporter } = args;
const bluehawk = await getBluehawk();
const statesFound = new Set<string>();
bluehawk.subscribe((result) => {
const { document } = result;
const { state } = document.attributes;
if (state === undefined) {
return;
}
statesFound.add(state as string);
});
await bluehawk.parseAndProcess(paths, {
reporter,
ignore,
waitForListeners: waitForListeners ?? false,
});
if (json) {
printJsonResult(args, { states: Array.from(statesFound) });
return;
}
reporter.onStatesFound({
action: "listStates",
paths,
statesFound: Array.from(statesFound),
});
};