/
listTags.ts
61 lines (55 loc) · 1.68 KB
/
listTags.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
import { getBluehawk } from "..";
import { ActionArgs } from "./ActionArgs";
import { printJsonResult } from "./printJsonResult";
export interface ListTagArgs extends ActionArgs {
json?: boolean;
}
export const listTags = async (args: ListTagArgs): Promise<void> => {
const { json } = args;
const bluehawk = await getBluehawk();
const { processor } = bluehawk;
const { processors } = processor;
if (json) {
const tags = Object.entries(processors).map(([registeredName, tag]) => {
const aliasOf = registeredName !== tag.name ? tag.name : undefined;
const name = registeredName;
const {
description,
supportsBlockMode,
supportsLineMode,
attributesSchema,
} = tag;
return {
name,
aliasOf,
description,
supportsBlockMode,
supportsLineMode,
attributesSchema,
};
});
printJsonResult(args, { tags });
return;
}
const tagsListText = Object.entries(processors)
.map(([registeredName, tag]) => {
const isAlias = registeredName !== tag.name;
const name = isAlias
? `${registeredName} (alias of ${tag.name})`
: tag.name;
return `${name}\n${[
`${tag.description ?? "No description"}`,
`block mode supported: ${tag.supportsBlockMode ? "yes" : "no"}`,
`line mode supported: ${tag.supportsLineMode ? "yes" : "no"}`,
`attributes schema: ${
tag.attributesSchema !== undefined
? JSON.stringify(tag.attributesSchema)
: "N/A"
}`,
]
.map((s) => ` ${s}`)
.join("\n")}`;
})
.join("\n\n");
console.log(`available markup tags:\n\n${tagsListText}`);
};