Skip to content

Commit c1d879e

Browse files
committed
✨ feat: common command component
1 parent ccf5839 commit c1d879e

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { GluegunCommand, GluegunToolbox, strings } from 'gluegun';
2+
3+
import {
4+
getComponentName, getComponentPath, printCreated
5+
} from '../../../../utils/functions.helper';
6+
7+
const COMMAND: GluegunCommand = {
8+
name: 'common',
9+
alias: ['c'],
10+
description: 'cria um componente Angular de tipo Common',
11+
run: async (toolbox: GluegunToolbox) => {
12+
const { parameters, print, prompt, template } = toolbox;
13+
const {
14+
options: { path }
15+
} = parameters;
16+
17+
const componentName = parameters.first ?? (await getComponentName(prompt));
18+
const componentPath = getComponentPath(path, componentName);
19+
20+
template.generate({
21+
template: 'component.template.html.ejs',
22+
target: `${componentPath}.component.html`,
23+
props: { name: componentName, ...strings }
24+
});
25+
26+
template.generate({
27+
template: 'component.template.scss.ejs',
28+
target: `${componentPath}.component.scss`
29+
});
30+
31+
template.generate({
32+
template: 'component.template.ts.ejs',
33+
target: `${componentPath}.component.ts`,
34+
props: {
35+
type: 'component',
36+
name: componentName,
37+
...strings
38+
}
39+
});
40+
41+
printCreated(print, `${componentPath}.component.html`);
42+
printCreated(print, `${componentPath}.component.scss`);
43+
printCreated(print, `${componentPath}.component.ts`);
44+
}
45+
};
46+
47+
module.exports = COMMAND;

src/utils/functions.helper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GluegunPrint, GluegunToolbox } from 'gluegun';
1+
import { GluegunPrint, GluegunToolbox, strings } from 'gluegun';
22
import { Command } from 'gluegun/build/types/domain/command';
33
import { GluegunAskResponse, GluegunPrompt } from 'gluegun/build/types/toolbox/prompt-types';
44

@@ -30,7 +30,7 @@ export async function getComponentName(prompt: GluegunPrompt) {
3030
}
3131
});
3232

33-
return response.componentName;
33+
return strings.kebabCase(response.componentName);
3434
}
3535

3636
export function getComponentPath(path: any, componentName: string) {

0 commit comments

Comments
 (0)