Skip to content

Commit 117b8c8

Browse files
committed
🐛 fix: suport to path parameter on component dialog command
1 parent 14c8824 commit 117b8c8

File tree

1 file changed

+17
-31
lines changed
  • src/commands/generate/component/dialog

1 file changed

+17
-31
lines changed

src/commands/generate/component/dialog/dialog.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,31 @@
1-
import { GluegunCommand, GluegunToolbox } from 'gluegun';
2-
import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types';
1+
import { GluegunCommand, GluegunToolbox, strings } from 'gluegun';
32

4-
import { printCreated } from '../../../../utils/functions.helper';
3+
import {
4+
getComponentName, getComponentPath, printCreated
5+
} from '../../../../utils/functions.helper';
56

67
const COMMAND: GluegunCommand = {
78
name: 'dialog',
89
alias: ['d'],
910
description: 'cria um componente Angular de tipo Dialog',
1011
run: async (toolbox: GluegunToolbox) => {
11-
const { parameters, print, prompt, template, strings } = toolbox;
12+
const { parameters, print, prompt, template } = toolbox;
13+
const {
14+
options: { path }
15+
} = parameters;
1216

13-
let componentName = parameters.first;
14-
15-
if (!componentName) {
16-
const response: GluegunAskResponse = await prompt.ask({
17-
type: 'input',
18-
name: 'componentName',
19-
message: 'Qual o nome do componente?',
20-
validate: (value: string) => {
21-
if (!value) {
22-
return 'O nome do componente não pode ser vazio';
23-
}
24-
25-
return true;
26-
}
27-
});
28-
29-
componentName = response.componentName;
30-
}
31-
32-
const componentNameKebab = strings.kebabCase(componentName);
17+
const componentName = parameters.first ?? (await getComponentName(prompt));
18+
const componentPath = getComponentPath(path, componentName);
3319

3420
template.generate({
3521
template: 'component.template.html.ejs',
36-
target: `./${componentNameKebab}/${componentNameKebab}.dialog.html`,
37-
props: { name: componentNameKebab, ...strings }
22+
target: `./${componentPath}.dialog.html`,
23+
props: { name: componentName, ...strings }
3824
});
3925

4026
template.generate({
4127
template: 'component.template.ts.ejs',
42-
target: `./${componentNameKebab}/${componentNameKebab}.dialog.ts`,
28+
target: `./${componentPath}.dialog.ts`,
4329
props: {
4430
type: 'dialog',
4531
name: componentName,
@@ -49,12 +35,12 @@ const COMMAND: GluegunCommand = {
4935

5036
template.generate({
5137
template: 'component.template.scss.ejs',
52-
target: `./${componentNameKebab}/${componentNameKebab}.dialog.scss`
38+
target: `./${componentPath}.dialog.scss`
5339
});
5440

55-
printCreated(print, `${componentNameKebab}/${componentNameKebab}.dialog.html`);
56-
printCreated(print, `${componentNameKebab}/${componentNameKebab}.dialog.ts`);
57-
printCreated(print, `${componentNameKebab}/${componentNameKebab}.dialog.scss`);
41+
printCreated(print, `${componentPath}.dialog.html`);
42+
printCreated(print, `${componentPath}.dialog.ts`);
43+
printCreated(print, `${componentPath}.dialog.scss`);
5844
}
5945
};
6046

0 commit comments

Comments
 (0)