@pega/custom-dx-components 0.23.2 → 0.23.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.23.2",
3
+ "version": "0.23.3",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -33,6 +33,7 @@
33
33
  "gitignore": "^0.7.0",
34
34
  "inquirer": "^9.1.1",
35
35
  "listr": "^0.14.3",
36
+ "lodash": "^4.17.21",
36
37
  "mini-css-extract-plugin": "2.6.1",
37
38
  "mustache": "^4.2.0",
38
39
  "ncp": "^2.0.0",
@@ -1,139 +1,25 @@
1
+ import fs from 'fs';
2
+ import {sep, join} from 'path';
3
+ import { URL, fileURLToPath } from 'url';
4
+
1
5
  import chalk from 'chalk';
2
6
  import inquirer from 'inquirer';
3
- import ora from 'ora';
4
- import path from 'path';
5
- import { URL, fileURLToPath } from 'url';
6
- import { join } from 'path';
7
- import fs from 'fs';
7
+ import _ from 'lodash';
8
8
 
9
9
  import {
10
10
  AI_PROMPT_FILENAME,
11
11
  AI_DAVINCI_PROMPT_FILENAME
12
12
  } from '../../constants.js';
13
-
14
- import _ from 'lodash';
15
-
16
-
17
13
  import {
18
14
  getComponents,
19
15
  getComponentsOfType,
20
- getPegaConfig,
21
- getAIPromptData,
22
16
  getDirectoryFiles,
23
- getAIComponent,
24
17
  getInfinityAIComponent,
25
18
  getComponentDirectoryPath,
26
19
  compileMustacheTemplate,
27
20
  getComponentConfigJson,
28
21
  getComponentConfigType
29
22
  } from '../../util.js';
30
- import { str } from 'ajv';
31
-
32
-
33
- export const getSelectAComponent = async() => {
34
- //let localComponents = await getComponents();
35
- const localComponents = await getComponentsOfType("Widget,Template");
36
-
37
- let answers;
38
-
39
- if (localComponents.length > 0) {
40
- answers = await inquirer.prompt([
41
- {
42
- name: 'componentKey',
43
- type: 'rawlist',
44
- message: 'Select component to generateAI',
45
- choices: localComponents
46
- }]);
47
- }
48
-
49
- return answers;
50
- }
51
-
52
- export const determineAndGenerateAI = async (enteredKey) => {
53
-
54
- if (!enteredKey) {
55
- let answer = await getSelectAComponent();
56
- if (answer) {
57
- enteredKey = answer.componentKey;
58
- }
59
- else {
60
- console.log(chalk.bold.redBright(`No custom components to generate AI. Please create a Widget or Template component first.`));
61
- process.exit(1);
62
- }
63
-
64
- }
65
-
66
- const targetDirectory = await getComponentDirectoryPath(enteredKey);
67
- const configType = await getComponentConfigType(targetDirectory);
68
-
69
- switch (configType.toLowerCase()) {
70
- case "widget":
71
- case "template":
72
- await getWidgetTemplateAndGenerateAI(enteredKey);
73
- break;
74
- case "field":
75
- await getFieldAndGenerateAI(enteredKey);
76
- break;
77
- }
78
-
79
-
80
- }
81
-
82
- export const getWidgetTemplateAndGenerateAI = async (enteredKey) => {
83
- const localComponents = await getComponents();
84
-
85
- let answers;
86
-
87
- if (localComponents.length > 0) {
88
-
89
- answers = await inquirer.prompt([
90
-
91
- {
92
- name: 'additionalPromptInfo',
93
- message: 'Enter what you would like this component to do? ',
94
- }
95
-
96
-
97
- ]);
98
-
99
- console.log("Generating component...");
100
-
101
- await generateInfinityAIComponent(enteredKey, answers.additionalPromptInfo);
102
-
103
- } else {
104
- console.log(chalk.bold.redBright(`No custom components in ${sourceOfComponents}`));
105
- }
106
- };
107
-
108
-
109
- export const getFieldAndGenerateAI = async (enteredKey) => {
110
- const localComponents = await getComponents();
111
-
112
- let answers;
113
-
114
- if (localComponents.length > 0) {
115
-
116
- answers = await inquirer.prompt([
117
- {
118
- name: 'designSystemComponents',
119
- message: 'Enter comma delimited string of Design system components (ie. Input, TextArea, etc.)'
120
- },
121
- {
122
- name: 'additionalPromptInfo',
123
- message: 'Enter any additional generation information',
124
- }
125
-
126
- ]);
127
-
128
-
129
- console.log("Generating component...");
130
-
131
- await generateAIComponent(enteredKey || answers.componentKey, answers.designSystemComponents, answers.additionalPropmtInfo);
132
-
133
- } else {
134
- console.log(chalk.bold.redBright(`No custom components in ${sourceOfComponents}`));
135
- }
136
- };
137
23
 
138
24
  export const renameFile = (oldFileName, newFileName) => {
139
25
  try {
@@ -146,12 +32,12 @@ export const renameFile = (oldFileName, newFileName) => {
146
32
 
147
33
  export const generateAIComponent = async (componentKey, designSystemComponents, additionalPromptInfo) => {
148
34
 
149
- const fileName = "." + path.sep + AI_PROMPT_FILENAME;
35
+ const fileName = "." + sep + AI_PROMPT_FILENAME;
150
36
 
151
37
  // get config file
152
38
  //
153
39
  const targetDirectory = await getComponentDirectoryPath(componentKey);
154
- let configFileData = await getComponentConfigJson(targetDirectory);
40
+ const configFileData = await getComponentConfigJson(targetDirectory);
155
41
 
156
42
  // let data = JSON.parse(configFileData);
157
43
  // data.properties = [];
@@ -169,12 +55,9 @@ export const generateAIComponent = async (componentKey, designSystemComponents,
169
55
  strPrompt = _.unescape(strPrompt);
170
56
 
171
57
 
172
- //let strPrompt = await getAIPromptData(fileURLToPath(new URL(fileName, import.meta.url)));
173
- //let aiComponent = await getAIComponent(strPrompt);
174
58
  let aiComponent = await getInfinityAIComponent(strPrompt);
175
59
 
176
60
  if (aiComponent) {
177
- //console.log(aiData);
178
61
  const indexFile = join(targetDirectory, "index.jsx");
179
62
 
180
63
  // remove enclosed ``` and "Answer:"
@@ -252,9 +135,11 @@ export const generateAIComponent = async (componentKey, designSystemComponents,
252
135
 
253
136
  }
254
137
 
138
+
139
+
255
140
  export const generateInfinityAIComponent = async (componentKey, additionalPromptInfo) => {
256
141
 
257
- const fileName = "." + path.sep + AI_DAVINCI_PROMPT_FILENAME;
142
+ const fileName = "." + sep + AI_DAVINCI_PROMPT_FILENAME;
258
143
 
259
144
  // get config file
260
145
  //
@@ -354,4 +239,152 @@ export const generateInfinityAIComponent = async (componentKey, additionalPrompt
354
239
 
355
240
 
356
241
 
242
+ }
243
+
244
+ export const getWidgetTemplateAndGenerateAI = async (enteredKey) => {
245
+ const localComponents = await getComponents();
246
+
247
+ let answers;
248
+
249
+ if (localComponents.length > 0) {
250
+
251
+ answers = await inquirer.prompt([
252
+ {
253
+ name: "fileOrText",
254
+ type: "rawlist",
255
+ choices: [ {name: "Prompt via a file", value:"File"}, {name: "Prompt entered text", value:"Text"}],
256
+ message: 'Enter how you want to propmt for component instructions '
257
+ },
258
+ {
259
+ name: 'fileName',
260
+ message: 'Enter file name? ',
261
+ default: 'prompt.txt',
262
+ when(answers) {
263
+ return answers.fileOrText === 'File';
264
+ }
265
+ },
266
+ {
267
+ name: 'additionalPromptInfo',
268
+ message: 'Enter what you would like this component to do? ',
269
+ when(answers) {
270
+ return answers.fileOrText === 'Text';
271
+ }
272
+ }
273
+
274
+ ]);
275
+
276
+ console.log("Generating component...");
277
+
278
+ if (answers.fileOrText === "Text") {
279
+ await generateInfinityAIComponent(enteredKey, answers.additionalPromptInfo);
280
+ }
281
+ else if (answers.fileOrText == "File") {
282
+ const strPrompt = await getFilePromptData(enteredKey, answers.fileName);
283
+
284
+ await generateInfinityAIComponent(enteredKey, strPrompt);
285
+ }
286
+
287
+
288
+
289
+ } else {
290
+ console.log(chalk.bold.redBright(`No custom components in ${sourceOfComponents}`));
291
+ }
292
+ };
293
+
294
+ export const getFilePromptData = async (componentKey, fileName) => {
295
+ const targetDirectory = await getComponentDirectoryPath(componentKey);
296
+
297
+ const fullFileName = join(targetDirectory, fileName);
298
+
299
+ if (fs.existsSync(fullFileName)) {
300
+ const promptData = fs.readFileSync(fullFileName, { encoding: 'utf8' });
301
+ return promptData;
302
+ }
303
+ else {
304
+ console.log(chalk.bold.redBright(`File ${fileName} does not exist.`));
305
+ process.exit(1);
306
+ }
307
+
308
+
309
+ }
310
+
311
+ export const getFieldAndGenerateAI = async (enteredKey) => {
312
+ const localComponents = await getComponents();
313
+
314
+ let answers;
315
+
316
+ if (localComponents.length > 0) {
317
+
318
+ answers = await inquirer.prompt([
319
+ {
320
+ name: 'designSystemComponents',
321
+ message: 'Enter comma delimited string of Design system components (ie. Input, TextArea, etc.)'
322
+ },
323
+ {
324
+ name: 'additionalPromptInfo',
325
+ message: 'Enter any additional generation information',
326
+ }
327
+
328
+ ]);
329
+
330
+
331
+ console.log("Generating component...");
332
+
333
+ await generateAIComponent(enteredKey || answers.componentKey, answers.designSystemComponents, answers.additionalPropmtInfo);
334
+
335
+ } else {
336
+ console.log(chalk.bold.redBright(`No custom components in ${sourceOfComponents}`));
337
+ }
338
+ };
339
+
340
+
341
+
342
+ export const getSelectAComponent = async() => {
343
+ const localComponents = await getComponentsOfType("Widget,Template");
344
+
345
+ let answers;
346
+
347
+ if (localComponents.length > 0) {
348
+ answers = await inquirer.prompt([
349
+ {
350
+ name: 'componentKey',
351
+ type: 'rawlist',
352
+ message: 'Select component to generateAI',
353
+ choices: localComponents
354
+ }]);
355
+ }
356
+
357
+ return answers;
358
+ }
359
+
360
+ export const determineAndGenerateAI = async (enteredKey) => {
361
+
362
+ if (!enteredKey) {
363
+ const answer = await getSelectAComponent();
364
+ if (answer) {
365
+ enteredKey = answer.componentKey;
366
+ }
367
+ else {
368
+ console.log(chalk.bold.redBright(`No custom components to generate AI. Please create a Widget or Template component first.`));
369
+ process.exit(1);
370
+ }
371
+
372
+ }
373
+
374
+ const targetDirectory = await getComponentDirectoryPath(enteredKey);
375
+ const configType = await getComponentConfigType(targetDirectory);
376
+
377
+ switch (configType.toLowerCase()) {
378
+ case "widget":
379
+ case "template":
380
+ await getWidgetTemplateAndGenerateAI(enteredKey);
381
+ break;
382
+ case "field":
383
+ await getFieldAndGenerateAI(enteredKey);
384
+ break;
385
+ default:
386
+ break;
387
+ }
388
+
389
+
357
390
  }
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "@pega/configs": "^0.5.3",
60
- "@pega/custom-dx-components": "^0.23.2",
60
+ "@pega/custom-dx-components": "^0.23.3",
61
61
  "@pega/eslint-config": "^0.3.2",
62
62
  "@storybook/addon-actions": "^6.5.12",
63
63
  "@storybook/addon-essentials": "^6.5.12",