Skip to content

Commit 5610901

Browse files
committed
✨ feat: page component command
1 parent 5bb5a02 commit 5610901

File tree

15 files changed

+196
-11
lines changed

15 files changed

+196
-11
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.ejs

delpe/delpe.page.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>delpe works</p>

delpe/delpe.page.scss

Whitespace-only changes.

delpe/delpe.page.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
templateUrl: './delpe.page.html',
5+
styleUrls: ['./delpe.page.scss'],
6+
})
7+
export class DelpePage implements OnInit {
8+
constructor() {}
9+
10+
ngOnInit(): void {
11+
}
12+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"prepublishOnly": "npm run build",
1515
"format": "eslint \"**/*.{js,jsx,ts,tsx}\" --fix && prettier \"**/*.{js,jsx,ts,tsx,json}\" --write",
1616
"test": "jest",
17+
"test-watch": "jest --watchAll",
1718
"watch": "jest --watch",
1819
"snapupdate": "jest --updateSnapshot",
1920
"coverage": "jest --coverage"

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# ngx-devs-cli CLI
22

3-
A CLI for ngx-devs-cli.
3+
Uma CLI criada para modernizar, padronizar e facilitar a criação/atualização e gestão de projetos angular.
4+
5+
███╗░░██╗░██████╗░██╗░░██╗░░░░░░██████╗░███████╗██╗░░░██╗░██████╗  ░█████╗░██╗░░░░░██╗
6+
████╗░██║██╔════╝░╚██╗██╔╝░░░░░░██╔══██╗██╔════╝██║░░░██║██╔════╝  ██╔══██╗██║░░░░░██║
7+
██╔██╗██║██║░░██╗░░╚███╔╝░█████╗██║░░██║█████╗░░╚██╗░██╔╝╚█████╗░  ██║░░╚═╝██║░░░░░██║
8+
██║╚████║██║░░╚██╗░██╔██╗░╚════╝██║░░██║██╔══╝░░░╚████╔╝░░╚═══██╗  ██║░░██╗██║░░░░░██║
9+
██║░╚███║╚██████╔╝██╔╝╚██╗░░░░░░██████╔╝███████╗░░╚██╔╝░░██████╔╝  ╚█████╔╝███████╗██║
10+
╚═╝░░╚══╝░╚═════╝░╚═╝░░╚═╝░░░░░░╚═════╝░╚══════╝░░░╚═╝░░░╚═════╝░  ░╚════╝░╚══════╝╚═╝
411

512
## Customizing your CLI
613

@@ -23,4 +30,3 @@ $ npm publish
2330
# License
2431

2532
MIT - see LICENSE
26-

src/cli.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ async function run(argv) {
55
.brand('ngx-devs-cli')
66
.src(__dirname)
77
.plugins('./node_modules', { matching: 'ngx-devs-cli-*', hidden: true })
8-
.version() // provides default for version, v, --version, -v
8+
.version()
9+
.exclude([
10+
'meta',
11+
'filesystem',
12+
'semver',
13+
'system',
14+
'http',
15+
'patching',
16+
'package-manager',
17+
])
918
.create()
10-
// enable the following method if you'd like to skip loading one of these core extensions
11-
// this can improve performance if they're not necessary for your project:
12-
// .exclude(['meta', 'strings', 'print', 'filesystem', 'semver', 'system', 'prompt', 'http', 'template', 'patching', 'package-manager'])
13-
// and run it
19+
1420
const toolbox = await cli.run(argv)
1521
return toolbox
1622
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { GluegunCommand, GluegunToolbox } from 'gluegun';
2+
import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types';
3+
4+
import { findCommand } from '../../../utils/functions.helper';
5+
6+
const COMMAND: GluegunCommand = {
7+
name: 'component',
8+
alias: ['c'],
9+
description: 'Cria um componente Angular de tipo específico',
10+
run: async (toolbox: GluegunToolbox) => {
11+
const { parameters, prompt } = 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 QUESTION = 'Qual tipo de componente você deseja criar?'
33+
const TYPES = ['common', 'page', 'widget', 'layout']
34+
35+
const componentTypeResponse: GluegunAskResponse = await prompt.ask({
36+
type: 'select',
37+
name: 'type',
38+
message: QUESTION,
39+
choices: TYPES,
40+
})
41+
42+
const componentType = componentTypeResponse.type
43+
const command = findCommand(toolbox, componentType)
44+
45+
toolbox.parameters.first = componentName
46+
command.run(toolbox)
47+
},
48+
}
49+
50+
module.exports = COMMAND
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { GluegunCommand, GluegunToolbox } from 'gluegun';
2+
3+
import { printCreated } from '../../../../utils/functions.helper';
4+
5+
const COMMAND: GluegunCommand = {
6+
name: 'page',
7+
alias: ['p'],
8+
description: 'Cria um componente Angular de tipo Page',
9+
run: async (toolbox: GluegunToolbox) => {
10+
const { parameters, print, template, strings } = toolbox
11+
12+
const componentName = parameters.first
13+
14+
template.generate({
15+
template: 'component.page.html.ejs',
16+
target: `./${componentName}/${componentName}.page.html`,
17+
props: { name: componentName, ...strings },
18+
})
19+
20+
template.generate({
21+
template: 'component.page.ts.ejs',
22+
target: `./${componentName}/${componentName}.page.ts`,
23+
props: { name: componentName, ...strings },
24+
})
25+
26+
template.generate({
27+
template: 'component.page.scss.ejs',
28+
target: `./${componentName}/${componentName}.page.scss`,
29+
})
30+
31+
printCreated(print, `${componentName}/${componentName}.page.html`)
32+
printCreated(print, `${componentName}/${componentName}.page.ts`)
33+
printCreated(print, `${componentName}/${componentName}.page.scss`)
34+
},
35+
}
36+
37+
module.exports = COMMAND

src/commands/generate/generate.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { GluegunCommand, GluegunToolbox } from 'gluegun';
2+
import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types';
3+
4+
import { findCommand } from '../../utils/functions.helper';
5+
6+
const COMMAND: GluegunCommand = {
7+
name: 'generate',
8+
description: 'Cria uma nova entidade',
9+
alias: ['g'],
10+
run: async (toolbox: GluegunToolbox) => {
11+
const { prompt } = toolbox
12+
13+
const GENERATE_MODEL_TYPE_QUESTION =
14+
'Qual o tipo de entidade que você deseja criar?'
15+
16+
const GENERATE_MODEL_TYPE_OPTIONS = [
17+
'component',
18+
'directive',
19+
'guard',
20+
'interceptor',
21+
'module',
22+
]
23+
24+
const modelTypeResponse: GluegunAskResponse = await prompt.ask({
25+
type: 'select',
26+
name: 'type',
27+
message: GENERATE_MODEL_TYPE_QUESTION,
28+
choices: GENERATE_MODEL_TYPE_OPTIONS,
29+
})
30+
31+
const command = findCommand(toolbox, modelTypeResponse.type)
32+
command.run(toolbox)
33+
},
34+
}
35+
36+
module.exports = COMMAND

src/commands/generate.ts renamed to src/commands/new.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { GluegunToolbox } from 'gluegun'
1+
import { GluegunCommand, GluegunToolbox } from 'gluegun';
22

3-
module.exports = {
4-
name: 'generate',
5-
alias: ['g'],
3+
const COMMAND: GluegunCommand = {
4+
name: 'new',
5+
alias: ['n'],
6+
description: 'Cria um novo projeto Angular',
67
run: async (toolbox: GluegunToolbox) => {
78
const {
89
parameters,
@@ -21,3 +22,5 @@ module.exports = {
2122
info(`Generated file at models/${name}-model.ts`)
2223
},
2324
}
25+
26+
module.exports = COMMAND

src/templates/component.page.html.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><%= props.name %> works</p>

src/templates/component.page.scss.ejs

Whitespace-only changes.

src/templates/component.page.ts.ejs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
templateUrl: './<%= kebabCase(props.name) %>.page.html',
5+
styleUrls: ['./<%= kebabCase(props.name) %>.page.scss'],
6+
})
7+
export class <%= pascalCase(props.name) %>Page implements OnInit {
8+
constructor() {}
9+
10+
ngOnInit(): void {
11+
}
12+
}

src/utils/functions.helper.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { GluegunPrint, GluegunToolbox } from 'gluegun';
2+
import { Command } from 'gluegun/build/types/domain/command';
3+
4+
export function findCommand(
5+
toolbox: GluegunToolbox,
6+
commandName: string
7+
): Command {
8+
const command = toolbox.runtime.commands.find(
9+
(command) => command.name === commandName
10+
)
11+
12+
return command
13+
}
14+
15+
export function printCreated(print: GluegunPrint, message: string) {
16+
const text =
17+
print.colors.green('CREATED') + ' ' + print.colors.yellow(message)
18+
print.info(text)
19+
}

0 commit comments

Comments
 (0)