-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: generate api and common service
- Loading branch information
Showing
5 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { GluegunCommand, GluegunToolbox } from 'gluegun'; | ||
import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types'; | ||
|
||
import { printCreated } from '../../../../utils/functions.helper'; | ||
|
||
const COMMAND: GluegunCommand = { | ||
name: 'api', | ||
alias: ['a'], | ||
description: 'cria um serviço Angular do tipo Api', | ||
run: async (toolbox: GluegunToolbox) => { | ||
const { parameters, print, prompt, template, strings } = toolbox; | ||
|
||
let serviceName = parameters.first; | ||
|
||
if (!serviceName) { | ||
const response: GluegunAskResponse = await prompt.ask({ | ||
type: 'input', | ||
name: 'serviceName', | ||
message: 'Qual o nome do serviço?', | ||
validate: (value: string) => { | ||
if (!value) { | ||
return 'O nome do serviço não pode ser vazio'; | ||
} | ||
|
||
return true; | ||
} | ||
}); | ||
|
||
serviceName = response.serviceName; | ||
} | ||
|
||
const serviceNameKebab = strings.kebabCase(serviceName); | ||
|
||
template.generate({ | ||
template: 'service.template.ts.ejs', | ||
target: `./${serviceNameKebab}/${serviceNameKebab}.api.ts`, | ||
props: { | ||
type: 'api', | ||
name: serviceName, | ||
...strings | ||
} | ||
}); | ||
|
||
template.generate({ | ||
template: 'service.template.spec.ts.ejs', | ||
target: `./${serviceNameKebab}/${serviceNameKebab}.api.spec.ts`, | ||
props: { | ||
type: 'api', | ||
name: serviceName, | ||
...strings | ||
} | ||
}); | ||
|
||
printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.api.ts`); | ||
printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.api.spec.ts`); | ||
} | ||
}; | ||
|
||
module.exports = COMMAND; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { GluegunCommand, GluegunToolbox } from 'gluegun'; | ||
import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types'; | ||
|
||
import { printCreated } from '../../../../utils/functions.helper'; | ||
|
||
const COMMAND: GluegunCommand = { | ||
name: 'common', | ||
alias: ['c'], | ||
description: 'cria um serviço Angular', | ||
run: async (toolbox: GluegunToolbox) => { | ||
const { parameters, print, prompt, template, strings } = toolbox; | ||
|
||
let serviceName = parameters.first; | ||
|
||
if (!serviceName) { | ||
const response: GluegunAskResponse = await prompt.ask({ | ||
type: 'input', | ||
name: 'serviceName', | ||
message: 'Qual o nome do serviço?', | ||
validate: (value: string) => { | ||
if (!value) { | ||
return 'O nome do serviço não pode ser vazio'; | ||
} | ||
|
||
return true; | ||
} | ||
}); | ||
|
||
serviceName = response.serviceName; | ||
} | ||
|
||
const serviceNameKebab = strings.kebabCase(serviceName); | ||
|
||
template.generate({ | ||
template: 'service.template.ts.ejs', | ||
target: `./${serviceNameKebab}/${serviceNameKebab}.service.ts`, | ||
props: { | ||
type: 'service', | ||
name: serviceName, | ||
...strings | ||
} | ||
}); | ||
|
||
template.generate({ | ||
template: 'service.template.spec.ts.ejs', | ||
target: `./${serviceNameKebab}/${serviceNameKebab}.service.spec.ts`, | ||
props: { | ||
type: 'service', | ||
name: serviceName, | ||
...strings | ||
} | ||
}); | ||
|
||
printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.service.ts`); | ||
printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.service.spec.ts`); | ||
} | ||
}; | ||
|
||
module.exports = COMMAND; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { GluegunCommand, GluegunToolbox } from 'gluegun'; | ||
import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types'; | ||
|
||
import { findCommand } from '../../../utils/functions.helper'; | ||
|
||
const COMMAND: GluegunCommand = { | ||
name: 'service', | ||
alias: ['s'], | ||
description: 'Cria um serviço Angular de tipo específico', | ||
|
||
run: async (toolbox: GluegunToolbox) => { | ||
const { parameters, prompt } = toolbox; | ||
|
||
let componentName = parameters.first; | ||
|
||
const QUESTION = 'Qual tipo de serviço você deseja criar?'; | ||
const TYPES = ['common', 'api']; | ||
|
||
const componentTypeResponse: GluegunAskResponse = await prompt.ask({ | ||
type: 'select', | ||
name: 'type', | ||
message: QUESTION, | ||
choices: TYPES | ||
}); | ||
|
||
const componentType = componentTypeResponse.type; | ||
const command = findCommand(toolbox, componentType); | ||
|
||
toolbox.parameters.first = componentName; | ||
command.run(toolbox); | ||
} | ||
}; | ||
|
||
module.exports = COMMAND; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { <%= pascalCase(props.name) %><%= pascalCase(props.type) %> } from './<%= kebabCase(props.name) %>.<%= kebabCase(props.type) %>'; | ||
|
||
describe('<%= pascalCase(props.name) %><%= pascalCase(props.type) %>', () => { | ||
let service: <%= pascalCase(props.name) %><%= pascalCase(props.type) %>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(<%= pascalCase(props.name) %><%= pascalCase(props.type) %>); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class <%= pascalCase(props.name) %><%= pascalCase(props.type) %> {} |