generate-react-cli 8.2.0 → 8.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": "8.2.0",
3
+ "version": "8.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",
@@ -0,0 +1,5 @@
1
+ export default `import styled from 'styled-components';
2
+
3
+ export const TemplateNameWrapper = styled.div\`
4
+ \`;
5
+ `;
@@ -11,6 +11,7 @@ import { aiComponentGenerator } 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';
14
+ import componentStyledTemplate from '../templates/component/componentStyledTemplate.js';
14
15
  import componentLazyTemplate from '../templates/component/componentLazyTemplate.js';
15
16
  import componentTsLazyTemplate from '../templates/component/componentTsLazyTemplate.js';
16
17
  import componentStoryTemplate from '../templates/component/componentStoryTemplate.js';
@@ -81,7 +82,7 @@ Please make sure you're pointing to the right custom template path in your gener
81
82
  }
82
83
 
83
84
  function componentTemplateGenerator({ cmd, componentName, cliConfigFile }) {
84
- const { cssPreprocessor, testLibrary, usesCssModule, usesTypeScript } = cliConfigFile;
85
+ const { usesStyledComponents, cssPreprocessor, testLibrary, usesCssModule, usesTypeScript } = cliConfigFile;
85
86
  const { customTemplates } = cliConfigFile.component[cmd.type];
86
87
  let template = null;
87
88
  let filename = null;
@@ -113,16 +114,27 @@ function componentTemplateGenerator({ cmd, componentName, cliConfigFile }) {
113
114
  // --- If it has a corresponding stylesheet
114
115
 
115
116
  if (cmd.withStyle) {
116
- const module = usesCssModule ? '.module' : '';
117
- const cssPath = `${componentName}${module}.${cssPreprocessor}`;
117
+ if (cliConfigFile.usesStyledComponents) {
118
+ const cssPath = `${componentName}.styled`;
119
+ template = template.replace(
120
+ `import styles from './TemplateName.module.css'`,
121
+ `import { TemplateNameWrapper } from './${cssPath}'`
122
+ );
123
+ template = template.replace(` className={styles.TemplateName}`, '');
124
+ template = template.replace(` <div`, '<TemplateNameWrapper');
125
+ template = template.replace(` </div>`, '</TemplateNameWrapper>');
126
+ } else {
127
+ const module = usesCssModule ? '.module' : '';
128
+ const cssPath = `${componentName}${module}.${cssPreprocessor}`;
118
129
 
119
- // --- If the css module is true make sure to update the template accordingly
130
+ // --- If the css module is true make sure to update the template accordingly
120
131
 
121
- if (module.length) {
122
- template = template.replace(`'./TemplateName.module.css'`, `'./${cssPath}'`);
123
- } else {
124
- template = template.replace(`{styles.TemplateName}`, `"${componentName}"`);
125
- template = template.replace(`styles from './TemplateName.module.css'`, `'./${cssPath}'`);
132
+ if (module.length) {
133
+ template = template.replace(`'./TemplateName.module.css'`, `'./${cssPath}'`);
134
+ } else {
135
+ template = template.replace(`{styles.TemplateName}`, `"${componentName}"`);
136
+ template = template.replace(`styles from './TemplateName.module.css'`, `'./${cssPath}'`);
137
+ }
126
138
  }
127
139
  } else {
128
140
  // --- If no stylesheet, remove className attribute and style import from jsTemplate
@@ -157,14 +169,19 @@ function componentStyleTemplateGenerator({ cliConfigFile, cmd, componentName })
157
169
  template = customTemplate;
158
170
  filename = customTemplateFilename;
159
171
  } else {
160
- const { cssPreprocessor, usesCssModule } = cliConfigFile;
161
- const module = usesCssModule ? '.module' : '';
162
- const cssFilename = `${componentName}${module}.${cssPreprocessor}`;
172
+ const { usesTypeScript, usesStyledComponents, cssPreprocessor, usesCssModule } = cliConfigFile;
173
+ if (usesStyledComponents) {
174
+ filename = usesTypeScript ? `${componentName}.styled.ts` : `${componentName}.styled.js`;
175
+ template = componentStyledTemplate;
176
+ } else {
177
+ const module = usesCssModule ? '.module' : '';
178
+ const cssFilename = `${componentName}${module}.${cssPreprocessor}`;
163
179
 
164
- // --- Else use GRC built-in style template
180
+ // --- Else use GRC built-in style template
165
181
 
166
- template = componentCssTemplate;
167
- filename = cssFilename;
182
+ template = componentCssTemplate;
183
+ filename = cssFilename;
184
+ }
168
185
  }
169
186
 
170
187
  return {
@@ -20,12 +20,19 @@ const projectLevelQuestions = [
20
20
  },
21
21
  {
22
22
  type: 'confirm',
23
+ name: 'usesStyledComponents',
24
+ message: 'Does this project use styled-components?',
25
+ },
26
+ {
27
+ type: 'confirm',
28
+ when: (answers) => !answers['usesStyledComponents'],
23
29
  name: 'usesCssModule',
24
30
  message: 'Does this project use CSS modules?',
25
31
  },
26
32
  {
27
33
  type: 'list',
28
34
  name: 'cssPreprocessor',
35
+ when: (answers) => !answers['usesStyledComponents'],
29
36
  message: 'Does this project use a CSS Preprocessor?',
30
37
  choices: ['css', 'scss', 'less', 'styl'],
31
38
  },
@@ -184,7 +191,9 @@ export async function getCLIConfigFile() {
184
191
  */
185
192
 
186
193
  const missingConfigQuestions = grcConfigQuestions.filter(
187
- (question) => !deepKeys(currentConfigFile).includes(question.name)
194
+ (question) =>
195
+ !deepKeys(currentConfigFile).includes(question.name) &&
196
+ (question.when ? question.when(currentConfigFile) : true)
188
197
  );
189
198
 
190
199
  if (missingConfigQuestions.length) {