@kosdev-code/kos-ui-cli 2.0.8 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,274 +0,0 @@
1
- import directoryPrompt from "inquirer-directory";
2
- import {
3
- detectWorkspace,
4
- execute,
5
- getAllModels,
6
- getAllProjects,
7
- getLibraryProjects,
8
- getProjectDetails,
9
- required,
10
- } from "./utils/utils.mjs";
11
-
12
- const DEFAULT_PROMPTS = [
13
- {
14
- type: "confirm",
15
- name: "interactive",
16
- message: "Do you want to use the interactive mode?",
17
- default: false,
18
- when: false,
19
- },
20
- {
21
- type: "confirm",
22
- name: "dryRun",
23
- message: "Show the output of the command without running it?",
24
- default: false,
25
- when: false,
26
- },
27
- ];
28
-
29
- const MODEL_PROMPTS = [
30
- {
31
- type: "confirm",
32
- name: "container",
33
- default: false,
34
- message: "Does this model require a container model?",
35
- },
36
- {
37
- type: "confirm",
38
- name: "parentAware",
39
- when: (answers) => {
40
- console.log(answers);
41
- return !!answers.container;
42
- },
43
- default: false,
44
- message: "Should the model be aware of it's parent container?",
45
- },
46
- {
47
- type: "confirm",
48
- name: "singleton",
49
- default: false,
50
- message: "Is this model a singleton?",
51
- },
52
-
53
- {
54
- type: "confirm",
55
- name: "dataServices",
56
- default: true,
57
- message: "Create data services for model?",
58
- },
59
- ];
60
- export default async function (plop) {
61
- plop.setPrompt("directory", directoryPrompt);
62
- const isWorkspace = await detectWorkspace();
63
-
64
- const allProjects = isWorkspace ? await getAllProjects() : [];
65
- const libraryProjects = isWorkspace ? await getLibraryProjects() : [];
66
- const allModels = isWorkspace ? await getAllModels() : [];
67
- const workspaceModels = allModels.map((model) => {
68
- return { name: `${model.model} (${model.project})`, value: model.model };
69
- });
70
-
71
- plop.setActionType("createContainer", async function (answers, config, plop) {
72
- const modelProjectName = allModels.find(
73
- (model) => model.model === answers.modelName
74
- )?.project;
75
- const modelProject = await getProjectDetails(modelProjectName);
76
-
77
- try {
78
- await execute(
79
- `npx nx generate @kosdev-code/kos-nx-plugin:kos-container-model --modelName=${
80
- answers.modelName
81
- } --modelProject=${
82
- modelProject.name
83
- } --skipRegistration=true --dataServices=${!!answers.dataServices} --singleton=${!!answers.singleton} --no-interactive ${
84
- answers.dryRun ? "--dryRun" : ""
85
- } --verbose`
86
- );
87
- } catch (error) {
88
- throw new Error(error);
89
- }
90
- return `model ${answers.modelName} created in ${answers.modelProject}`;
91
- });
92
-
93
- plop.setActionType("createHook", async function (answers, config, plop) {
94
- const modelProject = allModels.find(
95
- (model) => model.model === answers.modelName
96
- )?.project;
97
-
98
- try {
99
- await execute(
100
- `npx nx generate @kosdev-code/kos-nx-plugin:kos-hook --appProject=${
101
- answers.componentProject
102
- } --modelProject=${modelProject} --name=${
103
- answers.modelName
104
- } --no-interactive ${answers.dryRun ? "--dryRun" : ""}`
105
- );
106
- } catch (error) {
107
- throw new Error(error);
108
- }
109
-
110
- return `hook created for ${answers.modelName} in ${answers.componentProject}`;
111
- });
112
-
113
- plop.setActionType("createContext", async function (answers, config, plop) {
114
- const modelProject = allModels.find(
115
- (model) => model.model === answers.modelName
116
- )?.project;
117
-
118
- try {
119
- await execute(
120
- `npx nx generate @kosdev-code/kos-nx-plugin:kos-context --appProject=${
121
- answers.componentProject
122
- } --modelProject=${modelProject} --name=${
123
- answers.modelName
124
- } --no-interactive ${answers.dryRun ? "--dryRun" : ""}`
125
- );
126
- } catch (error) {
127
- throw new Error(error);
128
- }
129
-
130
- return `context created for ${answers.modelName} in ${answers.componentProject}`;
131
- });
132
-
133
- plop.setActionType(
134
- "createCompanionModel",
135
- async function (answers, config, plop) {
136
- console.log(JSON.stringify(answers, null, 2));
137
- const modelProject = await getProjectDetails(answers.modelProject);
138
-
139
- const companionParentProjectName = allModels.find(
140
- (model) => model.model === answers.companionParent
141
- )?.project;
142
- try {
143
- await execute(
144
- `npx nx generate @kosdev-code/kos-nx-plugin:kos-model --name=${
145
- answers.modelName
146
- } --modelProject=${
147
- modelProject.name
148
- } --skipRegistration=true --container=${!!answers.container} --dataServices=${!!answers.dataServices} --singleton=${!!answers.singleton} --parentAware=${!!answers.parentAware} --companion=true --companionModel=${
149
- answers.companionParent
150
- } --companionModelProject=${companionParentProjectName} --no-interactive ${
151
- answers.dryRun ? "--dryRun" : ""
152
- } --verbose`
153
- );
154
- } catch (error) {
155
- throw new Error(error);
156
- }
157
- }
158
- );
159
-
160
- plop.setGenerator("container", {
161
- description: "Create a new KOS Container Model",
162
- prompts: [
163
- ...DEFAULT_PROMPTS,
164
- {
165
- type: "list",
166
- name: "modelName",
167
- message: "Which model to use?",
168
- choices: workspaceModels,
169
- },
170
- {
171
- type: "list",
172
- name: "registrationProject",
173
- message: "Which project should the model be registered in?",
174
- validate: required,
175
- choices: allProjects,
176
- },
177
- ...MODEL_PROMPTS,
178
- ],
179
- actions: function (data) {
180
- const action = {
181
- type: "createContainer",
182
- };
183
- return [action];
184
- },
185
- });
186
-
187
- plop.setGenerator("hook", {
188
- description: "Create a hook for a KOS Model",
189
- prompts: [
190
- {
191
- type: "list",
192
- name: "modelName",
193
- message: "Which model to use?",
194
-
195
- choices: workspaceModels,
196
- },
197
-
198
- {
199
- type: "list",
200
- name: "componentProject",
201
- message: "Which project should the hook be created in?",
202
- when: (answers) => {
203
- return !answers.componentProject;
204
- },
205
- choices: allProjects,
206
- },
207
- ],
208
- actions: function (data) {
209
- const action = {
210
- type: "createHook",
211
- };
212
- return [action];
213
- },
214
- });
215
-
216
- plop.setGenerator("context", {
217
- description: "Create a context for a KOS Model",
218
- prompts: [
219
- {
220
- type: "list",
221
- name: "modelName",
222
- message: "Which model to use?",
223
- choices: workspaceModels,
224
- },
225
-
226
- {
227
- type: "list",
228
- name: "componentProject",
229
- message: "Which project should the context be created in?",
230
- choices: getAllProjects,
231
- },
232
- ],
233
- actions: function (data) {
234
- const action = {
235
- type: "createContext",
236
- };
237
- return [action];
238
- },
239
- });
240
-
241
- plop.setGenerator("model:companion", {
242
- description: "Create a new KOS Companion Model",
243
- prompts: [
244
- ...DEFAULT_PROMPTS,
245
- {
246
- type: "input",
247
- name: "modelName",
248
- message: "Enter the name of the model",
249
- validate: required,
250
- },
251
- {
252
- type: "list",
253
- name: "modelProject",
254
- message: "Which model project to use?",
255
- validate: required,
256
- choices: libraryProjects,
257
- },
258
- {
259
- type: "list",
260
- name: "companionParent",
261
- message: "Select the companion parent model?",
262
- choices: workspaceModels,
263
- },
264
-
265
- ...MODEL_PROMPTS,
266
- ],
267
- actions: function (data) {
268
- const action = {
269
- type: "createCompanionModel",
270
- };
271
- return [action];
272
- },
273
- });
274
- }