generate-react-cli 7.2.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
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",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"husky": "^7.0.4",
|
|
61
61
|
"prettier": "2.5.1",
|
|
62
62
|
"pretty-quick": "^3.1.3",
|
|
63
|
-
"semantic-release": "^
|
|
63
|
+
"semantic-release": "^19.0.3"
|
|
64
64
|
},
|
|
65
65
|
"prettier": {
|
|
66
66
|
"singleQuote": true,
|
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,16 +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 |
|
|
243
|
-
| `TEMPLATE_NAME` | component name in uppercase 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.
|
|
244
235
|
|
|
245
236
|
#### Example of using the `customTemplates` object within your generate-react-cli.json config file:
|
|
246
237
|
|
|
@@ -296,7 +287,16 @@ const TemplateName = () => (
|
|
|
296
287
|
export default TemplateName;
|
|
297
288
|
```
|
|
298
289
|
|
|
299
|
-
**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 |
|
|
300
300
|
|
|
301
301
|
#### Example of a custom test template file:
|
|
302
302
|
|
|
@@ -315,6 +315,7 @@ it('It should mount', () => {
|
|
|
315
315
|
```
|
|
316
316
|
|
|
317
317
|
### Custom component files
|
|
318
|
+
|
|
318
319
|
GRC comes with corresponding built-in files for a given component if you need them (i.e., `withStyle`, `withTest`, `withStory`, and `withLazy`).
|
|
319
320
|
|
|
320
321
|
What if you wanted to add custom files of your own?
|
|
@@ -358,7 +359,8 @@ export { default } from './TemplateName';
|
|
|
358
359
|
```css
|
|
359
360
|
/* templates/default/TemplateName.stories.css */
|
|
360
361
|
|
|
361
|
-
.TemplateName {
|
|
362
|
+
.TemplateName {
|
|
363
|
+
}
|
|
362
364
|
```
|
|
363
365
|
|
|
364
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),
|
|
@@ -390,6 +403,7 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
390
403
|
silent: true,
|
|
391
404
|
});
|
|
392
405
|
|
|
406
|
+
// Will replace the TEMPLATE_NAME in uppercase SNAKE_CASE
|
|
393
407
|
replace({
|
|
394
408
|
regex: 'TEMPLATE_NAME',
|
|
395
409
|
replacement: snakeCase(componentName).toUpperCase(),
|
|
@@ -409,8 +423,8 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
409
423
|
});
|
|
410
424
|
|
|
411
425
|
if (cmd.dryRun) {
|
|
412
|
-
console.log()
|
|
413
|
-
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.`));
|
|
414
428
|
}
|
|
415
429
|
}
|
|
416
430
|
|