Skip to content

Commit

Permalink
Criação da função capitalize para deixar a primeira letra do parametr…
Browse files Browse the repository at this point in the history
…o maiuscula e criacao do comando create:page
  • Loading branch information
pablogeokar committed Jun 26, 2021
1 parent c1fcd33 commit 0a5831b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zionix",
"version": "0.0.1",
"version": "0.0.2",
"description": "zionix CLI",
"bin": {
"zionix": "bin/zionix"
Expand Down
19 changes: 3 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
# zionix CLI

A CLI for zionix.

## Customizing your CLI

Check out the documentation at https://github.com/infinitered/gluegun/tree/master/docs.

## Publishing to NPM

To package your CLI up for NPM, do this:
Esta CLI foi criada com o objetivo de facilitar as tarefas repetitivas do dia a a dia durante os processos de desenvolvimento com React

```shell
$ npm login
$ npm whoami
$ npm lint
$ npm test
(if typescript, run `npm run build` here)
$ npm publish
$ zionix create:component {NAME} (Cria um componente padrão React)
$ zionix create:page {NAME} (Cria uma página padrão React)
```

# License

MIT - see LICENSE

13 changes: 8 additions & 5 deletions src/commands/component.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const capitalize = require('../utils/capitalize')

module.exports = {
name: 'component',
alias: ['c'],
name: 'create:component',
alias: ['comp'],
description: 'Cria um componente padrão React',
run: async toolbox => {
const { parameters, template, filesystem, print: { success, error } } = toolbox
const name = parameters.first
const name = capitalize(parameters.first)

if (!parameters.first) {
error('O nome do componente não foi especificado')
Expand All @@ -13,18 +15,19 @@ module.exports = {

const package = await filesystem.read('package.json', 'json')
const isReactNative = !!package.dependencies['react-native']
const isTypescript = !!package.dependencies['typescript']

const styleTemplate = isReactNative ? 'styles-rn.js.ejs' : 'styles-react.js.ejs'

await template.generate({
template: 'component.js.ejs',
target: `src/components/${name}/index.js`,
target: `src/components/${name}/index.${isTypescript ? 'tsx' : 'js'}`,
props: { name }
})

await template.generate({
template: styleTemplate,
target: `src/components/${name}/styles.js`
target: `src/components/${name}/styles.${isTypescript ? 'tsx' : 'js'}`
})

toolbox.print.success(`src/components/${name} gerado com sucesso!`)
Expand Down
35 changes: 35 additions & 0 deletions src/commands/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const capitalize = require('../utils/capitalize')

module.exports = {
name: 'create:page',
alias: ['page'],
description: 'Cria uma págnina padrão React',
run: async toolbox => {
const { parameters, template, filesystem, print: { success, error } } = toolbox
const name = capitalize(parameters.first)

if (!parameters.first) {
error('O nome do componente não foi especificado')
return
}

const package = await filesystem.read('package.json', 'json')
const isReactNative = !!package.dependencies['react-native']
const isTypescript = !!package.dependencies['typescript']

const styleTemplate = isReactNative ? 'styles-rn.js.ejs' : 'styles-react.js.ejs'

await template.generate({
template: 'component.js.ejs',
target: `src/pages/${name}/index.${isTypescript ? 'tsx' : 'js'}`,
props: { name }
})

await template.generate({
template: styleTemplate,
target: `src/pages/${name}/styles.${isTypescript ? 'tsx' : 'js'}`
})

toolbox.print.success(`src/pages/${name} gerado com sucesso!`)
}
}
9 changes: 9 additions & 0 deletions src/utils/capitalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const capitalize = str => {
if (typeof str === 'string') {
return str.replace(/^\w/, c => c.toUpperCase())
} else {
return ''
}
}

module.exports = capitalize

0 comments on commit 0a5831b

Please sign in to comment.