-
Notifications
You must be signed in to change notification settings - Fork 211
/
select-schematic.ts
51 lines (48 loc) · 1.43 KB
/
select-schematic.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
import { Schematic } from '@nx-console/schema';
import { TaskExecutionSchema } from '@nx-console/schema';
import { QuickPickItem, window } from 'vscode';
import {
readAllSchematicCollections,
readSchematicOptions,
} from './utils/read-schematic-collections';
export async function selectSchematic(
workspaceJsonPath: string
): Promise<TaskExecutionSchema | undefined> {
interface GenerateQuickPickItem extends QuickPickItem {
collectionName: string;
schematic: Schematic;
}
const schematics = (await readAllSchematicCollections(workspaceJsonPath))
.filter((c) => c && c.schematics.length)
.map((c): GenerateQuickPickItem[] =>
c.schematics.map(
(s: Schematic): GenerateQuickPickItem => ({
description: s.description,
label: `${c.name} - ${s.name}`,
collectionName: c.name,
schematic: s,
})
)
)
.flat();
if (schematics) {
const selection = await window.showQuickPick(schematics);
if (selection) {
const options =
selection.schematic.options ||
(await readSchematicOptions(
workspaceJsonPath,
selection.collectionName,
selection.schematic.name
));
const positional = `${selection.collectionName}:${selection.schematic.name}`;
return {
...selection.schematic,
options,
command: 'generate',
positional,
cliName: 'nx',
};
}
}
}