generate-react-cli 8.4.0 → 8.4.1
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/bin/generate-react.js +2 -2
- package/package.json +27 -21
- package/readme.md +1 -110
- package/src/utils/generateComponentUtils.js +0 -21
- package/src/services/openAiService.js +0 -18
package/bin/generate-react.js
CHANGED
|
@@ -6,12 +6,12 @@ const isNotValidNodeVersion = () => {
|
|
|
6
6
|
const semver = currentNodeVersion.split('.');
|
|
7
7
|
const major = semver[0];
|
|
8
8
|
|
|
9
|
-
if (major <
|
|
9
|
+
if (major < 18) {
|
|
10
10
|
console.error(
|
|
11
11
|
// eslint-disable-next-line
|
|
12
12
|
'You are running Node ' +
|
|
13
13
|
currentNodeVersion +
|
|
14
|
-
' Generate React CLI requires Node
|
|
14
|
+
' Generate React CLI requires Node 18 or higher. Please update your version of Node.'
|
|
15
15
|
);
|
|
16
16
|
|
|
17
17
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-react-cli",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.1",
|
|
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",
|
|
@@ -38,32 +38,31 @@
|
|
|
38
38
|
"prepare": "husky install"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"chalk": "5.
|
|
42
|
-
"commander": "
|
|
41
|
+
"chalk": "5.3.0",
|
|
42
|
+
"commander": "12.0.0",
|
|
43
43
|
"deep-keys": "0.5.0",
|
|
44
|
-
"dotenv": "
|
|
45
|
-
"fs-extra": "11.
|
|
46
|
-
"inquirer": "9.
|
|
44
|
+
"dotenv": "16.4.5",
|
|
45
|
+
"fs-extra": "11.2.0",
|
|
46
|
+
"inquirer": "9.2.15",
|
|
47
47
|
"lodash": "4.17.21",
|
|
48
|
-
"openai": "^3.1.0",
|
|
49
48
|
"replace": "1.2.2"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@commitlint/cli": "
|
|
53
|
-
"@commitlint/config-conventional": "
|
|
54
|
-
"@semantic-release/commit-analyzer": "
|
|
51
|
+
"@commitlint/cli": "18.6.1",
|
|
52
|
+
"@commitlint/config-conventional": "18.6.2",
|
|
53
|
+
"@semantic-release/commit-analyzer": "11.1.0",
|
|
55
54
|
"@semantic-release/git": "10.0.1",
|
|
56
|
-
"@semantic-release/github": "
|
|
57
|
-
"@semantic-release/npm": "
|
|
58
|
-
"@semantic-release/release-notes-generator": "
|
|
59
|
-
"eslint": "8.
|
|
55
|
+
"@semantic-release/github": "9.2.6",
|
|
56
|
+
"@semantic-release/npm": "11.0.2",
|
|
57
|
+
"@semantic-release/release-notes-generator": "12.1.0",
|
|
58
|
+
"eslint": "8.57.0",
|
|
60
59
|
"eslint-config-airbnb-base": "15.0.0",
|
|
61
|
-
"eslint-config-prettier": "
|
|
62
|
-
"eslint-plugin-prettier": "
|
|
63
|
-
"husky": "
|
|
64
|
-
"prettier": "2.
|
|
65
|
-
"pretty-quick": "
|
|
66
|
-
"semantic-release": "
|
|
60
|
+
"eslint-config-prettier": "9.1.0",
|
|
61
|
+
"eslint-plugin-prettier": "5.1.3",
|
|
62
|
+
"husky": "9.0.11",
|
|
63
|
+
"prettier": "3.2.5",
|
|
64
|
+
"pretty-quick": "4.0.0",
|
|
65
|
+
"semantic-release": "23.0.2"
|
|
67
66
|
},
|
|
68
67
|
"prettier": {
|
|
69
68
|
"singleQuote": true,
|
|
@@ -90,7 +89,14 @@
|
|
|
90
89
|
"commitlint": {
|
|
91
90
|
"extends": [
|
|
92
91
|
"@commitlint/config-conventional"
|
|
93
|
-
]
|
|
92
|
+
],
|
|
93
|
+
"rules": {
|
|
94
|
+
"body-max-line-length": [
|
|
95
|
+
0,
|
|
96
|
+
"always",
|
|
97
|
+
200
|
|
98
|
+
]
|
|
99
|
+
}
|
|
94
100
|
},
|
|
95
101
|
"eslintConfig": {
|
|
96
102
|
"extends": [
|
package/readme.md
CHANGED
|
@@ -22,7 +22,7 @@ You can also watch an excellent [video](https://www.youtube.com/watch?v=NEvnt3MW
|
|
|
22
22
|
- [Custom component templates](#custom-component-templates)
|
|
23
23
|
- [Custom component directory](#custom-component-directory)
|
|
24
24
|
- [Custom component files](#custom-component-files)
|
|
25
|
-
- [OpenAi integration (Alpha release)](#openai-integration-alpha-release)
|
|
25
|
+
- [OpenAi integration (Alpha release)](https://github.com/arminbro/generate-react-cli/tree/alpha?tab=readme-ov-file#openai-integration-alpha-release)
|
|
26
26
|
|
|
27
27
|
## You can run it using npx like this:
|
|
28
28
|
|
|
@@ -180,15 +180,6 @@ Otherwise, if you don't pass any options, it will just use the default values th
|
|
|
180
180
|
<td width="20%">String</td>
|
|
181
181
|
<td width="20%"><code>null</code></td>
|
|
182
182
|
</tr>
|
|
183
|
-
|
|
184
|
-
<tr>
|
|
185
|
-
<td width="20%"><b>--describe</b></td>
|
|
186
|
-
<td width="60%">
|
|
187
|
-
Describe the component you're trying to generate, and OpenAI will do its best to render it following your instructions.
|
|
188
|
-
</td>
|
|
189
|
-
<td width="20%">String</td>
|
|
190
|
-
<td width="20%"><code>null<code></td>
|
|
191
|
-
</tr>
|
|
192
183
|
</table>
|
|
193
184
|
|
|
194
185
|
### Custom component types
|
|
@@ -486,106 +477,6 @@ You should also see that we added `index` and `storyStyle` to our `customTemplat
|
|
|
486
477
|
|
|
487
478
|
Also, we used the `TemplateName` keyword for the `storyStyle` custom file. GRC will generate this corresponding file and replace `TemplateName` with the component name.
|
|
488
479
|
|
|
489
|
-
## OpenAI integration (Alpha release)
|
|
490
|
-
|
|
491
|
-
Well, the time has come to incorporate OpenAI with GRC.
|
|
492
|
-
|
|
493
|
-
I had a chance to experiment with OpenAI's latest GPT-3 natural language model, and I was super impressed by its capabilities. You can read more about OpenAI by visiting their site: https://openai.com/.
|
|
494
|
-
|
|
495
|
-
If you've been using GRC, you already know about its component generation capabilities using its internal templates or the custom ones you provide.
|
|
496
|
-
|
|
497
|
-
With the help of OpenAI, we can now generate our components intelligently by describing them using the new `--describe` flag, or `-d` for short.
|
|
498
|
-
|
|
499
|
-
The plan for this alpha integration will start simple, but I have a few good ideas coming in the near future (and I'm hoping to hear some of yours) on how we can use OpenAI with GRC to improve the developer experience.
|
|
500
|
-
|
|
501
|
-
Please remember that this release is still early, and you will run into bugs. So, please report any bugs or issues [here](https://github.com/arminbro/generate-react-cli/issues).
|
|
502
|
-
|
|
503
|
-
### Okay, let's get started.
|
|
504
|
-
|
|
505
|
-
1. If you don't have one, you must create an OpenAI account: https://openai.com/api/.
|
|
506
|
-
2. You'll need to obtain a secret API key from OpenAI. You can do so by visiting https://beta.openai.com/account/api-keys.
|
|
507
|
-
3. Once you have your API key, you'll need to create a `.env.local` file in your react project and store it as a variable as `OPENAI_API_KEY`. Please be sure not to share the key or push it to version control, as it is private.
|
|
508
|
-
|
|
509
|
-
GRC will pass the key to OpenAI to communicate with the API on your behalf. You will see the usage reflected on your OpenAI account here: https://beta.openai.com/account/usage.
|
|
510
|
-
|
|
511
|
-
GRC uses the DaVinci language model, so you can check out their pricing here: https://openai.com/api/pricing/.
|
|
512
|
-
|
|
513
|
-
Let's generate our first component using OpenAI:
|
|
514
|
-
|
|
515
|
-
```sh
|
|
516
|
-
npx generate-react-cli@alpha c Counter -d "Create a counter component that increments by one when I click on the increment button"
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
GRC should have created a Counter component that looks something like this 🤯:
|
|
520
|
-
|
|
521
|
-
```jsx
|
|
522
|
-
import React, { useState } from 'react';
|
|
523
|
-
import PropTypes from 'prop-types';
|
|
524
|
-
import './Counter.css';
|
|
525
|
-
|
|
526
|
-
const Counter = () => {
|
|
527
|
-
const [count, setCount] = useState(0);
|
|
528
|
-
|
|
529
|
-
return (
|
|
530
|
-
<div className="Counter" data-testid="Counter">
|
|
531
|
-
<h2> The count is: {count} </h2>
|
|
532
|
-
<button onClick={() => setCount(count + 1)}>Increment</button>
|
|
533
|
-
</div>
|
|
534
|
-
);
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
Counter.propTypes = {};
|
|
538
|
-
|
|
539
|
-
Counter.defaultProps = {};
|
|
540
|
-
|
|
541
|
-
export default Counter;
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
OpenAI will do its best to generate the component following the instructions provided in the `--describe` flag while using the patterns supplied from the internal or custom component templates.
|
|
545
|
-
|
|
546
|
-
Okay, let's try another one.
|
|
547
|
-
|
|
548
|
-
```sh
|
|
549
|
-
npx generate-react-cli@alpha c GlobalNav -d "Create a navbar component with 1 logo named 'GRC' and 3 links: 'Home', 'About', 'Contact'"
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
and here's the output in src/components/GlobalNav/GlobalNav.js:
|
|
553
|
-
|
|
554
|
-
```jsx
|
|
555
|
-
import React from 'react';
|
|
556
|
-
import PropTypes from 'prop-types';
|
|
557
|
-
import './GlobalNav.css';
|
|
558
|
-
|
|
559
|
-
const GlobalNav = () => (
|
|
560
|
-
<div className="GlobalNav" data-testid="GlobalNav">
|
|
561
|
-
<a href="#">GRC</a>
|
|
562
|
-
<ul>
|
|
563
|
-
<li>
|
|
564
|
-
<a href="#">Home</a>
|
|
565
|
-
</li>
|
|
566
|
-
<li>
|
|
567
|
-
<a href="#">About</a>
|
|
568
|
-
</li>
|
|
569
|
-
<li>
|
|
570
|
-
<a href="#">Contact</a>
|
|
571
|
-
</li>
|
|
572
|
-
</ul>
|
|
573
|
-
</div>
|
|
574
|
-
);
|
|
575
|
-
|
|
576
|
-
GlobalNav.propTypes = {};
|
|
577
|
-
|
|
578
|
-
GlobalNav.defaultProps = {};
|
|
579
|
-
|
|
580
|
-
export default GlobalNav;
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
That's a wrap. I hope this integration will allow us to generate React components more efficiently, and we can still go in and make the necessary adjustments.
|
|
584
|
-
|
|
585
|
-
Again, please provide any feedback if you have any, and I would love to see some of the components that you generate with GRC+OpenAI.
|
|
586
|
-
|
|
587
|
-
Please share them with me on Twitter [@arminbro](https://twitter.com/arminbro).
|
|
588
|
-
|
|
589
480
|
## License
|
|
590
481
|
|
|
591
482
|
Generate React CLI is an open source software [licensed as MIT](https://github.com/arminbro/generate-react-cli/blob/master/LICENSE).
|
|
@@ -7,7 +7,6 @@ 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';
|
|
11
10
|
import componentJsTemplate from '../templates/component/componentJsTemplate.js';
|
|
12
11
|
import componentTsTemplate from '../templates/component/componentTsTemplate.js';
|
|
13
12
|
import componentCssTemplate from '../templates/component/componentCssTemplate.js';
|
|
@@ -493,26 +492,6 @@ export function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
493
492
|
});
|
|
494
493
|
}
|
|
495
494
|
|
|
496
|
-
// Generate component with openAi, if component description is provided
|
|
497
|
-
|
|
498
|
-
if (cmd.describe && componentFileType === buildInComponentFileTypes.COMPONENT) {
|
|
499
|
-
aiComponentGenerator(template, cmd.describe)
|
|
500
|
-
.then((aiGeneratedComponent) => {
|
|
501
|
-
// @ts-ignore
|
|
502
|
-
outputFileSync(componentPath, aiGeneratedComponent.trim());
|
|
503
|
-
console.log(
|
|
504
|
-
chalk.green(`OpenAI Successfully created the ${filename} component with the provided description.`)
|
|
505
|
-
);
|
|
506
|
-
})
|
|
507
|
-
.catch((error) =>
|
|
508
|
-
console.log(
|
|
509
|
-
chalk.red(`OpenAI failed to create the ${filename} component with the provided description.`, error)
|
|
510
|
-
)
|
|
511
|
-
);
|
|
512
|
-
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
495
|
console.log(chalk.green(`${filename} was successfully created at ${componentPath}`));
|
|
517
496
|
} catch (error) {
|
|
518
497
|
console.error(chalk.red(`${filename} failed and was not created.`));
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Configuration, OpenAIApi } from 'openai';
|
|
2
|
-
|
|
3
|
-
export async function aiComponentGenerator(componentTemplate, prompt) {
|
|
4
|
-
const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY });
|
|
5
|
-
const openAiApi = new OpenAIApi(configuration);
|
|
6
|
-
|
|
7
|
-
const generatedComponent = await openAiApi.createCompletion({
|
|
8
|
-
model: 'text-davinci-003',
|
|
9
|
-
prompt: `Create a React component using this template "${componentTemplate}", but make the adjustments needed with these instructions as follows "${prompt}"`,
|
|
10
|
-
temperature: 0.7,
|
|
11
|
-
max_tokens: 2000,
|
|
12
|
-
top_p: 1.0,
|
|
13
|
-
frequency_penalty: 0.0,
|
|
14
|
-
presence_penalty: 1,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return generatedComponent.data.choices[0].text;
|
|
18
|
-
}
|