-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathyo.ts
101 lines (97 loc) · 2.34 KB
/
yo.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function toTitleCase(str: string): string {
return str
.trim()
.replace(
/\w\S*/g,
(txt) => txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase()
);
}
const suggestions: Fig.Suggestion[] = [
{
name: "doctor",
description: "Running sanity checks on your system",
icon: "fig://icon?type=alert",
},
{
name: "completion",
description: "To enable shell completion for the yo command",
icon: "fig://icon?type=asterisk",
},
];
// GENERATORS
const yeomanGeneratorList: Fig.Generator = {
script: ["yo", "--generators"],
postProcess: function (out) {
try {
return out
.split("\n")
.filter((item) => item.trim() && item !== "Available Generators:")
.map(
(item) =>
({
name: item.trim(),
icon: "https://avatars.githubusercontent.com/u/1714870?v=4",
displayName: toTitleCase(item),
description: `${toTitleCase(item)} Generator`,
priority: 100,
options: [
{
name: "--help",
description: `Help of "${toTitleCase(item)}" generator`,
},
],
}) as Fig.Suggestion
) as Fig.Suggestion[];
} catch (e) {
console.error(e);
return [];
}
},
};
const completionSpec: Fig.Spec = {
name: "yo",
description: "Yeoman generator",
args: {
name: "generator",
generators: yeomanGeneratorList,
suggestions: [...suggestions],
isCommand: true,
isOptional: true,
},
options: [
{
name: "--help",
description: "Print info and generator's options and usage",
},
{
name: ["-f", "--force"],
description: "Overwrite files that already exist",
isDangerous: true,
},
{
name: "--version",
description: "Print version",
},
{
name: "--no-color",
description: "Disable color",
},
{
name: "--insight",
description: "Enable anonymous tracking",
},
{
name: "--no-insight",
description: "Disable anonymous tracking",
},
{
name: "--generators",
description: "Print available generators",
},
{
name: "--local-only",
description: "Disable lookup of globally-installed generators",
},
],
};
export default completionSpec;