generate-react-cli 7.1.0 → 7.3.0
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 +56 -10
- package/readme.md +15 -12
- package/src/commands/generateComponent.js +2 -4
- package/src/utils/generateComponentUtils.js +26 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-react-cli",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
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",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"maintained node versions"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"
|
|
38
|
-
"release": "standard-version"
|
|
37
|
+
"prepare": "husky install"
|
|
39
38
|
},
|
|
40
39
|
"dependencies": {
|
|
41
40
|
"chalk": "^4.1.2",
|
|
@@ -47,18 +46,65 @@
|
|
|
47
46
|
"replace": "^1.2.0"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
|
-
"
|
|
49
|
+
"@commitlint/cli": "^13.2.1",
|
|
50
|
+
"@commitlint/config-conventional": "^13.2.0",
|
|
51
|
+
"@semantic-release/commit-analyzer": "^9.0.1",
|
|
52
|
+
"@semantic-release/git": "^10.0.0",
|
|
53
|
+
"@semantic-release/github": "^8.0.1",
|
|
54
|
+
"@semantic-release/npm": "^8.0.0",
|
|
55
|
+
"@semantic-release/release-notes-generator": "^10.0.2",
|
|
51
56
|
"eslint": "^8.7.0",
|
|
52
57
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
53
58
|
"eslint-config-prettier": "^8.3.0",
|
|
54
59
|
"eslint-plugin-prettier": "^4.0.0",
|
|
60
|
+
"husky": "^7.0.4",
|
|
55
61
|
"prettier": "2.5.1",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
62
|
+
"pretty-quick": "^3.1.3",
|
|
63
|
+
"semantic-release": "^19.0.3"
|
|
58
64
|
},
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
"prettier": {
|
|
66
|
+
"singleQuote": true,
|
|
67
|
+
"trailingComma": "es5",
|
|
68
|
+
"printWidth": 120
|
|
69
|
+
},
|
|
70
|
+
"release": {
|
|
71
|
+
"branches": [
|
|
72
|
+
"main"
|
|
73
|
+
],
|
|
74
|
+
"plugins": [
|
|
75
|
+
"@semantic-release/commit-analyzer",
|
|
76
|
+
"@semantic-release/release-notes-generator",
|
|
77
|
+
"@semantic-release/npm",
|
|
78
|
+
[
|
|
79
|
+
"@semantic-release/git",
|
|
80
|
+
{
|
|
81
|
+
"assets": [
|
|
82
|
+
"package.json"
|
|
83
|
+
],
|
|
84
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"@semantic-release/github"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"commitlint": {
|
|
91
|
+
"extends": [
|
|
92
|
+
"@commitlint/config-conventional"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"eslintConfig": {
|
|
96
|
+
"extends": [
|
|
97
|
+
"airbnb-base",
|
|
98
|
+
"plugin:prettier/recommended"
|
|
99
|
+
],
|
|
100
|
+
"env": {
|
|
101
|
+
"commonjs": true,
|
|
102
|
+
"es2021": true,
|
|
103
|
+
"node": true
|
|
104
|
+
},
|
|
105
|
+
"parserOptions": {
|
|
106
|
+
"ecmaVersion": 12
|
|
107
|
+
},
|
|
108
|
+
"rules": {}
|
|
63
109
|
}
|
|
64
110
|
}
|
package/readme.md
CHANGED
|
@@ -13,7 +13,7 @@ To help speed up productivity in React projects and stop copying, pasting, and r
|
|
|
13
13
|
|
|
14
14
|
A short [article](https://dev.to/arminbro/generate-react-cli-1ooh) that goes a little deeper into why we created GRC if you have the time.
|
|
15
15
|
|
|
16
|
-
Suppose you enjoy learning by watching tutorial videos. Here's an excellent [video](https://www.youtube.com/watch?v=NEvnt3MWttY) on how to use GRC by [Eric Murphy](https://www.youtube.com/channel/UC5KDiSAFxrDWhmysBcNqtMA).
|
|
16
|
+
Suppose you enjoy learning by watching tutorial videos. Here's an excellent [video](https://www.youtube.com/watch?v=NEvnt3MWttY) on how to use GRC by [Eric Murphy](https://www.youtube.com/channel/UC5KDiSAFxrDWhmysBcNqtMA).
|
|
17
17
|
|
|
18
18
|
**_A few notes:_**
|
|
19
19
|
|
|
@@ -231,15 +231,7 @@ There is an optional `customTemplates` object that you can pass to the `componen
|
|
|
231
231
|
},
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
The keys represent the type of file, and the values are the paths that point to where your custom template lives in your project/system. Please note the `TemplateName` keyword in the template filename. GRC will use this keyword and replace it with your component name as the filename.
|
|
235
|
-
|
|
236
|
-
You can also use the following keywords, which will be replaced with their corresponding formatted component name:
|
|
237
|
-
|
|
238
|
-
| Keyword | Replacement |
|
|
239
|
-
|-----------------|------------------------------|
|
|
240
|
-
| `templateName` | component name in camelCase |
|
|
241
|
-
| `template-name` | component name in kebab-case |
|
|
242
|
-
| `template_name` | component name in snake_case |
|
|
234
|
+
The keys represent the type of file, and the values are the paths that point to where your custom template lives in your project/system. Please note the `TemplateName` keyword in the template filename. GRC will use this keyword and replace it with your component name (in whichever format you typed the component name in the command) as the filename.
|
|
243
235
|
|
|
244
236
|
#### Example of using the `customTemplates` object within your generate-react-cli.json config file:
|
|
245
237
|
|
|
@@ -295,7 +287,16 @@ const TemplateName = () => (
|
|
|
295
287
|
export default TemplateName;
|
|
296
288
|
```
|
|
297
289
|
|
|
298
|
-
**Important** -
|
|
290
|
+
**Important** - You can also use the following keywords within your custom templates to format the component name in your templates accordingly:
|
|
291
|
+
|
|
292
|
+
| Keyword | Replacement |
|
|
293
|
+
| --------------- | ---------------------------------------------------------------------------------------------- |
|
|
294
|
+
| `templatename` | component name in raw case (whichever format the user typed the component name in the command) |
|
|
295
|
+
| `TemplateName` | component name in PascalCase |
|
|
296
|
+
| `templateName` | component name in camelCase |
|
|
297
|
+
| `template-name` | component name in kebab-case |
|
|
298
|
+
| `template_name` | component name in snake_case |
|
|
299
|
+
| `TEMPLATE_NAME` | component name in uppercase SNAKE_CASE |
|
|
299
300
|
|
|
300
301
|
#### Example of a custom test template file:
|
|
301
302
|
|
|
@@ -314,6 +315,7 @@ it('It should mount', () => {
|
|
|
314
315
|
```
|
|
315
316
|
|
|
316
317
|
### Custom component files
|
|
318
|
+
|
|
317
319
|
GRC comes with corresponding built-in files for a given component if you need them (i.e., `withStyle`, `withTest`, `withStory`, and `withLazy`).
|
|
318
320
|
|
|
319
321
|
What if you wanted to add custom files of your own?
|
|
@@ -357,7 +359,8 @@ export { default } from './TemplateName';
|
|
|
357
359
|
```css
|
|
358
360
|
/* templates/default/TemplateName.stories.css */
|
|
359
361
|
|
|
360
|
-
.TemplateName {
|
|
362
|
+
.TemplateName {
|
|
363
|
+
}
|
|
361
364
|
```
|
|
362
365
|
|
|
363
366
|
In this case, we added a `withIndex` & `withStoryStyle` to the `component.default`. Note: You can add custom files to any of your custom component types.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const { upperFirst } = require('lodash');
|
|
2
|
-
|
|
3
1
|
const {
|
|
4
2
|
generateComponent,
|
|
5
3
|
getComponentByType,
|
|
@@ -34,12 +32,12 @@ function initGenerateComponentCommand(args, cliConfigFile, program) {
|
|
|
34
32
|
);
|
|
35
33
|
});
|
|
36
34
|
|
|
37
|
-
componentCommand.option('--dry-run', 'Show what will be generated without writing to disk')
|
|
35
|
+
componentCommand.option('--dry-run', 'Show what will be generated without writing to disk');
|
|
38
36
|
|
|
39
37
|
// Component command action.
|
|
40
38
|
|
|
41
39
|
componentCommand.action((componentNames, cmd) =>
|
|
42
|
-
componentNames.forEach((componentName) => generateComponent(
|
|
40
|
+
componentNames.forEach((componentName) => generateComponent(componentName, cmd, cliConfigFile))
|
|
43
41
|
);
|
|
44
42
|
}
|
|
45
43
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const replace = require('replace');
|
|
4
|
-
const { camelCase, kebabCase, snakeCase } = require('lodash');
|
|
4
|
+
const { camelCase, kebabCase, snakeCase, upperFirst } = require('lodash');
|
|
5
5
|
const { existsSync, outputFileSync, readFileSync } = require('fs-extra');
|
|
6
6
|
|
|
7
7
|
const componentJsTemplate = require('../templates/component/componentJsTemplate');
|
|
@@ -358,14 +358,25 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
358
358
|
if (!cmd.dryRun) {
|
|
359
359
|
outputFileSync(componentPath, template);
|
|
360
360
|
|
|
361
|
+
// Will replace the templatename in whichever format the user typed the component name in the command.
|
|
361
362
|
replace({
|
|
362
|
-
regex: '
|
|
363
|
+
regex: 'templatename',
|
|
363
364
|
replacement: componentName,
|
|
364
365
|
paths: [componentPath],
|
|
365
366
|
recursive: false,
|
|
366
367
|
silent: true,
|
|
367
368
|
});
|
|
368
369
|
|
|
370
|
+
// Will replace the TemplateName in PascalCase
|
|
371
|
+
replace({
|
|
372
|
+
regex: 'TemplateName',
|
|
373
|
+
replacement: upperFirst(camelCase(componentName)),
|
|
374
|
+
paths: [componentPath],
|
|
375
|
+
recursive: false,
|
|
376
|
+
silent: true,
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// Will replace the templateName in camelCase
|
|
369
380
|
replace({
|
|
370
381
|
regex: 'templateName',
|
|
371
382
|
replacement: camelCase(componentName),
|
|
@@ -374,6 +385,7 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
374
385
|
silent: true,
|
|
375
386
|
});
|
|
376
387
|
|
|
388
|
+
// Will replace the template-name in kebab-case
|
|
377
389
|
replace({
|
|
378
390
|
regex: 'template-name',
|
|
379
391
|
replacement: kebabCase(componentName),
|
|
@@ -382,6 +394,7 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
382
394
|
silent: true,
|
|
383
395
|
});
|
|
384
396
|
|
|
397
|
+
// Will replace the template_name in snake_case
|
|
385
398
|
replace({
|
|
386
399
|
regex: 'template_name',
|
|
387
400
|
replacement: snakeCase(componentName),
|
|
@@ -389,6 +402,15 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
389
402
|
recursive: false,
|
|
390
403
|
silent: true,
|
|
391
404
|
});
|
|
405
|
+
|
|
406
|
+
// Will replace the TEMPLATE_NAME in uppercase SNAKE_CASE
|
|
407
|
+
replace({
|
|
408
|
+
regex: 'TEMPLATE_NAME',
|
|
409
|
+
replacement: snakeCase(componentName).toUpperCase(),
|
|
410
|
+
paths: [componentPath],
|
|
411
|
+
recursive: false,
|
|
412
|
+
silent: true,
|
|
413
|
+
});
|
|
392
414
|
}
|
|
393
415
|
|
|
394
416
|
console.log(chalk.green(`${filename} was successfully created at ${componentPath}`));
|
|
@@ -401,8 +423,8 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
401
423
|
});
|
|
402
424
|
|
|
403
425
|
if (cmd.dryRun) {
|
|
404
|
-
console.log()
|
|
405
|
-
console.log(chalk.yellow(`NOTE: The "dry-run" flag means no changes were made.`))
|
|
426
|
+
console.log();
|
|
427
|
+
console.log(chalk.yellow(`NOTE: The "dry-run" flag means no changes were made.`));
|
|
406
428
|
}
|
|
407
429
|
}
|
|
408
430
|
|