jabuti 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. jabuti-0.3.0/LICENSE +21 -0
  2. jabuti-0.3.0/PKG-INFO +131 -0
  3. jabuti-0.3.0/README.md +106 -0
  4. jabuti-0.3.0/pyproject.toml +61 -0
  5. jabuti-0.3.0/setup.cfg +4 -0
  6. jabuti-0.3.0/src/jabuti/__init__.py +5 -0
  7. jabuti-0.3.0/src/jabuti/cli.py +28 -0
  8. jabuti-0.3.0/src/jabuti/commands/__init__.py +1 -0
  9. jabuti-0.3.0/src/jabuti/commands/create.py +116 -0
  10. jabuti-0.3.0/src/jabuti/commands/doctor.py +45 -0
  11. jabuti-0.3.0/src/jabuti/commands/prompts.py +153 -0
  12. jabuti-0.3.0/src/jabuti/commands/summary.py +50 -0
  13. jabuti-0.3.0/src/jabuti/deployment/__init__.py +1 -0
  14. jabuti-0.3.0/src/jabuti/deployment/checks.py +78 -0
  15. jabuti-0.3.0/src/jabuti/deployment/model.py +70 -0
  16. jabuti-0.3.0/src/jabuti/deployment/workflows.py +112 -0
  17. jabuti-0.3.0/src/jabuti/doctor.py +144 -0
  18. jabuti-0.3.0/src/jabuti/documentation/__init__.py +1 -0
  19. jabuti-0.3.0/src/jabuti/documentation/agents.py +168 -0
  20. jabuti-0.3.0/src/jabuti/documentation/markdown.py +128 -0
  21. jabuti-0.3.0/src/jabuti/documentation/readme.py +114 -0
  22. jabuti-0.3.0/src/jabuti/generators/__init__.py +1 -0
  23. jabuti-0.3.0/src/jabuti/generators/angular.py +45 -0
  24. jabuti-0.3.0/src/jabuti/generators/environment.py +20 -0
  25. jabuti-0.3.0/src/jabuti/generators/express.py +84 -0
  26. jabuti-0.3.0/src/jabuti/generators/fastapi.py +26 -0
  27. jabuti-0.3.0/src/jabuti/generators/flask.py +30 -0
  28. jabuti-0.3.0/src/jabuti/generators/process.py +51 -0
  29. jabuti-0.3.0/src/jabuti/generators/python_project.py +89 -0
  30. jabuti-0.3.0/src/jabuti/generators/react.py +62 -0
  31. jabuti-0.3.0/src/jabuti/node.py +161 -0
  32. jabuti-0.3.0/src/jabuti/prerequisites.py +85 -0
  33. jabuti-0.3.0/src/jabuti/project/__init__.py +1 -0
  34. jabuti-0.3.0/src/jabuti/project/config.py +185 -0
  35. jabuti-0.3.0/src/jabuti/project/gitignore.py +48 -0
  36. jabuti-0.3.0/src/jabuti/project/planner.py +174 -0
  37. jabuti-0.3.0/src/jabuti/project/repository.py +29 -0
  38. jabuti-0.3.0/src/jabuti/project/stacks.py +96 -0
  39. jabuti-0.3.0/src/jabuti/python_runtime.py +74 -0
  40. jabuti-0.3.0/src/jabuti/rendering.py +42 -0
  41. jabuti-0.3.0/src/jabuti/templates/express/app-api.js.tpl +13 -0
  42. jabuti-0.3.0/src/jabuti/templates/express/app-web.js.tpl +23 -0
  43. jabuti-0.3.0/src/jabuti/templates/express/database.js.tpl +17 -0
  44. jabuti-0.3.0/src/jabuti/templates/express/health.test.js.tpl +17 -0
  45. jabuti-0.3.0/src/jabuti/templates/express/index.ejs.tpl +15 -0
  46. jabuti-0.3.0/src/jabuti/templates/express/server.js.tpl +13 -0
  47. jabuti-0.3.0/src/jabuti/templates/fastapi/main.py.tpl +11 -0
  48. jabuti-0.3.0/src/jabuti/templates/fastapi/test_health.py.tpl +10 -0
  49. jabuti-0.3.0/src/jabuti/templates/flask/__init__.py.tpl +16 -0
  50. jabuti-0.3.0/src/jabuti/templates/flask/index.html.tpl +15 -0
  51. jabuti-0.3.0/src/jabuti/templates/flask/routes.py.tpl +17 -0
  52. jabuti-0.3.0/src/jabuti/templates/flask/test_routes.py.tpl +14 -0
  53. jabuti-0.3.0/src/jabuti/templates/python/alembic.ini.tpl +40 -0
  54. jabuti-0.3.0/src/jabuti/templates/python/config.py.tpl +22 -0
  55. jabuti-0.3.0/src/jabuti/templates/python/database.py.tpl +14 -0
  56. jabuti-0.3.0/src/jabuti/templates/python/migrations/env.py.tpl +46 -0
  57. jabuti-0.3.0/src/jabuti/templates/python/migrations/script.py.mako.tpl +28 -0
  58. jabuti-0.3.0/src/jabuti/templates/web/styles.css.tpl +12 -0
  59. jabuti-0.3.0/src/jabuti/templates/workflows/deploy.yml.tpl +294 -0
  60. jabuti-0.3.0/src/jabuti/templates/workflows/migrations-node.yml.tpl +28 -0
  61. jabuti-0.3.0/src/jabuti/templates/workflows/migrations-python.yml.tpl +37 -0
  62. jabuti-0.3.0/src/jabuti.egg-info/PKG-INFO +131 -0
  63. jabuti-0.3.0/src/jabuti.egg-info/SOURCES.txt +71 -0
  64. jabuti-0.3.0/src/jabuti.egg-info/dependency_links.txt +1 -0
  65. jabuti-0.3.0/src/jabuti.egg-info/entry_points.txt +2 -0
  66. jabuti-0.3.0/src/jabuti.egg-info/requires.txt +2 -0
  67. jabuti-0.3.0/src/jabuti.egg-info/top_level.txt +1 -0
  68. jabuti-0.3.0/tests/test_cli.py +206 -0
  69. jabuti-0.3.0/tests/test_doctor.py +73 -0
  70. jabuti-0.3.0/tests/test_node.py +64 -0
  71. jabuti-0.3.0/tests/test_project_config.py +119 -0
  72. jabuti-0.3.0/tests/test_project_planner.py +142 -0
  73. jabuti-0.3.0/tests/test_react_generator.py +85 -0
jabuti-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jabuti contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
jabuti-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: jabuti
3
+ Version: 0.3.0
4
+ Summary: CLI para criação e padronização de projetos de software
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/catrique/jabuti
7
+ Project-URL: Repository, https://github.com/catrique/jabuti
8
+ Project-URL: Issues, https://github.com/catrique/jabuti/issues
9
+ Keywords: cli,scaffolding,github-actions,react,fastapi
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Code Generators
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: questionary<3,>=2.1
23
+ Requires-Dist: typer<1,>=0.27
24
+ Dynamic: license-file
25
+
26
+ # Jabuti
27
+
28
+ Jabuti é um CLI que cria e padroniza projetos de software: frontends, APIs,
29
+ projetos fullstack e aplicações web integradas, já com `AGENTS.md`, `README.md`,
30
+ `.gitignore` e workflows de deploy do GitHub Actions.
31
+
32
+ O Jabuti prepara e padroniza projetos; ele não administra a máquina do
33
+ desenvolvedor. Ferramentas do sistema são verificadas, nunca instaladas.
34
+
35
+ ## Instalação
36
+
37
+ Requer Python 3.11 ou superior.
38
+
39
+ ```bash
40
+ git clone https://github.com/catrique/jabuti.git
41
+ cd jabuti
42
+ pip install .
43
+ ```
44
+
45
+ Instalação diretamente do GitHub:
46
+
47
+ ```bash
48
+ pip install git+https://github.com/catrique/jabuti.git
49
+ ```
50
+
51
+ Após a publicação no PyPI:
52
+
53
+ ```bash
54
+ pip install jabuti
55
+ pipx install jabuti
56
+ ```
57
+
58
+ ## Uso
59
+
60
+ ```bash
61
+ jabuti --help
62
+ jabuti version
63
+ jabuti doctor
64
+ jabuti create
65
+ ```
66
+
67
+ ### `jabuti doctor`
68
+
69
+ Diagnostica o ambiente local sem alterar nada: mostra as versões de Python,
70
+ Node.js, npm e Git e quais stacks podem ser criadas, usando as mesmas regras
71
+ de versão do `jabuti create`. Retorna código 1 quando algo está ausente ou
72
+ incompatível.
73
+
74
+ | Stack | Precisa de |
75
+ | --- | --- |
76
+ | React, Express | Node.js 20.19+ ou 22.12+ e npm |
77
+ | Angular | Node.js 22.22.3+ ou 24.15+ e npm (CLI oficial via `npm exec`) |
78
+ | FastAPI, Flask | Python 3.10+ (cada projeto recebe sua própria `.venv`) |
79
+
80
+ ### `jabuti create`
81
+
82
+ Menus navegáveis por setas e Enter, perguntando só o que é relevante:
83
+
84
+ | Tipo | Opções | Estrutura |
85
+ | --- | --- | --- |
86
+ | Frontend | React (Vite + TypeScript), Angular | aplicação única na raiz |
87
+ | API | FastAPI, Express | aplicação única na raiz |
88
+ | Fullstack | React ou Angular + FastAPI ou Express | `frontend/` e `backend/` independentes |
89
+ | Aplicação web | Flask (Jinja), Express (EJS) | backend serve o HTML e os estáticos |
90
+
91
+ - **Banco:** MySQL opcional onde há backend. O Jabuti gera a configuração por
92
+ variáveis de ambiente e um `.env.example`, mas não instala MySQL, não cria
93
+ banco ou usuário e nunca gera credenciais nem `.env` real.
94
+ - **Migrations:** Alembic, para FastAPI e Flask com MySQL. Express ainda não
95
+ tem mecanismo de migrations no scaffold.
96
+
97
+ ## Deploy gerado
98
+
99
+ Os workflows publicam em um runner self-hosted Linux X64, no diretório
100
+ `/opt/governo-digital/<APP>`.
101
+
102
+ | Projeto | Workflows | APP no servidor |
103
+ | --- | --- | --- |
104
+ | Aplicação única | `deploy.yml` (+ `migrations.yml`) | `<repo>` |
105
+ | Fullstack | `deploy-frontend.yml`, `deploy-backend.yml` (+ `migrations-backend.yml`) | frontend `<repo>`, backend `<repo>-api` |
106
+
107
+ No fullstack, cada lado tem seu próprio deploy, disparado só por mudanças na
108
+ sua pasta. Migrations nunca rodam no push: seus workflows são manuais
109
+ (`workflow_dispatch`).
110
+
111
+ ## Desenvolvimento
112
+
113
+ ```bash
114
+ python -m venv .venv
115
+ .\.venv\Scripts\Activate.ps1 # PowerShell
116
+ source .venv/bin/activate # Linux ou macOS
117
+ python -m pip install -r requirements.txt
118
+ python -m pip install -e .
119
+ ```
120
+
121
+ Antes de cada commit:
122
+
123
+ ```bash
124
+ ruff check .
125
+ pytest
126
+ python -m pip check
127
+ python -m build
128
+ ```
129
+
130
+ O mesmo conjunto roda no CI (`.github/workflows/ci.yml`) em pushes e pull
131
+ requests para `main`.
jabuti-0.3.0/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Jabuti
2
+
3
+ Jabuti é um CLI que cria e padroniza projetos de software: frontends, APIs,
4
+ projetos fullstack e aplicações web integradas, já com `AGENTS.md`, `README.md`,
5
+ `.gitignore` e workflows de deploy do GitHub Actions.
6
+
7
+ O Jabuti prepara e padroniza projetos; ele não administra a máquina do
8
+ desenvolvedor. Ferramentas do sistema são verificadas, nunca instaladas.
9
+
10
+ ## Instalação
11
+
12
+ Requer Python 3.11 ou superior.
13
+
14
+ ```bash
15
+ git clone https://github.com/catrique/jabuti.git
16
+ cd jabuti
17
+ pip install .
18
+ ```
19
+
20
+ Instalação diretamente do GitHub:
21
+
22
+ ```bash
23
+ pip install git+https://github.com/catrique/jabuti.git
24
+ ```
25
+
26
+ Após a publicação no PyPI:
27
+
28
+ ```bash
29
+ pip install jabuti
30
+ pipx install jabuti
31
+ ```
32
+
33
+ ## Uso
34
+
35
+ ```bash
36
+ jabuti --help
37
+ jabuti version
38
+ jabuti doctor
39
+ jabuti create
40
+ ```
41
+
42
+ ### `jabuti doctor`
43
+
44
+ Diagnostica o ambiente local sem alterar nada: mostra as versões de Python,
45
+ Node.js, npm e Git e quais stacks podem ser criadas, usando as mesmas regras
46
+ de versão do `jabuti create`. Retorna código 1 quando algo está ausente ou
47
+ incompatível.
48
+
49
+ | Stack | Precisa de |
50
+ | --- | --- |
51
+ | React, Express | Node.js 20.19+ ou 22.12+ e npm |
52
+ | Angular | Node.js 22.22.3+ ou 24.15+ e npm (CLI oficial via `npm exec`) |
53
+ | FastAPI, Flask | Python 3.10+ (cada projeto recebe sua própria `.venv`) |
54
+
55
+ ### `jabuti create`
56
+
57
+ Menus navegáveis por setas e Enter, perguntando só o que é relevante:
58
+
59
+ | Tipo | Opções | Estrutura |
60
+ | --- | --- | --- |
61
+ | Frontend | React (Vite + TypeScript), Angular | aplicação única na raiz |
62
+ | API | FastAPI, Express | aplicação única na raiz |
63
+ | Fullstack | React ou Angular + FastAPI ou Express | `frontend/` e `backend/` independentes |
64
+ | Aplicação web | Flask (Jinja), Express (EJS) | backend serve o HTML e os estáticos |
65
+
66
+ - **Banco:** MySQL opcional onde há backend. O Jabuti gera a configuração por
67
+ variáveis de ambiente e um `.env.example`, mas não instala MySQL, não cria
68
+ banco ou usuário e nunca gera credenciais nem `.env` real.
69
+ - **Migrations:** Alembic, para FastAPI e Flask com MySQL. Express ainda não
70
+ tem mecanismo de migrations no scaffold.
71
+
72
+ ## Deploy gerado
73
+
74
+ Os workflows publicam em um runner self-hosted Linux X64, no diretório
75
+ `/opt/governo-digital/<APP>`.
76
+
77
+ | Projeto | Workflows | APP no servidor |
78
+ | --- | --- | --- |
79
+ | Aplicação única | `deploy.yml` (+ `migrations.yml`) | `<repo>` |
80
+ | Fullstack | `deploy-frontend.yml`, `deploy-backend.yml` (+ `migrations-backend.yml`) | frontend `<repo>`, backend `<repo>-api` |
81
+
82
+ No fullstack, cada lado tem seu próprio deploy, disparado só por mudanças na
83
+ sua pasta. Migrations nunca rodam no push: seus workflows são manuais
84
+ (`workflow_dispatch`).
85
+
86
+ ## Desenvolvimento
87
+
88
+ ```bash
89
+ python -m venv .venv
90
+ .\.venv\Scripts\Activate.ps1 # PowerShell
91
+ source .venv/bin/activate # Linux ou macOS
92
+ python -m pip install -r requirements.txt
93
+ python -m pip install -e .
94
+ ```
95
+
96
+ Antes de cada commit:
97
+
98
+ ```bash
99
+ ruff check .
100
+ pytest
101
+ python -m pip check
102
+ python -m build
103
+ ```
104
+
105
+ O mesmo conjunto roda no CI (`.github/workflows/ci.yml`) em pushes e pull
106
+ requests para `main`.
@@ -0,0 +1,61 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "jabuti"
7
+ dynamic = ["version"]
8
+ description = "CLI para criação e padronização de projetos de software"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ keywords = ["cli", "scaffolding", "github-actions", "react", "fastapi"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Software Development :: Code Generators",
24
+ ]
25
+ dependencies = [
26
+ "questionary>=2.1,<3",
27
+ "typer>=0.27,<1",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/catrique/jabuti"
32
+ Repository = "https://github.com/catrique/jabuti"
33
+ Issues = "https://github.com/catrique/jabuti/issues"
34
+
35
+ [project.scripts]
36
+ jabuti = "jabuti.cli:app"
37
+
38
+ [tool.setuptools.dynamic]
39
+ version = { attr = "jabuti.__version__" }
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+
44
+ # Templates are package resources read through importlib.resources.
45
+ [tool.setuptools.package-data]
46
+ jabuti = ["templates/**/*.tpl"]
47
+
48
+ [tool.pytest.ini_options]
49
+ addopts = "-ra"
50
+ pythonpath = ["src"]
51
+ testpaths = ["tests"]
52
+
53
+ [tool.ruff]
54
+ line-length = 88
55
+ target-version = "py311"
56
+
57
+ [tool.ruff.lint]
58
+ select = ["E", "F", "I"]
59
+
60
+ [tool.ruff.lint.isort]
61
+ known-first-party = ["jabuti"]
jabuti-0.3.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ """Jabuti command-line interface."""
2
+
3
+ __version__ = "0.3.0"
4
+
5
+ __all__ = ["__version__"]
@@ -0,0 +1,28 @@
1
+ """Command-line interface for Jabuti."""
2
+
3
+ import typer
4
+
5
+ from jabuti import __version__
6
+ from jabuti.commands.create import create
7
+ from jabuti.commands.doctor import doctor
8
+
9
+ app = typer.Typer(
10
+ name="jabuti",
11
+ help="Jabuti: uma base para criar e padronizar projetos de software.",
12
+ no_args_is_help=True,
13
+ )
14
+
15
+
16
+ @app.callback()
17
+ def main() -> None:
18
+ """Crie e padronize projetos de software com o Jabuti."""
19
+
20
+
21
+ @app.command()
22
+ def version() -> None:
23
+ """Exibe a versão atual do Jabuti."""
24
+ typer.echo(f"Jabuti {__version__}")
25
+
26
+
27
+ app.command()(create)
28
+ app.command()(doctor)
@@ -0,0 +1 @@
1
+ """Commands exposed by the Jabuti CLI."""
@@ -0,0 +1,116 @@
1
+ """Interactive project creation command."""
2
+
3
+ from collections.abc import Callable
4
+ from pathlib import Path
5
+
6
+ import typer
7
+
8
+ from jabuti.commands.prompts import PromptCancelled, prompt_project_config
9
+ from jabuti.commands.summary import summary_lines
10
+ from jabuti.deployment.checks import DeploymentCheckError
11
+ from jabuti.deployment.workflows import WorkflowConfigurationError
12
+ from jabuti.generators.angular import generate_angular
13
+ from jabuti.generators.express import generate_express
14
+ from jabuti.generators.fastapi import generate_fastapi
15
+ from jabuti.generators.flask import generate_flask
16
+ from jabuti.generators.process import GenerationError
17
+ from jabuti.generators.react import generate_react
18
+ from jabuti.prerequisites import PrerequisiteError, Toolchain, check_prerequisites
19
+ from jabuti.project.config import Backend, Framework, Frontend
20
+ from jabuti.project.planner import (
21
+ ComponentPlan,
22
+ ProjectPlan,
23
+ ProjectTargetExistsError,
24
+ component_directory,
25
+ create_project_structure,
26
+ plan_project,
27
+ )
28
+ from jabuti.project.repository import write_repository_files
29
+
30
+ Generator = Callable[[ComponentPlan, Path, Toolchain], None]
31
+
32
+ _GENERATORS: dict[Framework, Generator] = {
33
+ Frontend.REACT: generate_react,
34
+ Frontend.ANGULAR: generate_angular,
35
+ Backend.FASTAPI: generate_fastapi,
36
+ Backend.FLASK: generate_flask,
37
+ Backend.EXPRESS: generate_express,
38
+ }
39
+
40
+
41
+ def create() -> None:
42
+ """Configure e crie um projeto com o Jabuti."""
43
+ try:
44
+ config = prompt_project_config()
45
+ except PromptCancelled:
46
+ typer.echo("Operação cancelada.")
47
+ return
48
+
49
+ plan = plan_project(config)
50
+ typer.echo()
51
+ typer.echo("\n".join(summary_lines(plan)))
52
+ typer.echo()
53
+
54
+ if not typer.confirm("Continuar?", default=True):
55
+ typer.echo("Operação cancelada.")
56
+ return
57
+
58
+ tools = _check_prerequisites(plan)
59
+ project_root = _create_root(plan)
60
+ _generate(plan, project_root, tools)
61
+ _show_success(plan)
62
+
63
+
64
+ def _check_prerequisites(plan: ProjectPlan) -> Toolchain:
65
+ try:
66
+ tools = check_prerequisites(plan)
67
+ except PrerequisiteError as error:
68
+ typer.echo(str(error), err=True)
69
+ typer.echo("\nNenhum arquivo foi criado.", err=True)
70
+ raise typer.Exit(code=1) from None
71
+
72
+ for tool in tools.describe():
73
+ typer.echo(f"[OK] {tool}")
74
+ return tools
75
+
76
+
77
+ def _create_root(plan: ProjectPlan) -> Path:
78
+ try:
79
+ return create_project_structure(plan)
80
+ except ProjectTargetExistsError as error:
81
+ typer.echo(str(error), err=True)
82
+ raise typer.Exit(code=1) from None
83
+
84
+
85
+ def _generate(plan: ProjectPlan, project_root: Path, tools: Toolchain) -> None:
86
+ """Generate every component, then the repository files that depend on them."""
87
+ try:
88
+ for component in plan.components:
89
+ generator = _GENERATORS[component.framework]
90
+ generator(component, component_directory(component, project_root), tools)
91
+ typer.echo(f"[OK] {component.framework} criado")
92
+
93
+ write_repository_files(plan, project_root)
94
+ except (
95
+ GenerationError,
96
+ DeploymentCheckError,
97
+ WorkflowConfigurationError,
98
+ ) as error:
99
+ typer.echo(str(error), err=True)
100
+ typer.echo(
101
+ f"\nA criação foi interrompida. Os arquivos gerados até aqui foram "
102
+ f"mantidos em '{plan.root}' para inspeção.",
103
+ err=True,
104
+ )
105
+ raise typer.Exit(code=1) from None
106
+
107
+ typer.echo("[OK] Workflows, README.md, AGENTS.md e .gitignore gerados")
108
+
109
+
110
+ def _show_success(plan: ProjectPlan) -> None:
111
+ typer.echo("\nProjeto criado com sucesso.")
112
+ for component in plan.components:
113
+ directory = Path(plan.root, component.directory).as_posix()
114
+ typer.echo(f"\nPara iniciar {component.framework}:")
115
+ typer.echo(f"cd {directory}")
116
+ typer.echo(component.stack.run_command)
@@ -0,0 +1,45 @@
1
+ """Environment diagnosis command."""
2
+
3
+ import typer
4
+
5
+ from jabuti import __version__
6
+ from jabuti.doctor import Diagnosis, diagnose
7
+
8
+ _SEPARATOR = "-" * 32
9
+ _NAME_WIDTH = 10
10
+
11
+
12
+ def doctor() -> None:
13
+ """Verifique as ferramentas do ambiente sem alterar o sistema."""
14
+ diagnosis = diagnose()
15
+ typer.echo("\n".join(report_lines(diagnosis)))
16
+ if not diagnosis.ready:
17
+ raise typer.Exit(code=1)
18
+
19
+
20
+ def report_lines(diagnosis: Diagnosis) -> list[str]:
21
+ """Human-readable report, using only ASCII markers."""
22
+ lines = [f"Jabuti {__version__}", "", "Ambiente", _SEPARATOR]
23
+ for tool in diagnosis.tools:
24
+ detail = tool.version if tool.ok else tool.problem
25
+ lines.append(f"{_marker(tool.ok)} {tool.name:<{_NAME_WIDTH}}{detail}")
26
+
27
+ lines.extend(("", "Stacks", _SEPARATOR))
28
+ for stack in diagnosis.stacks:
29
+ lines.append(f"{_marker(stack.ok)} {stack.framework}")
30
+ if stack.problem:
31
+ lines.extend(f" {line}" for line in stack.problem.splitlines())
32
+
33
+ lines.append("")
34
+ if diagnosis.ready:
35
+ lines.append("Ambiente pronto.")
36
+ else:
37
+ lines.append(
38
+ "Algumas ferramentas estão ausentes ou incompatíveis. "
39
+ "O Jabuti não instala nada: instale-as e execute jabuti doctor novamente."
40
+ )
41
+ return lines
42
+
43
+
44
+ def _marker(ok: bool) -> str:
45
+ return "[OK]" if ok else "[--]"
@@ -0,0 +1,153 @@
1
+ """Interactive menu prompts used by Jabuti commands."""
2
+
3
+ from enum import StrEnum
4
+ from typing import TypeVar, cast
5
+
6
+ import questionary
7
+ import typer
8
+
9
+ from jabuti.project.config import (
10
+ BACKENDS_BY_PROJECT_TYPE,
11
+ PROJECT_TYPES_WITH_FRONTEND,
12
+ Backend,
13
+ Database,
14
+ Frontend,
15
+ MigrationStrategy,
16
+ ProjectConfig,
17
+ ProjectConfigError,
18
+ ProjectType,
19
+ validate_project_name,
20
+ )
21
+
22
+ MenuValue = TypeVar("MenuValue", bound=StrEnum)
23
+
24
+ _BACKEND_TITLES = {
25
+ Backend.FASTAPI: "FastAPI (Python)",
26
+ Backend.EXPRESS: "Express (Node.js)",
27
+ Backend.FLASK: "Flask (Python)",
28
+ }
29
+ _FRONTEND_MESSAGES = {
30
+ ProjectType.FRONTEND: "Framework:",
31
+ ProjectType.FULLSTACK: "Frontend:",
32
+ }
33
+ _BACKEND_MESSAGES = {
34
+ ProjectType.API: "Backend:",
35
+ ProjectType.FULLSTACK: "Backend:",
36
+ ProjectType.WEB_APP: "Framework:",
37
+ }
38
+ # Migrations are offered only where the scaffold creates a working mechanism.
39
+ # Express has no migration library yet, so `npm run migrar` is not offered.
40
+ _OFFERED_MIGRATIONS = {
41
+ Backend.FASTAPI: MigrationStrategy.ALEMBIC,
42
+ Backend.FLASK: MigrationStrategy.ALEMBIC,
43
+ }
44
+
45
+
46
+ class PromptCancelled(RuntimeError):
47
+ """Raised when the user cancels an interactive menu."""
48
+
49
+
50
+ def select_option(
51
+ message: str,
52
+ options: tuple[tuple[str, MenuValue], ...],
53
+ ) -> MenuValue:
54
+ """Show an arrow-key menu and return its typed value."""
55
+ choices = [
56
+ questionary.Choice(title=title, value=value)
57
+ for title, value in options
58
+ ]
59
+ answer = questionary.select(
60
+ message,
61
+ choices=choices,
62
+ qmark="?",
63
+ pointer=">",
64
+ use_arrow_keys=True,
65
+ use_shortcuts=False,
66
+ instruction="Use as setas e Enter",
67
+ ).ask()
68
+
69
+ if answer is None:
70
+ raise PromptCancelled
71
+
72
+ return cast(MenuValue, answer)
73
+
74
+
75
+ def prompt_project_config() -> ProjectConfig:
76
+ """Collect only the choices relevant to the selected project type."""
77
+ name = _prompt_project_name()
78
+ project_type = select_option(
79
+ "O que você quer criar?",
80
+ tuple((option.value, option) for option in ProjectType),
81
+ )
82
+ frontend = _prompt_frontend(project_type)
83
+ backend = _prompt_backend(project_type)
84
+ database = _prompt_database(backend)
85
+ migrations = _prompt_migrations(backend, database)
86
+
87
+ try:
88
+ return ProjectConfig(
89
+ name=name,
90
+ project_type=project_type,
91
+ frontend=frontend,
92
+ backend=backend,
93
+ database=database,
94
+ migrations=migrations,
95
+ )
96
+ except ProjectConfigError as error:
97
+ typer.echo(f"Configuração inválida: {error}", err=True)
98
+ raise typer.Exit(code=2) from None
99
+
100
+
101
+ def _prompt_frontend(project_type: ProjectType) -> Frontend | None:
102
+ if project_type not in PROJECT_TYPES_WITH_FRONTEND:
103
+ return None
104
+ return select_option(
105
+ _FRONTEND_MESSAGES[project_type],
106
+ tuple((option.value, option) for option in Frontend),
107
+ )
108
+
109
+
110
+ def _prompt_backend(project_type: ProjectType) -> Backend | None:
111
+ backends = BACKENDS_BY_PROJECT_TYPE[project_type]
112
+ if not backends:
113
+ return None
114
+ return select_option(
115
+ _BACKEND_MESSAGES[project_type],
116
+ tuple((_BACKEND_TITLES[option], option) for option in backends),
117
+ )
118
+
119
+
120
+ def _prompt_database(backend: Backend | None) -> Database:
121
+ if backend is None:
122
+ return Database.NONE
123
+ return select_option(
124
+ "Banco de dados:",
125
+ tuple((option.value, option) for option in Database),
126
+ )
127
+
128
+
129
+ def _prompt_migrations(
130
+ backend: Backend | None,
131
+ database: Database,
132
+ ) -> MigrationStrategy:
133
+ offered = _OFFERED_MIGRATIONS.get(backend) if backend else None
134
+ if database is Database.NONE or offered is None:
135
+ return MigrationStrategy.NONE
136
+ no_migrations = MigrationStrategy.NONE
137
+ return select_option(
138
+ "Migrations:",
139
+ ((offered.value, offered), (no_migrations.value, no_migrations)),
140
+ )
141
+
142
+
143
+ def _prompt_project_name() -> str:
144
+ while True:
145
+ name = typer.prompt("Nome do projeto")
146
+
147
+ try:
148
+ validate_project_name(name)
149
+ except ProjectConfigError as error:
150
+ typer.echo(f"Nome inválido: {error}", err=True)
151
+ continue
152
+
153
+ return name