forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnx.ts
484 lines (473 loc) · 12.6 KB
/
nx.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
type PostProcessFn = (out: string, context: string[]) => Fig.Suggestion[];
interface NxProject {
projectType: string;
}
type PostProcessWorkspaceFn = (
filterFn: (
projectEntry: [string, NxProject],
index: number,
array: [string, NxProject][]
) => boolean
) => PostProcessFn;
interface NxGenerators {
apps: Fig.Generator;
e2eApps: Fig.Generator;
appsAndLibs: Fig.Generator;
localSchematics: Fig.Generator;
localGenerators: Fig.Generator;
installedPlugins: Fig.Generator;
pluginsSchematics: Fig.Generator;
}
const processWorkspaceJson: PostProcessWorkspaceFn = (filterFn) => (out) => {
try {
const workspace = JSON.parse(out);
return Object.entries<NxProject>(workspace.projects)
.filter(filterFn)
.map(([projectName]) => projectName)
.map((suggestion) => ({
name: suggestion,
type: "option",
}));
} catch (err) {
console.log(err);
return [];
}
};
const processGenerators: PostProcessFn = (out) => {
return out
.split("\n")
.map((line) => line.split(" ").pop())
.map((suggestion) => ({
name: suggestion,
type: "option",
}));
};
const oneDayCache: Fig.Cache = {
ttl: 60 * 60 * 24,
};
const nxGenerators: NxGenerators = {
apps: {
script: "cat workspace.json",
postProcess: processWorkspaceJson(
([projectName, project], _, projects) =>
project.projectType === "application" && !projectName.endsWith("-e2e")
),
},
e2eApps: {
script: "cat workspace.json",
postProcess: processWorkspaceJson(
([projectName, project], _, projects) =>
project.projectType === "application" && projectName.endsWith("-e2e")
),
},
appsAndLibs: {
script: "cat workspace.json",
postProcess: processWorkspaceJson(() => true),
},
localSchematics: {
script: "ls tools/schematics",
cache: oneDayCache,
postProcess: processGenerators,
},
localGenerators: {
script: "ls tools/generators",
cache: oneDayCache,
postProcess: processGenerators,
},
installedPlugins: {
script: "nx list",
cache: oneDayCache,
postProcess: (out) => {
if (out.indexOf("Installed plugins") > -1) {
const fullList = out.split(">");
const plugins = fullList[1].split("\n").filter(Boolean);
plugins.shift();
return plugins
.map((pluginEntry) => pluginEntry.trim().split(" ")[0])
.map((suggestion) => ({
name: suggestion,
type: "option",
}));
}
},
},
pluginsSchematics: {
script: (context) => {
const argument = context.slice(-1)[0];
if (argument.indexOf(":") > -1) {
return `nx list ${argument.split(":")[0]}`;
} else {
return "nx list";
}
},
trigger: ":",
cache: oneDayCache,
postProcess: (out, context) => {
if (out.indexOf("Installed plugins") > -1) {
const fullList = out.split(">");
const plugins = fullList[1].split("\n").filter(Boolean);
plugins.shift();
return plugins
.map((pluginEntry) => pluginEntry.trim().split(" ")[0])
.map((suggestion) => ({
name: suggestion,
type: "option",
}));
} else if (out.indexOf("Capabilities") > -1) {
const pluginArg = context.slice(-1)[0];
const lines = out.split("\n");
return lines
.filter((line) => line.trim().indexOf(" : ") > -1)
.map((line) => pluginArg + line.trim().split(" : ")[0])
.map((suggestion) => ({
name: suggestion,
type: "option",
}));
}
},
},
};
const defaultOptions: Fig.Option[] = [
{
name: "--help",
description: "Show help",
},
{
name: "--version",
description: "Show version number",
},
];
const affectedOptions: Fig.Option[] = [
{
name: "--all",
description: "All projects",
},
{
name: "--base",
args: {},
description: "Base of the current branch (usually master)",
},
{
name: "--configuration",
args: {},
description:
"This is the configuration to use when performing tasks on projects",
},
{
name: "--exclude",
args: {},
description: "Exclude certain projects from being processed",
},
{
name: "--files",
args: {},
description:
"Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas",
},
{
name: "--head",
args: {},
description: "Latest commit of the current branch (usually HEAD)",
},
{
name: "--maxParallel",
args: { suggestions: ["3"] },
description:
"Max number of parallel processes. This flag is ignored if the parallel option is set to false. (default: 3)",
},
{
name: "--only-failed",
description: "Isolate projects which previously failed",
},
{
name: "--parallel",
args: { suggestions: ["false", "true"] },
description: "Parallelize the command (default: false)",
},
{
name: "--runner",
args: {},
description: "This is the name of the tasks runner configured in nx.json",
},
{
name: "--skip-nx-cache",
description:
"Rerun the tasks even when the results are available in the cache",
},
{
name: "--target",
args: {},
description: "Task to run for affected projects",
},
{
name: "--uncommitted",
description: "Uncommitted changes",
},
{
name: "--untracked",
description: "Untracked changes",
},
{
name: "--verbose",
description: "Print additional error stack trace on failure",
},
];
export const completionSpec: Fig.Spec = {
name: "nx",
description: "fig completions for Nx by Nrwl",
subcommands: [
{
name: "build",
description: "build an Nx app",
args: {
generators: nxGenerators.apps,
name: "app",
},
},
{
name: "serve",
description: "serve an Nx app",
args: {
generators: nxGenerators.apps,
name: "app",
},
options: [
{
name: "--allowedHosts",
args: {},
description:
"This option allows you to whitelist services that are allowed to access the dev server.",
},
{
name: "--host",
args: { suggestions: ["localhost"] },
description: "Host to listen on (default: localhost)",
},
{
name: "--liveReload",
args: { suggestions: ["true", "false"] },
description:
"Whether to reload the page on change, using live-reload.",
},
{
name: ["--open", "-o"],
description: "Open the application in the browser",
},
{
name: "--port",
args: { suggestions: ["4200"] },
description: "Port to listen on (default: 4200)",
},
{
name: "--publicHost",
description: "Public URL where the application will be served",
},
{
name: "--ssl",
args: { suggestions: ["true", "false"] },
description: "Serve using HTTPS.",
},
{
name: "--sslKey",
args: {},
description: "SSL key to use for serving HTTPS.",
},
{
name: "--sslCert",
args: {},
description: "SSL certificate to use for serving HTTPS.",
},
{
name: "--watch",
args: { suggestions: ["true", "false"] },
description:
"Watches for changes and rebuilds application (default: true)",
},
{
name: "--buildTarget",
args: {},
description: "Target which builds the application",
},
{
name: "--memoryLimit",
args: {},
description: "Memory limit for type checking service process in MB.",
},
{
name: "--maxWorkers",
args: {},
description: "Number of workers to use for type checking.",
},
...defaultOptions,
],
},
{
name: "test",
description: "test an Nx app or lib",
args: {
generators: nxGenerators.appsAndLibs,
name: "app/lib",
},
options: [...defaultOptions],
},
{
name: "e2e",
description: "run e2e tests for an Nx app",
args: {
generators: nxGenerators.e2eApps,
name: "app",
},
options: [...defaultOptions],
},
{
name: "lint",
description: "lint an Nx app or lib",
args: {
generators: nxGenerators.appsAndLibs,
name: "app/lib",
},
options: [...defaultOptions],
},
{
name: "workspace-schematic",
description: "Run a workspace schematic",
args: {
generators: nxGenerators.localSchematics,
name: "schematic",
},
options: [
{
name: "--list-schematics",
description: "List the available workspace-schematics",
},
...defaultOptions,
],
},
{
name: "workspace-generator",
description: "Run a workspace generator",
args: {
generators: nxGenerators.localGenerators,
name: "generator",
},
options: [
{
name: "--list-generators",
description: "List the available workspace-generators",
},
...defaultOptions,
],
},
{
name: "generate",
description: "run a generator",
args: {
generators: nxGenerators.pluginsSchematics,
name: "collection:generator",
},
options: [
{
name: ["--defaults"],
args: [{ name: "true" }, { name: "false" }],
description:
"when true, disables interactive input prompts for options with a default {true|false}",
},
{
name: ["--dryRun"],
args: [{ name: "true" }, { name: "false" }],
description:
"when true, runs the generator without making actual changes {true|false}",
},
{
name: ["--force"],
args: [{ name: "true" }, { name: "false" }],
description:
"when true, forces overwriting of existing files {true|false}",
},
{
name: ["--interactive"],
args: [{ name: "true" }, { name: "false" }],
description:
"when false, disables interactive input prompts {true|false}",
},
...defaultOptions,
],
},
{
name: "dep-graph",
options: [
{
name: "--exclude",
args: {},
description:
"List of projects delimited by commas to exclude from the dependency graph.",
},
{
name: "--file",
args: {},
description:
"output file (e.g. --file=output.json or --file=dep-graph.html)",
},
{
name: "--focus",
args: {},
description:
"Use to show the dependency graph for a particular project and every node that is either an ancestor or a descendant.",
},
{
name: "--groupByFolder",
description: "Group projects by folder in dependency graph",
},
{
name: "--host",
args: {},
description: "Bind the dep graph server to a specific ip address.",
},
{
name: "--port",
args: {},
description: "Bind the dep graph server to a specific port.",
},
...defaultOptions,
],
},
{ name: "affected", options: [...affectedOptions, ...defaultOptions] },
{
name: "affected:build",
options: [...affectedOptions, ...defaultOptions],
},
{
name: "affected:serve",
options: [...affectedOptions, ...defaultOptions],
},
{ name: "affected:test", options: [...affectedOptions, ...defaultOptions] },
{ name: "affected:e2e", options: [...affectedOptions, ...defaultOptions] },
{ name: "affected:lint", options: [...affectedOptions, ...defaultOptions] },
{
name: "affected:dep-graph",
options: [...affectedOptions, ...defaultOptions],
},
{ name: "affected:apps", options: [...affectedOptions, ...defaultOptions] },
{ name: "affected:libs", options: [...affectedOptions, ...defaultOptions] },
{
name: "report",
options: [...defaultOptions],
},
{
name: "workspace-lint",
options: [...defaultOptions],
},
{
name: "connect-lint",
options: [...defaultOptions],
},
{
name: "list",
args: {
generators: [nxGenerators.installedPlugins],
description: "The name of an installed plugin to query",
},
options: [...defaultOptions],
},
],
};