|
| 1 | +import { GluegunCommand, GluegunToolbox } from 'gluegun'; |
| 2 | +import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types'; |
| 3 | + |
| 4 | +import { printCreated } from '../../../../utils/functions.helper'; |
| 5 | + |
| 6 | +const COMMAND: GluegunCommand = { |
| 7 | + name: 'dialog', |
| 8 | + alias: ['d'], |
| 9 | + description: 'cria um componente Angular de tipo Dialog', |
| 10 | + run: async (toolbox: GluegunToolbox) => { |
| 11 | + const { parameters, print, prompt, template, strings } = toolbox; |
| 12 | + |
| 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); |
| 33 | + |
| 34 | + template.generate({ |
| 35 | + template: 'component.template.html.ejs', |
| 36 | + target: `./${componentNameKebab}/${componentNameKebab}.dialog.html`, |
| 37 | + props: { name: componentNameKebab, ...strings } |
| 38 | + }); |
| 39 | + |
| 40 | + template.generate({ |
| 41 | + template: 'component.template.ts.ejs', |
| 42 | + target: `./${componentNameKebab}/${componentNameKebab}.dialog.ts`, |
| 43 | + props: { |
| 44 | + type: 'dialog', |
| 45 | + name: componentName, |
| 46 | + ...strings |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + template.generate({ |
| 51 | + template: 'component.template.scss.ejs', |
| 52 | + target: `./${componentNameKebab}/${componentNameKebab}.dialog.scss` |
| 53 | + }); |
| 54 | + |
| 55 | + printCreated(print, `${componentNameKebab}/${componentNameKebab}.dialog.html`); |
| 56 | + printCreated(print, `${componentNameKebab}/${componentNameKebab}.dialog.ts`); |
| 57 | + printCreated(print, `${componentNameKebab}/${componentNameKebab}.dialog.scss`); |
| 58 | + } |
| 59 | +}; |
| 60 | + |
| 61 | +module.exports = COMMAND; |
0 commit comments