1
- import { GluegunCommand , GluegunToolbox } from 'gluegun' ;
2
- import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types' ;
1
+ import { GluegunCommand , GluegunToolbox , strings } from 'gluegun' ;
3
2
4
- import { printCreated } from '../../../../utils/functions.helper' ;
3
+ import {
4
+ getComponentName , getComponentPath , printCreated
5
+ } from '../../../../utils/functions.helper' ;
5
6
6
7
const COMMAND : GluegunCommand = {
7
8
name : 'dialog' ,
8
9
alias : [ 'd' ] ,
9
10
description : 'cria um componente Angular de tipo Dialog' ,
10
11
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 ;
12
16
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 ) ;
33
19
34
20
template . generate ( {
35
21
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 }
38
24
} ) ;
39
25
40
26
template . generate ( {
41
27
template : 'component.template.ts.ejs' ,
42
- target : `./${ componentNameKebab } / ${ componentNameKebab } .dialog.ts` ,
28
+ target : `./${ componentPath } .dialog.ts` ,
43
29
props : {
44
30
type : 'dialog' ,
45
31
name : componentName ,
@@ -49,12 +35,12 @@ const COMMAND: GluegunCommand = {
49
35
50
36
template . generate ( {
51
37
template : 'component.template.scss.ejs' ,
52
- target : `./${ componentNameKebab } / ${ componentNameKebab } .dialog.scss`
38
+ target : `./${ componentPath } .dialog.scss`
53
39
} ) ;
54
40
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` ) ;
58
44
}
59
45
} ;
60
46
0 commit comments