-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathtrex.ts
195 lines (186 loc) · 4.43 KB
/
trex.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
const dependenciesGenerator: Fig.Generator = {
script: ["cat", "import_map.json"],
postProcess: function (out) {
if (out) {
try {
const deps = JSON.parse(out);
if (deps.imports) {
const imports = Object.entries(deps.imports);
const suggestions = imports.map(([name, url]) => ({
name: name as string,
icon: "🦖",
description: url as string,
}));
return suggestions;
}
} catch (error) {
return [];
}
}
return [];
},
};
const scriptsGenerator: Fig.Generator = {
script: ["cat", "run.json"],
postProcess: function (out) {
if (out) {
try {
const scriptsObj = JSON.parse(out);
if (scriptsObj.scripts) {
const scripts = Object.entries(scriptsObj.scripts);
const suggestions = scripts.map(([name, command]) => ({
name: name as string,
icon: "🚀",
description: "trex script" as string,
}));
return suggestions;
}
} catch (error) {
return [];
}
}
return [];
},
};
const trexOptions: Record<string, Fig.Option> = {
version: { name: ["-v", "--version"], description: "Print version" },
map: {
name: ["-m", "--map"],
description: "Install package from deno.land",
args: {
name: "package name",
description: "Deno.land package name",
},
},
nest: {
name: ["-n", "--nest"],
description: "Install package from nest.land",
args: {
name: "package name",
description: "Nest.land package name",
},
},
pkg: {
name: ["-p", "--pkg"],
description: "Install package from some repository",
args: [
{
name: "repository",
description: "[user]/[repo or repo@tag/branch]/[path/to/file]",
},
{
name: "Package Name",
description: "Prefered package alias",
},
],
},
custom: {
name: ["-c", "--custom"],
description: "Install custom package",
args: {
name: "custom package",
description:
"Install a package from a custom URL source, eg: React=https://dev.jspm.io/react/index.js",
},
},
};
const completionSpec: Fig.Spec = {
name: "trex",
description: "Advanced package management for deno, based on import_map.json",
subcommands: [
{
name: ["i", "install"],
description: "Install a package",
options: [trexOptions.map, trexOptions.nest, trexOptions.pkg],
},
{
name: "delete",
description: "Delete a package",
args: {
name: "package name",
generators: dependenciesGenerator,
filterStrategy: "fuzzy",
},
},
{
name: "upgrade",
description: "Upgrade trex",
options: [
{
name: "--canary",
description: "Install from dev branch",
},
],
},
{
name: "tree",
description: "View dependency tree",
},
{
name: "run",
description: "Run a script alias in a file run.json",
options: [
{
name: ["-w", "--watch"],
description: "Use reboot script alias protocol (rsap)",
},
{
name: "-wv",
description: "Verbose output in --watch mode (rsap)",
},
],
args: {
name: "script alias",
generators: scriptsGenerator,
},
},
{
name: "purge",
description: "Remove a package or url from cache",
args: {
name: "package | url",
generators: dependenciesGenerator,
filterStrategy: "fuzzy",
},
},
{
name: "ls",
description: "Shows the list of installed packages",
},
{
name: "exec",
description: "Execute a cli tool with out install then",
options: [
{
name: "--perms",
description: "Specify cli permisions",
},
],
args: {
name: "cli tool",
},
},
{
name: "check",
description: "Check deno.land [std/x] dependencies updates",
options: [
{
name: ["-f", "--fix"],
description: "Update outdated dependencies",
},
],
},
],
options: [
{
name: ["-h", "--help"],
description: "Print help info",
isPersistent: true,
},
trexOptions.version,
trexOptions.custom,
],
// Only uncomment if trex takes an argument
// args: {}
};
export default completionSpec;