generate-react-cli 8.2.0-alpha.1 → 8.2.0-alpha.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": "generate-react-cli",
|
|
3
|
-
"version": "8.2.0-alpha.
|
|
3
|
+
"version": "8.2.0-alpha.3",
|
|
4
4
|
"description": "A simple React CLI to generate components instantly and more.",
|
|
5
5
|
"repository": "https://github.com/arminbro/generate-react-cli",
|
|
6
6
|
"bugs": "https://github.com/arminbro/generate-react-cli/issues",
|
|
@@ -24,7 +24,8 @@ export default function initGenerateComponentCommand(args, cliConfigFile, progra
|
|
|
24
24
|
'Describe the component you want GRC to generate (e.g., Create a counter component that increments by one when I click on the increment button).',
|
|
25
25
|
null
|
|
26
26
|
)
|
|
27
|
-
.option('-f, --flat', 'Generate the files in the mentioned path insted of creating new folder for it', false)
|
|
27
|
+
.option('-f, --flat', 'Generate the files in the mentioned path insted of creating new folder for it', false)
|
|
28
|
+
.option('-dr, --dry-run', 'Show what will be generated without writing to disk');
|
|
28
29
|
|
|
29
30
|
// Dynamic component command option defaults.
|
|
30
31
|
|
|
@@ -38,8 +39,6 @@ export default function initGenerateComponentCommand(args, cliConfigFile, progra
|
|
|
38
39
|
);
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
componentCommand.option('--dry-run', 'Show what will be generated without writing to disk');
|
|
42
|
-
|
|
43
42
|
// Component command action.
|
|
44
43
|
|
|
45
44
|
componentCommand.action((componentNames, cmd) =>
|
|
@@ -16,3 +16,20 @@ export async function aiComponentGenerator(componentTemplate, prompt) {
|
|
|
16
16
|
|
|
17
17
|
return generatedComponent.data.choices[0].text;
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
export async function aiComponentTestGenerator(componentTemplate, prompt) {
|
|
21
|
+
const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY });
|
|
22
|
+
const openAiApi = new OpenAIApi(configuration);
|
|
23
|
+
|
|
24
|
+
const generatedComponent = await openAiApi.createCompletion({
|
|
25
|
+
model: 'text-davinci-003',
|
|
26
|
+
prompt: `Create a React component unit tests using this template "${componentTemplate}", but make the adjustments needed with these instructions as follows "${prompt}"`,
|
|
27
|
+
temperature: 0.7,
|
|
28
|
+
max_tokens: 2000,
|
|
29
|
+
top_p: 1.0,
|
|
30
|
+
frequency_penalty: 0.0,
|
|
31
|
+
presence_penalty: 1,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return generatedComponent.data.choices[0].text;
|
|
35
|
+
}
|
|
@@ -7,7 +7,7 @@ import snakeCase from 'lodash/snakeCase.js';
|
|
|
7
7
|
import startCase from 'lodash/startCase.js';
|
|
8
8
|
import fsExtra from 'fs-extra';
|
|
9
9
|
|
|
10
|
-
import { aiComponentGenerator } from '../services/openAiService.js';
|
|
10
|
+
import { aiComponentGenerator, aiComponentTestGenerator } from '../services/openAiService.js';
|
|
11
11
|
import componentJsTemplate from '../templates/component/componentJsTemplate.js';
|
|
12
12
|
import componentTsTemplate from '../templates/component/componentTsTemplate.js';
|
|
13
13
|
import componentCssTemplate from '../templates/component/componentCssTemplate.js';
|
|
@@ -438,6 +438,30 @@ export function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
438
438
|
return;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
// Generate component test with openAi, if component description is provided
|
|
442
|
+
|
|
443
|
+
if (cmd.describe && componentFileType === buildInComponentFileTypes.TEST) {
|
|
444
|
+
aiComponentTestGenerator(template, cmd.describe)
|
|
445
|
+
.then((aiGeneratedComponentTest) => {
|
|
446
|
+
outputFileSync(componentPath, aiGeneratedComponentTest.trim());
|
|
447
|
+
console.log(
|
|
448
|
+
chalk.green(
|
|
449
|
+
`OpenAI Successfully created the ${filename} component test with the provided description.`
|
|
450
|
+
)
|
|
451
|
+
);
|
|
452
|
+
})
|
|
453
|
+
.catch((error) =>
|
|
454
|
+
console.log(
|
|
455
|
+
chalk.red(
|
|
456
|
+
`OpenAI failed to create the ${filename} component test with the provided description.`,
|
|
457
|
+
error
|
|
458
|
+
)
|
|
459
|
+
)
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
441
465
|
console.log(chalk.green(`${filename} was successfully created at ${componentPath}`));
|
|
442
466
|
} catch (error) {
|
|
443
467
|
console.error(chalk.red(`${filename} failed and was not created.`));
|