Skip to content

Commit 14b0621

Browse files
committed
Add cpp-gen initial project generator
0 parents  commit 14b0621

21 files changed

Lines changed: 7988 additions & 0 deletions

File tree

.gitignore

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# =============================================================================
2+
# .gitignore — cpp-gen (Go project)
3+
# =============================================================================
4+
5+
# ── Binários compilados ───────────────────────────────────────────────────────
6+
cpp-gen
7+
cpp-gen.exe
8+
9+
# Diretório de build genérico
10+
dist/
11+
bin/
12+
out/
13+
14+
# ── Go ────────────────────────────────────────────────────────────────────────
15+
16+
# Módulos vendorizados (usar apenas se optar por vendor/)
17+
vendor/
18+
19+
# Cache de build do Go
20+
*.test
21+
*.out
22+
23+
# Cobertura de testes
24+
coverage.out
25+
coverage.html
26+
27+
# Profiling
28+
*.prof
29+
*.pprof
30+
cpu.out
31+
mem.out
32+
33+
# ── IDEs e editores ───────────────────────────────────────────────────────────
34+
35+
# VSCode
36+
.vscode/
37+
38+
# JetBrains / GoLand
39+
.idea/
40+
*.iml
41+
42+
# Vim / Neovim
43+
*.swp
44+
*.swo
45+
*~
46+
.session.vim
47+
Session.vim
48+
49+
# Emacs
50+
*~
51+
\#*\#
52+
.\#*
53+
54+
# ── Sistema Operacional ───────────────────────────────────────────────────────
55+
56+
# macOS
57+
.DS_Store
58+
.DS_Store?
59+
._*
60+
.Spotlight-V100
61+
.Trashes
62+
.AppleDouble
63+
.LSOverride
64+
65+
# Windows
66+
Thumbs.db
67+
Thumbs.db:encryptable
68+
ehthumbs.db
69+
desktop.ini
70+
$RECYCLE.BIN/
71+
72+
# Linux
73+
.fuse_hidden*
74+
.directory
75+
.Trash-*
76+
77+
# ── Logs e temporários ────────────────────────────────────────────────────────
78+
*.log
79+
*.tmp
80+
*.temp
81+
*.bak
82+
*.orig
83+
84+
# ── Variáveis de ambiente ─────────────────────────────────────────────────────
85+
.env
86+
.env.local
87+
.env.*.local

Makefile

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# ==============================================================================
2+
# Makefile — cpp-gen
3+
# ==============================================================================
4+
# Targets disponíveis:
5+
# make → build (padrão)
6+
# make build → compila o binário
7+
# make install → instala em ~/.local/bin (sem sudo)
8+
# make install-global → instala em /usr/local/bin (requer sudo)
9+
# make uninstall → remove o binário instalado
10+
# make clean → remove artefatos de build locais
11+
# make help → exibe esta mensagem
12+
# ==============================================================================
13+
14+
# ── Metadados ─────────────────────────────────────────────────────────────────
15+
16+
BINARY := cpp-gen
17+
VERSION := $(shell grep 'AppVersion' cmd/root.go 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "0.1.0")
18+
BUILD_DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
19+
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
20+
21+
# ── Diretórios ────────────────────────────────────────────────────────────────
22+
23+
# Diretório de instalação padrão (sem sudo, já suportado pela maioria dos shells)
24+
INSTALL_DIR := $(HOME)/.local/bin
25+
26+
# Diretório de instalação global (requer sudo)
27+
INSTALL_DIR_GLOBAL := /usr/local/bin
28+
29+
# Diretório de saída do build local
30+
BUILD_DIR := ./dist
31+
32+
# ── Flags de compilação Go ────────────────────────────────────────────────────
33+
34+
# Injeta versão, commit e data no binário via ldflags para exibição no --version
35+
LDFLAGS := -s -w \
36+
-X 'cpp-gen/cmd.AppVersion=$(VERSION)' \
37+
-X 'cpp-gen/cmd.BuildDate=$(BUILD_DATE)' \
38+
-X 'cpp-gen/cmd.GitCommit=$(GIT_COMMIT)'
39+
40+
GO := go
41+
GOFLAGS := -trimpath
42+
43+
# ── Cores para output ─────────────────────────────────────────────────────────
44+
45+
RESET := \033[0m
46+
BOLD := \033[1m
47+
GREEN := \033[32m
48+
CYAN := \033[36m
49+
YELLOW := \033[33m
50+
PURPLE := \033[35m
51+
RED := \033[31m
52+
GRAY := \033[90m
53+
54+
# ==============================================================================
55+
# Targets
56+
# ==============================================================================
57+
58+
.DEFAULT_GOAL := build
59+
60+
.PHONY: build install install-global uninstall clean help
61+
62+
# ── build ─────────────────────────────────────────────────────────────────────
63+
## Compila o binário em ./dist/cpp-gen
64+
build:
65+
@printf "$(BOLD)$(CYAN) Building$(RESET) $(BINARY) v$(VERSION) ($(GIT_COMMIT))\n"
66+
@mkdir -p $(BUILD_DIR)
67+
@$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY) .
68+
@printf "$(BOLD)$(GREEN) ✓ Built$(RESET) $(BUILD_DIR)/$(BINARY)\n"
69+
70+
# ── install ───────────────────────────────────────────────────────────────────
71+
## Instala o binário em ~/.local/bin (sem necessidade de sudo)
72+
install: build
73+
@printf "\n$(BOLD)$(CYAN) Installing$(RESET) $(BINARY)$(INSTALL_DIR)/$(BINARY)\n"
74+
@mkdir -p $(INSTALL_DIR)
75+
@cp $(BUILD_DIR)/$(BINARY) $(INSTALL_DIR)/$(BINARY)
76+
@chmod +x $(INSTALL_DIR)/$(BINARY)
77+
@printf "$(BOLD)$(GREEN) ✓ Installed$(RESET) $(INSTALL_DIR)/$(BINARY)\n"
78+
@$(MAKE) --no-print-directory _post_install_log INSTALL_LOCATION=$(INSTALL_DIR)
79+
80+
# ── install-global ────────────────────────────────────────────────────────────
81+
## Instala o binário em /usr/local/bin (requer sudo)
82+
install-global: build
83+
@printf "\n$(BOLD)$(CYAN) Installing$(RESET) $(BINARY)$(INSTALL_DIR_GLOBAL)/$(BINARY)$(RESET) $(GRAY)(requer sudo)$(RESET)\n"
84+
@sudo cp $(BUILD_DIR)/$(BINARY) $(INSTALL_DIR_GLOBAL)/$(BINARY)
85+
@sudo chmod +x $(INSTALL_DIR_GLOBAL)/$(BINARY)
86+
@printf "$(BOLD)$(GREEN) ✓ Installed$(RESET) $(INSTALL_DIR_GLOBAL)/$(BINARY)\n"
87+
@$(MAKE) --no-print-directory _post_install_log INSTALL_LOCATION=$(INSTALL_DIR_GLOBAL)
88+
89+
# ── uninstall ─────────────────────────────────────────────────────────────────
90+
## Remove o binário de ~/.local/bin e /usr/local/bin (se existirem)
91+
uninstall:
92+
@printf "$(BOLD)$(CYAN) Uninstalling$(RESET) $(BINARY)...\n"
93+
@removed=0; \
94+
if [ -f "$(INSTALL_DIR)/$(BINARY)" ]; then \
95+
rm -f "$(INSTALL_DIR)/$(BINARY)"; \
96+
printf "$(BOLD)$(GREEN) ✓ Removed$(RESET) $(INSTALL_DIR)/$(BINARY)\n"; \
97+
removed=1; \
98+
fi; \
99+
if [ -f "$(INSTALL_DIR_GLOBAL)/$(BINARY)" ]; then \
100+
sudo rm -f "$(INSTALL_DIR_GLOBAL)/$(BINARY)"; \
101+
printf "$(BOLD)$(GREEN) ✓ Removed$(RESET) $(INSTALL_DIR_GLOBAL)/$(BINARY)\n"; \
102+
removed=1; \
103+
fi; \
104+
if [ $$removed -eq 0 ]; then \
105+
printf "$(YELLOW) ⚠ Nenhuma instalação encontrada.$(RESET)\n"; \
106+
fi
107+
108+
# ── clean ─────────────────────────────────────────────────────────────────────
109+
## Remove o diretório ./dist com os artefatos de build
110+
clean:
111+
@printf "$(BOLD)$(CYAN) Cleaning$(RESET) $(BUILD_DIR)/\n"
112+
@rm -rf $(BUILD_DIR)
113+
@printf "$(BOLD)$(GREEN) ✓ Done$(RESET)\n"
114+
115+
# ── help ──────────────────────────────────────────────────────────────────────
116+
## Exibe todos os targets disponíveis
117+
help:
118+
@printf "\n$(BOLD)$(PURPLE)⚡ cpp-gen$(RESET) — Makefile\n\n"
119+
@printf "$(BOLD)Uso:$(RESET) make $(CYAN)<target>$(RESET)\n\n"
120+
@printf "$(BOLD)Targets:$(RESET)\n"
121+
@awk '/^## / { desc=substr($$0, 4) } \
122+
/^[a-zA-Z][a-zA-Z_-]*:/ && desc != "" { \
123+
target=$$1; sub(/:.*/, "", target); \
124+
printf " \033[36m%-20s\033[0m %s\n", target, desc; \
125+
desc="" \
126+
}' \
127+
$(MAKEFILE_LIST)
128+
@printf "\n$(BOLD)Variáveis:$(RESET)\n"
129+
@printf " $(CYAN)%-20s$(RESET) %s\n" "INSTALL_DIR" "$(INSTALL_DIR)"
130+
@printf " $(CYAN)%-20s$(RESET) %s\n" "INSTALL_DIR_GLOBAL" "$(INSTALL_DIR_GLOBAL)"
131+
@printf " $(CYAN)%-20s$(RESET) %s\n" "VERSION" "$(VERSION)"
132+
@printf " $(CYAN)%-20s$(RESET) %s\n" "GIT_COMMIT" "$(GIT_COMMIT)"
133+
@printf "\n$(BOLD)Exemplos:$(RESET)\n"
134+
@printf " make install $(GRAY)# instala em ~/.local/bin$(RESET)\n"
135+
@printf " make install-global $(GRAY)# instala em /usr/local/bin$(RESET)\n"
136+
@printf " make INSTALL_DIR=~/bin install $(GRAY)# diretório customizado$(RESET)\n\n"
137+
138+
# ==============================================================================
139+
# Target interno — Log pós-instalação com instruções de PATH
140+
# ==============================================================================
141+
142+
INSTALL_LOCATION ?= $(INSTALL_DIR)
143+
144+
.PHONY: _post_install_log
145+
_post_install_log:
146+
@printf "\n"
147+
@printf "$(BOLD)$(PURPLE)╔══════════════════════════════════════════════════════════════╗$(RESET)\n"
148+
@printf "$(BOLD)$(PURPLE)$(RESET) $(BOLD)⚡ cpp-gen v$(VERSION) instalado com sucesso!$(RESET) $(BOLD)$(PURPLE)$(RESET)\n"
149+
@printf "$(BOLD)$(PURPLE)╚══════════════════════════════════════════════════════════════╝$(RESET)\n"
150+
@printf "\n"
151+
152+
# Verifica se o diretório de instalação já está no PATH
153+
@if echo "$$PATH" | tr ':' '\n' | grep -qx "$(INSTALL_LOCATION)"; then \
154+
printf "$(BOLD)$(GREEN) ✓ $(INSTALL_LOCATION)$(RESET) já está no seu PATH. Tudo pronto!\n\n"; \
155+
printf " Execute: $(BOLD)$(CYAN)$(BINARY) --help$(RESET)\n\n"; \
156+
else \
157+
printf "$(BOLD)$(YELLOW) ⚠ Ação necessária:$(RESET) adicione $(BOLD)$(INSTALL_LOCATION)$(RESET) ao seu PATH.\n"; \
158+
printf " Siga as instruções abaixo para o seu shell:\n\n"; \
159+
$(MAKE) --no-print-directory _log_bash_zsh INSTALL_LOCATION=$(INSTALL_LOCATION); \
160+
$(MAKE) --no-print-directory _log_fish INSTALL_LOCATION=$(INSTALL_LOCATION); \
161+
$(MAKE) --no-print-directory _log_next_steps; \
162+
fi
163+
164+
# ── Instruções bash / zsh ─────────────────────────────────────────────────────
165+
.PHONY: _log_bash_zsh
166+
_log_bash_zsh:
167+
@printf "$(BOLD)$(CYAN) ┌─ Bash / Zsh $(GRAY)─────────────────────────────────────────────$(RESET)\n"
168+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
169+
@printf "$(BOLD)$(CYAN)$(RESET) Adicione ao final do $(BOLD)~/.bashrc$(RESET) $(GRAY)(bash)$(RESET) ou $(BOLD)~/.zshrc$(RESET) $(GRAY)(zsh)$(RESET):\n"
170+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
171+
@printf "$(BOLD)$(CYAN)$(RESET) $(GRAY)# cpp-gen$(RESET)\n"
172+
@printf "$(BOLD)$(CYAN)$(RESET) $(GREEN)export PATH=\"$(INSTALL_LOCATION):\$$PATH\"$(RESET)\n"
173+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
174+
@printf "$(BOLD)$(CYAN)$(RESET) Ou execute o comando abaixo para adicionar automaticamente:\n"
175+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
176+
@printf "$(BOLD)$(CYAN)$(RESET) $(GRAY)# bash:$(RESET)\n"
177+
@printf "$(BOLD)$(CYAN)$(RESET) $(YELLOW)echo 'export PATH=\"$(INSTALL_LOCATION):\$$PATH\"' >> ~/.bashrc$(RESET)\n"
178+
@printf "$(BOLD)$(CYAN)$(RESET) $(YELLOW)source ~/.bashrc$(RESET)\n"
179+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
180+
@printf "$(BOLD)$(CYAN)$(RESET) $(GRAY)# zsh:$(RESET)\n"
181+
@printf "$(BOLD)$(CYAN)$(RESET) $(YELLOW)echo 'export PATH=\"$(INSTALL_LOCATION):\$$PATH\"' >> ~/.zshrc$(RESET)\n"
182+
@printf "$(BOLD)$(CYAN)$(RESET) $(YELLOW)source ~/.zshrc$(RESET)\n"
183+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
184+
@printf "$(BOLD)$(CYAN) └─────────────────────────────────────────────────────────────$(RESET)\n"
185+
@printf "\n"
186+
187+
# ── Instruções fish ───────────────────────────────────────────────────────────
188+
.PHONY: _log_fish
189+
_log_fish:
190+
@printf "$(BOLD)$(CYAN) ┌─ Fish Shell $(GRAY)────────────────────────────────────────────$(RESET)\n"
191+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
192+
@printf "$(BOLD)$(CYAN)$(RESET) $(BOLD)Opção 1$(RESET) — Comando único $(GRAY)(persistente, recomendado)$(RESET):\n"
193+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
194+
@printf "$(BOLD)$(CYAN)$(RESET) $(YELLOW)fish_add_path $(INSTALL_LOCATION)$(RESET)\n"
195+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
196+
@printf "$(BOLD)$(CYAN)$(RESET) $(BOLD)Opção 2$(RESET) — Adicione ao $(BOLD)~/.config/fish/config.fish$(RESET):\n"
197+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
198+
@printf "$(BOLD)$(CYAN)$(RESET) $(GRAY)# cpp-gen$(RESET)\n"
199+
@printf "$(BOLD)$(CYAN)$(RESET) $(GREEN)fish_add_path $(INSTALL_LOCATION)$(RESET)\n"
200+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
201+
@printf "$(BOLD)$(CYAN)$(RESET) Ou com set -x para compatibilidade:\n"
202+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
203+
@printf "$(BOLD)$(CYAN)$(RESET) $(GREEN)set -x PATH $(INSTALL_LOCATION) \$$PATH$(RESET)\n"
204+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
205+
@printf "$(BOLD)$(CYAN)$(RESET) Ou execute o comando abaixo para adicionar automaticamente:\n"
206+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
207+
@printf "$(BOLD)$(CYAN)$(RESET) $(YELLOW)echo 'fish_add_path $(INSTALL_LOCATION)' >> ~/.config/fish/config.fish$(RESET)\n"
208+
@printf "$(BOLD)$(CYAN)$(RESET)\n"
209+
@printf "$(BOLD)$(CYAN) └─────────────────────────────────────────────────────────────$(RESET)\n"
210+
@printf "\n"
211+
212+
# ── Próximos passos ───────────────────────────────────────────────────────────
213+
.PHONY: _log_next_steps
214+
_log_next_steps:
215+
@printf "$(BOLD) Após configurar o PATH, recarregue o shell e execute:$(RESET)\n"
216+
@printf "\n"
217+
@printf " $(BOLD)$(CYAN)$(BINARY) --help$(RESET) $(GRAY)# exibe a ajuda$(RESET)\n"
218+
@printf " $(BOLD)$(CYAN)$(BINARY) new meu-projeto$(RESET) $(GRAY)# cria um projeto interativamente$(RESET)\n"
219+
@printf " $(BOLD)$(CYAN)$(BINARY) version$(RESET) $(GRAY)# confirma a versão instalada$(RESET)\n"
220+
@printf "\n"
221+
@printf " $(GRAY)Para desinstalar: $(RESET)$(YELLOW)make uninstall$(RESET)\n"
222+
@printf "\n"

0 commit comments

Comments
 (0)