Skip to content

Commit

Permalink
✨ feat: common command component
Browse files Browse the repository at this point in the history
  • Loading branch information
gleisonkz committed May 28, 2022
1 parent ccf5839 commit c1d879e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
47 changes: 47 additions & 0 deletions src/commands/generate/component/common/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { GluegunCommand, GluegunToolbox, strings } from 'gluegun';

import {
getComponentName, getComponentPath, printCreated
} from '../../../../utils/functions.helper';

const COMMAND: GluegunCommand = {
name: 'common',
alias: ['c'],
description: 'cria um componente Angular de tipo Common',
run: async (toolbox: GluegunToolbox) => {
const { parameters, print, prompt, template } = toolbox;
const {
options: { path }
} = parameters;

const componentName = parameters.first ?? (await getComponentName(prompt));
const componentPath = getComponentPath(path, componentName);

template.generate({
template: 'component.template.html.ejs',
target: `${componentPath}.component.html`,
props: { name: componentName, ...strings }
});

template.generate({
template: 'component.template.scss.ejs',
target: `${componentPath}.component.scss`
});

template.generate({
template: 'component.template.ts.ejs',
target: `${componentPath}.component.ts`,
props: {
type: 'component',
name: componentName,
...strings
}
});

printCreated(print, `${componentPath}.component.html`);
printCreated(print, `${componentPath}.component.scss`);
printCreated(print, `${componentPath}.component.ts`);
}
};

module.exports = COMMAND;
4 changes: 2 additions & 2 deletions src/utils/functions.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GluegunPrint, GluegunToolbox } from 'gluegun';
import { GluegunPrint, GluegunToolbox, strings } from 'gluegun';
import { Command } from 'gluegun/build/types/domain/command';
import { GluegunAskResponse, GluegunPrompt } from 'gluegun/build/types/toolbox/prompt-types';

Expand Down Expand Up @@ -30,7 +30,7 @@ export async function getComponentName(prompt: GluegunPrompt) {
}
});

return response.componentName;
return strings.kebabCase(response.componentName);
}

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

0 comments on commit c1d879e

Please sign in to comment.