-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adicionando bibliotecas e configurando typescript * Adicionando suporte a version e description * Add chalk * Adicionando configurações para yargs * Implementando comando de criação de projeto na CLI de liquido * Atualizando comando gerar na cli * Corrigindo local da pasta exemplos * Atualizando engines. * Atualizando GitHub Action. * Adicionando comando global --------- Co-authored-by: Leonel Sanches da Silva <53848829+leonelsanchesdasilva@users.noreply.github.com>
- Loading branch information
1 parent
24bdd88
commit 2522b66
Showing
22 changed files
with
191 additions
and
110 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
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 @@ | ||
22.1.0 |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,162 @@ | ||
import { Command } from 'commander'; | ||
import { textSync } from 'figlet' | ||
import {version} from './package.json' | ||
import { | ||
blue, | ||
green, | ||
yellow | ||
} from "chalk"; | ||
import yargs from 'yargs' | ||
import { Liquido } from './liquido'; | ||
import prompts from 'prompts'; | ||
import { | ||
copiarExemploParaProjeto, | ||
criarDiretorioAplicacao, | ||
criarDiretorioSeNaoExiste, | ||
importarModelos, | ||
obterTodosModelos | ||
} from './interface-linha-comando'; | ||
import { ComandoGerarInterface, ComandoNovoInterface } from './interfaces'; | ||
import { GeradorVisoes } from './interface-linha-comando/gerar/gerador-visoes'; | ||
import { GeradorRotas } from './interface-linha-comando/gerar/gerador-rotas'; | ||
import { Classe } from '@designliquido/delegua/declaracoes'; | ||
import { pluralizar } from '@designliquido/flexoes'; | ||
|
||
const pontoDeEntrada = async () => { | ||
const analisadorArgumentos = new Command(); | ||
analisadorArgumentos; | ||
|
||
analisadorArgumentos | ||
.helpOption('-?, --ajuda', 'Exibe a ajuda para o comando.') | ||
.command('servidor', 'Serve o diretório local como uma aplicação para a internet.', { isDefault: true }) | ||
.command('novo [nome]', 'Inicia uma nova aplicação pré-configurada para funcionar com Liquido.') | ||
.command('gerar [modelo]', 'Gera controlador e visão correspondentes ao nome do modelo passado por parâmetro. O modelo deve ter um arquivo .delegua correspondente no diretório "modelos".'); | ||
/** | ||
* Classe que representa o ponto de entrada da aplicação Liquido. | ||
*/ | ||
class LiquidoPontoEntrada { | ||
logo: string | ||
|
||
analisadorArgumentos.parse(); | ||
constructor() { | ||
this.logo = textSync('Liquido', { horizontalLayout: 'full' }) | ||
} | ||
|
||
mostrarLogo() { | ||
console.log(blue(this.logo + '\n')) | ||
} | ||
|
||
comandoServidor() { | ||
const liquido = new Liquido(process.cwd()) | ||
liquido.iniciar() | ||
} | ||
|
||
async comandoNovo( | ||
args: yargs.ArgumentsCamelCase<ComandoNovoInterface> | ||
) { | ||
let nomeProjeto = args.nome | ||
|
||
if (nomeProjeto === undefined || nomeProjeto.length <= 0) { | ||
const respostaNomeProjeto = await prompts({ | ||
type: 'text', | ||
name: 'nomeProjeto', | ||
message: 'Qual o nome do seu projeto?' | ||
}); | ||
|
||
|
||
nomeProjeto = respostaNomeProjeto.nomeProjeto; | ||
} | ||
|
||
if (nomeProjeto.length > 0) { | ||
console.log(green(`Iremos criar um novo projeto em Liquido chamado "${nomeProjeto}"`)); | ||
const resposta = await prompts({ | ||
type: 'confirm', | ||
message: 'Confirma?', | ||
name: 'confirmado', | ||
initial: true, | ||
onRender() { | ||
this.yesMsg = 'Sim'; | ||
this.noMsg = 'não'; | ||
this.yesOption = '(S/n)'; | ||
} | ||
}); | ||
|
||
if (resposta.confirmado) { | ||
const diretorioCompleto = criarDiretorioAplicacao(nomeProjeto); | ||
|
||
const perguntaTipoProjeto = await prompts({ | ||
type: 'select', | ||
name: 'tipoProjeto', | ||
message: 'Selecione o tipo de projeto', | ||
choices: [ | ||
{ title: 'MVC', description: 'Modelo-Visão-Controlador', value: 'mvc' }, | ||
{ title: 'API REST', description: 'Interface de dados usando o modelo REST', value: 'api-rest' } | ||
], | ||
initial: 1 | ||
}); | ||
|
||
await copiarExemploParaProjeto(perguntaTipoProjeto.tipoProjeto, diretorioCompleto); | ||
console.info(yellow(`Seu projeto foi criado com sucesso! ${diretorioCompleto}`)) | ||
} | ||
} | ||
} | ||
|
||
async comandoGerar( | ||
args: yargs.ArgumentsCamelCase<ComandoGerarInterface> | ||
) { | ||
let nomeModelo = args.modelo | ||
|
||
if (nomeModelo === undefined || nomeModelo.length <= 0) { | ||
const opcoesModelos = obterTodosModelos() | ||
|
||
const respostaNomeModelo = await prompts({ | ||
type: 'select', | ||
name: 'nomeModelo', | ||
message: 'Qual o nome do modelo?', | ||
choices: opcoesModelos | ||
}); | ||
|
||
nomeModelo = respostaNomeModelo.nomeModelo; | ||
} | ||
|
||
const declaracoes = importarModelos(nomeModelo); | ||
criarDiretorioAplicacao('rotas'); | ||
|
||
const geradorVisoes = new GeradorVisoes(); | ||
const geradorRotas = new GeradorRotas(); | ||
|
||
for (const declaracao of declaracoes) { | ||
const declaracaoModelo = <Classe>declaracao | ||
const nomeBaseModelo = declaracaoModelo.simbolo.lexema.toLocaleLowerCase('pt'); | ||
const nomeModeloPlural = pluralizar(nomeBaseModelo).toLocaleLowerCase('pt'); | ||
|
||
const caminhosRotas: string[] = geradorRotas.criarNovasRotas(declaracaoModelo); | ||
for (const caminhoRota of caminhosRotas) { | ||
console.info(blue(`Rota ${caminhoRota}`)); | ||
} | ||
|
||
criarDiretorioSeNaoExiste('visoes', nomeModeloPlural); | ||
|
||
const visaoSelecionarTudo = geradorVisoes.criarNovaVisao(nomeModeloPlural, declaracaoModelo, 'selecionarTudo'); | ||
console.info(blue(`Visão ${visaoSelecionarTudo}`)); | ||
const visaoSelecionarUm = geradorVisoes.criarNovaVisao(nomeModeloPlural, declaracaoModelo, 'selecionarUm'); | ||
console.info(blue(`Visão ${visaoSelecionarUm}`)); | ||
const visaoAdicionar = geradorVisoes.criarNovaVisao(nomeModeloPlural, declaracaoModelo, 'adicionar'); | ||
console.info(blue(`Visão ${visaoAdicionar}`)); | ||
const visaoEditar = geradorVisoes.criarNovaVisao(nomeModeloPlural, declaracaoModelo, 'editar'); | ||
console.info(blue(`Visão ${visaoEditar}`)); | ||
const visaoExcluir = geradorVisoes.criarNovaVisao(nomeModeloPlural, declaracaoModelo, 'excluir'); | ||
console.info(blue(`Visão ${visaoExcluir}`)); | ||
} | ||
} | ||
|
||
opcoes() { | ||
return yargs | ||
.scriptName('liquido') | ||
.version(version) | ||
.usage('Uso: $0 <comando> [opções]') | ||
.help('ajuda') | ||
.alias('ajuda', '?') | ||
.command(['*', 'servidor'], 'Serve o diretório local como uma aplicação para a internet.', {}, this.comandoServidor) | ||
.command('novo [nome]', 'Inicia uma nova aplicação pré-configurada para funcionar com Liquido.', {}, this.comandoNovo) | ||
.command('gerar [modelo]', 'Gera controlador e visão correspondentes ao nome do modelo passado por parâmetro. O modelo deve ter um arquivo .delegua correspondente no diretório "modelos".', {}, this.comandoGerar) | ||
.argv | ||
} | ||
|
||
async iniciar() { | ||
this.mostrarLogo() | ||
this.opcoes() | ||
} | ||
} | ||
|
||
pontoDeEntrada(); | ||
(async () => new LiquidoPontoEntrada().iniciar())() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
export interface ComandoGerarInterface { | ||
modelo: string; | ||
} |
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,3 @@ | ||
export interface ComandoNovoInterface { | ||
nome: string | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './erro-lexador-liquido'; | ||
export * from './interface-liquido'; | ||
export * from './retorno-middleware'; | ||
export * from './comando-novo-interface' | ||
export * from './comando-gerar-interface' |
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
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
Oops, something went wrong.