generate-react-cli 7.2.0 → 7.4.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.2.0",
3
+ "version": "7.4.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": "^18.0.0"
63
+ "semantic-release": "^19.0.3"
64
64
  },
65
65
  "prettier": {
66
66
  "singleQuote": true,
package/readme.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Generate React CLI
2
2
 
3
- [![dependencies](https://david-dm.org/arminbro/generate-react-cli.svg)](https://david-dm.org/arminbro/generate-react-cli)
4
3
  [![License](https://img.shields.io/npm/l/express.svg)](https://github.com/arminbro/generate-react-cli/blob/master/LICENSE)
5
4
 
6
5
  <p align="center">
@@ -13,7 +12,7 @@ To help speed up productivity in React projects and stop copying, pasting, and r
13
12
 
14
13
  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
14
 
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).
15
+ 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
16
 
18
17
  **_A few notes:_**
19
18
 
@@ -159,6 +158,14 @@ Otherwise, if you don't pass any options, it will just use the default values th
159
158
  <td width="20%">Boolean</td>
160
159
  <td width="20%"><code>false<code></td>
161
160
  </tr>
161
+ <tr>
162
+ <td width="20%"><b>--flat</b></td>
163
+ <td width="60%">
164
+ Generate the files in the mentioned path insted of creating new folder for it
165
+ </td>
166
+ <td width="20%">Boolean</td>
167
+ <td width="20%"><code>false<code></td>
168
+ </tr>
162
169
  </table>
163
170
 
164
171
  ### Custom component types:
@@ -231,16 +238,7 @@ There is an optional `customTemplates` object that you can pass to the `componen
231
238
  },
232
239
  ```
233
240
 
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 |
241
+ 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
242
 
245
243
  #### Example of using the `customTemplates` object within your generate-react-cli.json config file:
246
244
 
@@ -296,7 +294,16 @@ const TemplateName = () => (
296
294
  export default TemplateName;
297
295
  ```
298
296
 
299
- **Important** - Make sure to use the `TemplateName` keyword in your templates as well. GRC will also use this keyword to replace it with your component name.
297
+ **Important** - You can also use the following keywords within your custom templates to format the component name in your templates accordingly:
298
+
299
+ | Keyword | Replacement |
300
+ | --------------- | ---------------------------------------------------------------------------------------------- |
301
+ | `templatename` | component name in raw case (whichever format the user typed the component name in the command) |
302
+ | `TemplateName` | component name in PascalCase |
303
+ | `templateName` | component name in camelCase |
304
+ | `template-name` | component name in kebab-case |
305
+ | `template_name` | component name in snake_case |
306
+ | `TEMPLATE_NAME` | component name in uppercase SNAKE_CASE |
300
307
 
301
308
  #### Example of a custom test template file:
302
309
 
@@ -315,6 +322,7 @@ it('It should mount', () => {
315
322
  ```
316
323
 
317
324
  ### Custom component files
325
+
318
326
  GRC comes with corresponding built-in files for a given component if you need them (i.e., `withStyle`, `withTest`, `withStory`, and `withLazy`).
319
327
 
320
328
  What if you wanted to add custom files of your own?
@@ -358,7 +366,8 @@ export { default } from './TemplateName';
358
366
  ```css
359
367
  /* templates/default/TemplateName.stories.css */
360
368
 
361
- .TemplateName {}
369
+ .TemplateName {
370
+ }
362
371
  ```
363
372
 
364
373
  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,
@@ -20,7 +18,8 @@ function initGenerateComponentCommand(args, cliConfigFile, program) {
20
18
  '--type <type>',
21
19
  'You can pass a component type that you have configured in your GRC config file.',
22
20
  'default'
23
- );
21
+ )
22
+ .option('-f, --flat', 'Generate the files in the mentioned path insted of creating new folder for it', false);
24
23
 
25
24
  // Dynamic component command option defaults.
26
25
 
@@ -34,12 +33,12 @@ function initGenerateComponentCommand(args, cliConfigFile, program) {
34
33
  );
35
34
  });
36
35
 
37
- componentCommand.option('--dry-run', 'Show what will be generated without writing to disk')
36
+ componentCommand.option('--dry-run', 'Show what will be generated without writing to disk');
38
37
 
39
38
  // Component command action.
40
39
 
41
40
  componentCommand.action((componentNames, cmd) =>
42
- componentNames.forEach((componentName) => generateComponent(upperFirst(componentName), cmd, cliConfigFile))
41
+ componentNames.forEach((componentName) => generateComponent(componentName, cmd, cliConfigFile))
43
42
  );
44
43
  }
45
44
 
@@ -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');
@@ -127,7 +127,7 @@ function componentTemplateGenerator({ cmd, componentName, cliConfigFile }) {
127
127
  }
128
128
 
129
129
  return {
130
- componentPath: `${cmd.path}/${componentName}/${filename}`,
130
+ componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
131
131
  filename,
132
132
  template,
133
133
  };
@@ -162,7 +162,7 @@ function componentStyleTemplateGenerator({ cliConfigFile, cmd, componentName })
162
162
  }
163
163
 
164
164
  return {
165
- componentPath: `${cmd.path}/${componentName}/${filename}`,
165
+ componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
166
166
  filename,
167
167
  template,
168
168
  };
@@ -201,7 +201,7 @@ function componentTestTemplateGenerator({ cliConfigFile, cmd, componentName }) {
201
201
  }
202
202
 
203
203
  return {
204
- componentPath: `${cmd.path}/${componentName}/${filename}`,
204
+ componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
205
205
  filename,
206
206
  template,
207
207
  };
@@ -233,7 +233,7 @@ function componentStoryTemplateGenerator({ cliConfigFile, cmd, componentName })
233
233
  }
234
234
 
235
235
  return {
236
- componentPath: `${cmd.path}/${componentName}/${filename}`,
236
+ componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
237
237
  filename,
238
238
  template,
239
239
  };
@@ -265,7 +265,7 @@ function componentLazyTemplateGenerator({ cmd, componentName, cliConfigFile }) {
265
265
  }
266
266
 
267
267
  return {
268
- componentPath: `${cmd.path}/${componentName}/${filename}`,
268
+ componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
269
269
  filename,
270
270
  template,
271
271
  };
@@ -303,7 +303,7 @@ Please make sure you're pointing to the right custom template path in your gener
303
303
  filename = customTemplateFilename;
304
304
 
305
305
  return {
306
- componentPath: `${cmd.path}/${componentName}/${filename}`,
306
+ componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
307
307
  filename,
308
308
  template,
309
309
  };
@@ -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: 'TemplateName',
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