Skip to content

Commit d268046

Browse files
committed
✨ feat(cli): support for --path option
1 parent 7b00ac7 commit d268046

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

__tests__/cli.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { filesystem, system } from 'gluegun';
22

33
const src = filesystem.path(__dirname, '..');
44

5-
const cli = async (cmd) =>
6-
system.run('node ' + filesystem.path(src, 'bin', 'ngx-devs-cli') + ` ${cmd}`);
5+
const cli = async (cmd) => system.run('node ' + filesystem.path(src, 'bin', 'ngx-devs-cli') + ` ${cmd}`);
76

87
describe('[CLI]', () => {
98
describe('[Commands: generate page component]', () => {
@@ -45,6 +44,23 @@ describe('[CLI]', () => {
4544
filesystem.remove('sample');
4645
});
4746

47+
test('should generate a widget component on provided path', async () => {
48+
await cli('g c w sample --path=sample-project/components');
49+
50+
const path = 'sample-project/components/sample';
51+
const html = filesystem.read(`${path}/sample.component.html`);
52+
const scss = filesystem.read(`${path}/sample.component.scss`);
53+
const ts = filesystem.read(`${path}/sample.component.ts`);
54+
const widgetModule = filesystem.read('sample-project/components/sample/sample.widget.module.ts');
55+
56+
expect(html).toBeDefined();
57+
expect(scss).toBeDefined();
58+
expect(ts).toBeDefined();
59+
expect(widgetModule).toBeDefined();
60+
61+
filesystem.remove('sample-project');
62+
});
63+
4864
test('should generate widget component with 4 files', async () => {
4965
await cli('g c w sample');
5066

src/commands/generate/component/component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const COMMAND: GluegunCommand = {
77
name: 'component',
88
alias: ['c'],
99
description: 'Cria um componente Angular de tipo específico',
10+
1011
run: async (toolbox: GluegunToolbox) => {
1112
const { parameters, prompt } = toolbox;
1213

src/commands/generate/component/widget/widget.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const COMMAND: GluegunCommand = {
99
description: 'cria um componente Angular do tipo widget',
1010
run: async (toolbox) => {
1111
const { parameters, print, prompt, template } = toolbox;
12+
const {
13+
options: { path }
14+
} = parameters;
15+
1216
let componentName = parameters.first;
1317

1418
if (!componentName) {
@@ -28,20 +32,24 @@ const COMMAND: GluegunCommand = {
2832
componentName = response.componentName;
2933
}
3034

35+
const componentPath = path
36+
? `${path}/${componentName}/${componentName}`
37+
: `./${componentName}/${componentName}`;
38+
3139
template.generate({
3240
template: 'component.template.html.ejs',
33-
target: `./${componentName}/${componentName}.component.html`,
41+
target: `${componentPath}.component.html`,
3442
props: { name: componentName, ...strings }
3543
});
3644

3745
template.generate({
3846
template: 'component.template.scss.ejs',
39-
target: `./${componentName}/${componentName}.component.scss`
47+
target: `${componentPath}.component.scss`
4048
});
4149

4250
template.generate({
4351
template: 'component.template.ts.ejs',
44-
target: `./${componentName}/${componentName}.component.ts`,
52+
target: `${componentPath}.component.ts`,
4553
props: {
4654
type: 'component',
4755
name: componentName,
@@ -51,18 +59,18 @@ const COMMAND: GluegunCommand = {
5159

5260
template.generate({
5361
template: 'widget.module.template.ts.ejs',
54-
target: `./${componentName}/${componentName}.widget.module.ts`,
62+
target: `${componentPath}.widget.module.ts`,
5563
props: {
5664
type: 'component',
5765
name: componentName,
5866
...strings
5967
}
6068
});
6169

62-
printCreated(print, `${componentName}/${componentName}.component.html`);
63-
printCreated(print, `${componentName}/${componentName}.component.ts`);
64-
printCreated(print, `${componentName}/${componentName}.component.scss`);
65-
printCreated(print, `${componentName}/${componentName}.widget.module.ts`);
70+
printCreated(print, `${componentPath}.component.html`);
71+
printCreated(print, `${componentPath}.component.ts`);
72+
printCreated(print, `${componentPath}.component.scss`);
73+
printCreated(print, `${componentPath}.widget.module.ts`);
6674
}
6775
};
6876

0 commit comments

Comments
 (0)