Skip to content

Commit f2b0847

Browse files
committed
Check for the JSON property within the generation rather than utils
1 parent 4efe51c commit f2b0847

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/commands/generateComponent.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export default function initGenerateComponentCommand(args, cliConfigFile, progra
2424
'Describe the component you want GRC to generate (e.g., Create a counter component that increments by one when I click on the increment button).',
2525
null
2626
)
27-
.option('-f, --flat', 'Generate the files in the mentioned path insted of creating new folder for it', false)
27+
.option(
28+
'-f, --flat',
29+
'Generate the files in the mentioned path instead of creating new folder for it',
30+
selectedComponentType.flat || false
31+
)
2832
.option('-dr, --dry-run', 'Show what will be generated without writing to disk');
2933

3034
// Dynamic component command option defaults.

src/utils/generateComponentUtils.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ Please make sure you're pointing to the right custom template path in your gener
8282

8383
function componentTemplateGenerator({ cmd, componentName, cliConfigFile }) {
8484
const { cssPreprocessor, testLibrary, usesCssModule, usesTypeScript } = cliConfigFile;
85-
const { customTemplates, flat } = cliConfigFile.component[cmd.type];
85+
const { customTemplates } = cliConfigFile.component[cmd.type];
8686
let template = null;
8787
let filename = null;
88-
const isFlat = flat || cmd.flat;
8988

9089
// Check for a custom component template.
9190

@@ -134,17 +133,16 @@ function componentTemplateGenerator({ cmd, componentName, cliConfigFile }) {
134133
}
135134

136135
return {
137-
componentPath: `${cmd.path}${isFlat ? '' : `/${componentName}`}/${filename}`,
136+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
138137
filename,
139138
template,
140139
};
141140
}
142141

143142
function componentStyleTemplateGenerator({ cliConfigFile, cmd, componentName }) {
144-
const { customTemplates, flat } = cliConfigFile.component[cmd.type];
143+
const { customTemplates } = cliConfigFile.component[cmd.type];
145144
let template = null;
146145
let filename = null;
147-
const isFlat = flat || cmd.flat;
148146

149147
// Check for a custom style template.
150148

@@ -170,18 +168,17 @@ function componentStyleTemplateGenerator({ cliConfigFile, cmd, componentName })
170168
}
171169

172170
return {
173-
componentPath: `${cmd.path}${isFlat ? '' : `/${componentName}`}/${filename}`,
171+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
174172
filename,
175173
template,
176174
};
177175
}
178176

179177
function componentTestTemplateGenerator({ cliConfigFile, cmd, componentName }) {
180-
const { customTemplates, flat } = cliConfigFile.component[cmd.type];
178+
const { customTemplates } = cliConfigFile.component[cmd.type];
181179
const { testLibrary, usesTypeScript } = cliConfigFile;
182180
let template = null;
183181
let filename = null;
184-
const isFlat = flat || cmd.flat;
185182

186183
// Check for a custom test template.
187184

@@ -210,18 +207,17 @@ function componentTestTemplateGenerator({ cliConfigFile, cmd, componentName }) {
210207
}
211208

212209
return {
213-
componentPath: `${cmd.path}${isFlat ? '' : `/${componentName}`}/${filename}`,
210+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
214211
filename,
215212
template,
216213
};
217214
}
218215

219216
function componentStoryTemplateGenerator({ cliConfigFile, cmd, componentName }) {
220217
const { usesTypeScript } = cliConfigFile;
221-
const { customTemplates, flat } = cliConfigFile.component[cmd.type];
218+
const { customTemplates } = cliConfigFile.component[cmd.type];
222219
let template = null;
223220
let filename = null;
224-
const isFlat = flat || cmd.flat;
225221

226222
// Check for a custom story template.
227223

@@ -243,18 +239,17 @@ function componentStoryTemplateGenerator({ cliConfigFile, cmd, componentName })
243239
}
244240

245241
return {
246-
componentPath: `${cmd.path}${isFlat ? '' : `/${componentName}`}/${filename}`,
242+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
247243
filename,
248244
template,
249245
};
250246
}
251247

252248
function componentLazyTemplateGenerator({ cmd, componentName, cliConfigFile }) {
253249
const { usesTypeScript } = cliConfigFile;
254-
const { customTemplates, flat } = cliConfigFile.component[cmd.type];
250+
const { customTemplates } = cliConfigFile.component[cmd.type];
255251
let template = null;
256252
let filename = null;
257-
const isFlat = flat || cmd.flat;
258253

259254
// Check for a custom lazy template.
260255

@@ -276,18 +271,17 @@ function componentLazyTemplateGenerator({ cmd, componentName, cliConfigFile }) {
276271
}
277272

278273
return {
279-
componentPath: `${cmd.path}${isFlat ? '' : `/${componentName}`}/${filename}`,
274+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
280275
filename,
281276
template,
282277
};
283278
}
284279

285280
function customFileTemplateGenerator({ componentName, cmd, cliConfigFile, componentFileType }) {
286-
const { customTemplates, flat } = cliConfigFile.component[cmd.type];
281+
const { customTemplates } = cliConfigFile.component[cmd.type];
287282
const fileType = camelCase(componentFileType.split('with')[1]);
288283
let filename = null;
289284
let template = null;
290-
const isFlat = flat || cmd.flat;
291285

292286
// Check for a valid custom template for the corresponding custom component file.
293287

@@ -315,7 +309,7 @@ Please make sure you're pointing to the right custom template path in your gener
315309
filename = customTemplateFilename;
316310

317311
return {
318-
componentPath: `${cmd.path}${isFlat ? '' : `/${componentName}`}/${filename}`,
312+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
319313
filename,
320314
template,
321315
};

0 commit comments

Comments
 (0)