File size: 31,599 Bytes
04da94d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | <#
.SYNOPSIS
build_tool - Compilador modular para múltiplas linguagens.
.DESCRIPTION
Detecta automaticamente o tipo de projeto e compila usando o comando
adequado. Suporta: Rust, Python, C, C++, Go, JavaScript/Node, TypeScript, Java.
#>
$BuildToolVersion = "1.0.0"
# ============================================================================
# FUNÇÕES AUXILIARES
# ============================================================================
Function Global:Detect-Language {
<#
.DESCRIPTION
Detecta automaticamente a linguagem do projeto analisando arquivos de configuração.
#>
Param(
[string]$Path
)
# Verificar arquivos de configuração comuns
$configFiles = @(
"Cargo.toml",
"package.json",
"pkg.json",
"setup.py",
"pyproject.toml",
"CMakeLists.txt",
"CMakeLists",
"Makefile",
"Gopkg.toml",
"go.mod",
"build.gradle",
"build.gradle.kts",
"pom.xml",
"build.pom.xml",
".csproj",
".vbproj",
".fsproj",
".psm1",
"Rakefile",
"Gemfile"
)
foreach ($cfg in $configFiles) {
$cfgPath = Join-Path $Path $cfg
if (Test-Path $cfgPath) {
# Determinar linguagem baseado no arquivo
switch ($cfg) {
"Cargo.toml" { return "Rust" }
"setup.py" { return "Python" }
"pyproject.toml" { return "Python" }
"Gopkg.toml" { return "Rust" }
"go.mod" { return "Go" }
"build.gradle" { return "Java" }
"build.gradle.kts" { return "Java" }
"pom.xml" { return "Java" }
"build.pom.xml" { return "Java" }
"build.gradle.kts" { return "Java" }
".vbproj" { return "VB.NET" }
".csproj" { return "C#" }
".fsproj" { return "F#" }
".psm1" { return "PowerShell" }
default { return "C" }
}
}
}
# Fallback: tentar detectar pelo conteúdo de arquivos fonte
$sourcePatterns = @{
"*.rs" = "Rust"
"*.py" = "Python"
"*.c" = "C"
"*.cpp" = "C++"
"*.h" = "C++"
"*.go" = "Go"
"*.java" = "Java"
"*.ts" = "TypeScript"
"*.tsx" = "TypeScript"
"*.js" = "JavaScript"
"*.cs" = "C#"
"*.vb" = "VB.NET"
"*.fs" = "F#"
}
foreach ($pair in $sourcePatterns.GetEnumerator()) {
$pattern = $pair.Key
$lang = $pair.Value
$files = Get-ChildItem -Path $Path -Include $pattern -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if ($files) {
return $lang
}
}
return "Unknown"
}
Function Global:Get-Compiler {
<#
.DESCRIPTION
Retorna o comando e argumentos do compilador adequado para cada linguagem.
#>
Param(
[string]$Language,
[string]$SourceFile,
[string]$OutputFile
)
$compilers = @{
"Rust" = @{
Command = "cargo"
Args = "build"
Source = "Cargo.toml"
Output = "target/debug/"
Executable = "debug/<name>"
}
"Python" = @{
Command = "pip"
Args = "install -e ."
Source = "setup.py"
Output = "dist/"
Executable = "app.exe"
}
"JavaScript" = @{
Command = "npm"
Args = "run build"
Source = "package.json"
Output = "dist/"
Executable = "dist/<name>.js"
}
"TypeScript" = @{
Command = "npm"
Args = "run build"
Source = "package.json"
Output = "dist/"
Executable = "dist/<name>.js"
}
"C" = @{
Command = "gcc"
Args = "-o $OutputFile $SourceFile"
Output = "output.exe"
}
"C++" = @{
Command = "g++"
Args = "-o $OutputFile $SourceFile"
Output = "output.exe"
}
"Go" = @{
Command = "go"
Args = "build -o $OutputFile ./"
Output = "output.exe"
}
"Java" = @{
Command = "mvn"
Args = "package"
Source = "pom.xml"
Output = "target/"
Executable = "target/<artifact>-jar-dependencies.jar"
}
"VB.NET" = @{
Command = "dotnet"
Args = "build"
Source = ".vbproj"
Output = "bin/"
Executable = "bin/<name>.dll"
}
"C#" = @{
Command = "dotnet"
Args = "build"
Source = ".csproj"
Output = "bin/"
Executable = "bin/<name>.dll"
}
"F#" = @{
Command = "dotnet"
Args = "build"
Source = ".fsproj"
Output = "bin/"
Executable = "bin/<name>.dll"
}
"PowerShell" = @{
Command = "pwsh"
Args = "-NoProfile -ExecutionPolicy Bypass"
Source = "*.ps1"
Output = "bin/"
Executable = "bin/<name>.ps1"
}
"Ruby" = @{
Command = "bundle"
Args = "exec rake"
Source = "Rakefile"
Output = "bin/"
Executable = "bin/<name>"
}
}
if ($compilers.ContainsKey($Language)) {
$comp = $compilers[$Language]
return $comp
}
return @{ Command="unknown"; Args="" }
}
Function Global:Check-Compiler-Available {
<#
.DESCRIPTION
Verifica se um compilador/interpreter está disponível no sistema.
#>
Param(
[string]$Compiler
)
try {
$version = & $Compiler --version 2>&1
return $LASTEXITCODE -eq 0
} catch {
return $false
}
}
Function Global:Find-Compiler {
<#
.DESCRIPTION
Tenta encontrar o compilador em diferentes locais.
#>
Param(
[string]$Compiler
)
# Tentar sem caminho primeiro
if (Test-Path $Compiler) {
return $Compiler
}
# Tentar em PATH
try {
$compilerInPath = $null
if ($Compiler -eq "python" -or $Compiler -eq "python3") {
# Python pode estar em múltiplos locais
foreach ($pyPath in @("python", "python3", "C:\Python*Python.exe", "C:\Python*python.exe")) {
if (Test-Path $pyPath) { return $pyPath }
}
} elseif ($Compiler -eq "npm" -or $Compiler -eq "node") {
foreach ($nodePath in @("node", "C:\Program Files\nodejs\node.exe", "C:\npm\node.exe")) {
if (Test-Path $nodePath) { return $nodePath }
}
} elseif ($Compiler -eq "cargo" -or $Compiler -eq "rustc") {
foreach ($rustPath in @("cargo", "rustc", "C:\Program Files\rga\cargo.exe", "C:\Program Files\rga\rustc.exe", "$env:LOCALAPPDATA\Programs\rust", "C:\msys64\mingw64\bin", "C:\msys64\usr\bin")) {
if (Test-Path $rustPath) { return $rustPath }
}
} elseif ($Compiler -eq "gcc" -or $Compiler -eq "g++" -or $Compiler -eq "clang") {
foreach ($gccPath in @("gcc", "g++", "clang", "clang++", "C:\Program Files\LLVM\bin", "C:\MinGW\bin", "$env:PATH")) {
try {
if (Test-Path $gccPath) { return $gccPath }
} catch {}
}
} elseif ($Compiler -eq "go") {
foreach ($goPath in @("go", "C:\Program Files\go\go.exe", "$env:GOROOT\bin\go.exe")) {
if (Test-Path $goPath) { return $goPath }
}
} elseif ($Compiler -eq "mvn") {
foreach ($mvnPath in @("mvn", "C:\Program Files\Apache Maven\bin\mvn.cmd", "C:\Program Files\Apache Maven3\bin\mvn.cmd")) {
if (Test-Path $mvnPath) { return $mvnPath }
}
} elseif ($Compiler -eq "dotnet") {
if (Test-Path "dotnet") { return "dotnet" }
}
} catch {}
return $null
}
Function Global:Parse-Project-Config {
<#
.DESCRIPTION
Extrai informações de configuração de projeto.
#>
Param(
[string]$Path,
[string]$ConfigFile
)
$configPath = Join-Path $Path $ConfigFile
if (-not (Test-Path $configPath)) {
return $null
}
try {
# Tentar JSON primeiro
$config = Get-Content $configPath -ErrorAction SilentlyContinue | ConvertFrom-Json
return @{
Name = $config.name
Version = $config.version
Output = $config.output
MainFile = $config.main || $config.entry
Source = $config.source || $config.src
Dependencies = $config.dependencies
Scripts = $config.scripts
}
} catch {
# Tentar XML para projetos .NET
if ($configPath -like "*.xml") {
return @{
Name = $config.productname
Version = $config.version
}
}
return $null
}
}
Function Global:Format-Build-Result {
<#
.DESCRIPTION
Cria um objeto de resultado estruturado para build.
#>
Param(
[Parameter(Mandatory=$true)]
[string]$Status, # success, fail, partial
[Parameter(Mandatory=$true)]
[string]$Command,
[Parameter(Mandatory=$true)]
[double]$Duration,
[string]$OutputPath = $null,
[string]$Errors = $null,
[string]$Warnings = $null
)
$result = [PSCustomObject] @{
Status = $Status
Command = $Command
Duration = $Duration
OutputPath = $OutputPath
Errors = $Errors
Warnings = $Warnings
Timestamp = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"
Language = "unknown"
Mode = "compile"
}
return $result
}
# ============================================================================
# FUNÇÃO PRINCIPAL
# ============================================================================
Function Global:Build-Project {
<#
.SYNOPSIS
Compila um projeto detectando automaticamente a linguagem.
.DESCRIPTION
Detecta o tipo de projeto, verifica ferramentas necessárias,
executa compilação e retorna resultado estruturado.
.PARAMETER Path
Caminho para o diretório do projeto a compilar.
.PARAMETER Output
Caminho de saída do executável ou bundle gerado.
.PARAMETER Mode
Modo de operação:
- compile: compila padrão
- bundle: cria executável bundlado
- lint: executa análise estática
- clean: limpa diretórios de build
- test: executa testes
.PARAMETER Quiet
Modo silencioso - minimiza output durante o build.
.PARAMETER Verbose
Mostra mais detalhes durante o processo de compilação.
.EXAMPLE
Build-Project -Path "C:\myproject"
.EXAMPLE
Build-Project -Path "C:\rustproject" -Mode "bundle" -Output "dist\app.exe"
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]$Path,
[string]$Output,
[string]$Mode = "compile",
[switch]$Quiet,
[switch]$Verbose
)
$startTime = Get-Date
$results = [PSCustomObject]@{
Status = "fail"
Command = "unknown"
Duration = 0
OutputPath = $null
Errors = $null
Warnings = $null
Language = "unknown"
Mode = $Mode
Timestamp = (Get-Date).ToString('yyyy-MM-ddTHH:mm:ssZ')
}
begin {
if ($Verbose) {
Write-Host "`n=== BUILD TOOL $BuildToolVersion ===" -ForegroundColor Cyan
Write-Host "Project Path: $Path" -ForegroundColor Yellow
Write-Host "Mode: $Mode" -ForegroundColor Yellow
}
}
process {
# Validar caminho
if (-not (Test-Path $Path)) {
if ($Quiet) {
$results.Status = "fail"
$results.Errors = "Project path does not exist: $Path"
return $results
}
Write-Host "❌ Error: Project path does not exist: $Path" -ForegroundColor Red
return $results
}
# Detectar linguagem
$language = Detect-Language -Path $Path
$results.Language = $language
if ($language -eq "Unknown") {
if (-not $Quiet) {
Write-Host "❌ Error: Could not detect project language. Supported: Rust, Python, C, C++, Go, JavaScript, TypeScript, Java, Ruby, VB.NET, C#, F#, PowerShell" -ForegroundColor Red
}
$results.Errors = "Could not detect project language. Supported: Rust, Python, C, C++, Go, JavaScript, TypeScript, Java, Ruby, VB.NET, C#, F#, PowerShell"
return $results
}
if (-not $Quiet) {
Write-Host "✅ Detected project language: $language" -ForegroundColor Green
}
# Encontrar arquivo de configuração principal
$configFile = $null
$config = $null
switch ($language) {
"Rust" { $configFile = "Cargo.toml" }
"Python" { $configFile = "setup.py"; $altConfig = "pyproject.toml" }
"JavaScript" { $configFile = "package.json" }
"TypeScript" { $configFile = "package.json" }
"C" { $configFile = "Makefile" }
"C++" { $configFile = "CMakeLists.txt" }
"Go" { $configFile = "go.mod" }
"Java" { $configFile = "pom.xml"; $altConfig = "build.gradle" }
"Ruby" { $configFile = "Rakefile" }
"VB.NET" { $configFile = ".vbproj" }
"C#" { $configFile = ".csproj" }
"F#" { $configFile = ".fsproj" }
"PowerShell" { $configFile = "*.psm1" }
}
# Verificar arquivo de configuração
$fullConfigPath = Join-Path $Path $configFile
if (-not (Test-Path $fullConfigPath)) {
if (-not $Quiet) {
Write-Host "⚠️ Warning: Config file not found: $configFile" -ForegroundColor Yellow
}
} else {
$config = Parse-Project-Config -Path $Path -ConfigFile $configFile
}
# Modo clean
if ($Mode -eq "clean") {
if (-not $Quiet) {
Write-Host "🧹 Cleaning build artifacts..." -ForegroundColor Cyan
}
# Identificar diretórios de build
$buildDirs = @(
"target", # Rust, .NET
"build", # C/C++
"dist", # JavaScript
"bin", # .NET
"__pycache__", # Python
".pytest_cache", # Python tests
".tox", # Python
"node_modules" # NPM
)
foreach ($dir in $buildDirs) {
$dirPath = Join-Path $Path $dir
if (Test-Path $dirPath) {
if ($Quiet) {
$null = Remove-Item -Path $dirPath -Recurse -Force -ErrorAction SilentlyContinue
continue
}
Write-Host " Removing: $dirPath" -ForegroundColor Gray
$null = Remove-Item -Path $dirPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
$results.Status = "success"
$results.Command = "clean"
$results.Duration = (Get-Date).Subtract($startTime).TotalSeconds
if ($Quiet) {
return $results
}
Write-Host "✅ Build artifacts cleaned." -ForegroundColor Green
return $results
}
# Modo lint
if ($Mode -eq "lint") {
if ($Quiet) {
$results.Status = "partial"
$results.Command = "lint"
$results.OutputPath = Join-Path $Path ".lint_report"
return $results
}
Write-Host "📝 Running linting checks..." -ForegroundColor Cyan
switch ($language) {
"JavaScript" {
if (Test-Path (Join-Path $Path "package.json")) {
try {
$null = Invoke-Expression "npm run lint 2>&1" 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$results.Status = "success"
} else {
$results.Status = "partial"
}
} catch {
$results.Status = "partial"
}
}
}
"Python" {
if (Test-Path (Join-Path $Path "setup.py")) {
try {
$null = Invoke-Expression "python -m py_compile ." 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$results.Status = "success"
} else {
$results.Status = "partial"
}
} catch {
$results.Status = "partial"
}
}
}
"Rust" {
try {
$null = Invoke-Expression "cargo check 2>&1" 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$results.Status = "success"
} else {
$results.Status = "partial"
}
} catch {
$results.Status = "partial"
}
}
"Go" {
try {
$null = Invoke-Expression "go vet ./... 2>&1" 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$results.Status = "success"
} else {
$results.Status = "partial"
}
} catch {
$results.Status = "partial"
}
}
"Java" {
try {
$null = Invoke-Expression "mvn checkstyle:check 2>&1" 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$results.Status = "success"
} else {
$results.Status = "partial"
}
} catch {
$results.Status = "partial"
}
}
"C" | "C++" {
try {
$null = Invoke-Expression "clang-format --diff . 2>&1" 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$results.Status = "success"
} else {
$results.Status = "partial"
}
} catch {
$results.Status = "partial"
}
}
}
$results.Command = "lint"
$results.Duration = (Get-Date).Subtract($startTime).TotalSeconds
if ($Quiet) {
return $results
}
Write-Host "✅ Linting complete. Status: $($results.Status)" -ForegroundColor Gray
return $results
}
# Modo test
if ($Mode -eq "test") {
if ($Quiet) {
$results.Status = "partial"
$results.Command = "test"
$results.OutputPath = Join-Path $Path ".test_results"
return $results
}
Write-Host "🧪 Running tests..." -ForegroundColor Cyan
switch ($language) {
"Rust" {
try {
$null = Invoke-Expression "cargo test --no-fail-fast 2>&1" 2>&1
$exitCode = $LASTEXITCODE
} catch { $exitCode = $LASTEXITCODE }
}
"Python" {
try {
$null = Invoke-Expression "python -m unittest discover -s . 2>&1" 2>&1
$exitCode = $LASTEXITCODE
} catch { $exitCode = $LASTEXITCODE }
}
"JavaScript" {
try {
$null = Invoke-Expression "npm run test 2>&1" 2>&1
$exitCode = $LASTEXITCODE
} catch { $exitCode = $LASTEXITCODE }
}
"Go" {
try {
$null = Invoke-Expression "go test ./... -v 2>&1" 2>&1
$exitCode = $LASTEXITCODE
} catch { $exitCode = $LASTEXITCODE }
}
"Java" {
try {
$null = Invoke-Expression "mvn test 2>&1" 2>&1
$exitCode = $LASTEXITCODE
} catch { $exitCode = $LASTEXITCODE }
}
"Ruby" {
try {
$null = Invoke-Expression "bundle exec rake test 2>&1" 2>&1
$exitCode = $LASTEXITCODE
} catch { $exitCode = $LASTEXITCODE }
}
}
if ($exitCode -eq 0) {
$results.Status = "success"
} else {
$results.Status = "partial"
}
$results.Command = "test"
$results.Duration = (Get-Date).Subtract($startTime).TotalSeconds
if ($Quiet) {
return $results
}
Write-Host "✅ Tests complete. Status: $($results.Status)" -ForegroundColor Gray
return $results
}
# Modo bundle
if ($Mode -eq "bundle") {
if (-not $Quiet) {
Write-Host "📦 Creating bundled executable..." -ForegroundColor Cyan
}
$compiler = Get-Compiler -Language $language -OutputFile $Output
# Verificar se bundler está disponível
$bundleAvailable = $false
switch ($language) {
"Rust" {
$bundleAvailable = Check-Compiler-Available -Compiler "cargo-bundle"
if ($bundleAvailable) {
try {
$null = Invoke-Expression "cargo binstall cargo-bundle --force 2>&1" 2>&1
} catch {}
$bundleAvailable = Check-Compiler-Available -Compiler "cargo-bundle"
}
}
"Python" {
$bundleAvailable = Check-Compiler-Available -Compiler "pyinstaller"
}
"JavaScript" {
$bundleAvailable = Check-Compiler-Available -Compiler "webpack-cli"
}
}
if ($bundleAvailable) {
if ($Quiet) {
$results.Status = "success"
$results.Command = "bundle"
return $results
}
Write-Host "✅ Bundler available: $(if ($bundleAvailable) { 'yes' } else { 'no' })" -ForegroundColor Gray
} else {
if ($Quiet) {
$results.Errors = "Bundler not available for $language"
return $results
}
Write-Host "⚠️ Warning: Bundler not available, falling back to compilation" -ForegroundColor Yellow
}
$results.Command = "bundle"
$results.Status = "partial"
$results.Duration = (Get-Date).Subtract($startTime).TotalSeconds
if ($Quiet) {
return $results
}
Write-Host "✅ Bundle mode attempted (fallback to compile if bundler unavailable)" -ForegroundColor Gray
return $results
}
# Modo compile padrão
Write-Host "🔨 Compiling project ($language)..." -ForegroundColor Cyan
$compiler = Get-Compiler -Language $language -OutputFile $Output
# Verificar se compilador está disponível
$compilerAvailable = $false
$compilerPath = Find-Compiler -Compiler $compiler.Command
if ($compilerPath) {
$compilerAvailable = $true
}
if (-not $compilerAvailable) {
if ($Quiet) {
$results.Errors = "Compiler not found: $($compiler.Command)"
return $results
}
Write-Host "❌ Error: Compiler not found: $($compiler.Command)" -ForegroundColor Red
Write-Host " Please install $($compiler.Command) to compile $language projects." -ForegroundColor Yellow
$results.Errors = "Compiler not found: $($compiler.Command). Please install $($compiler.Command) to compile $language projects."
return $results
}
if ($Quiet) {
$results.Status = "success"
$results.Command = "$(if ($compiler.Command -eq "cargo") { "cargo build" } elseif ($compiler.Command -eq "npm") { "npm run build" } elseif ($compiler.Command -eq "pip" -and $language -eq "Python" ) { "pip install -e . " } elseif ($compiler.Command -eq "gcc") { "gcc -o output.exe source.c" } elseif ($compiler.Command -eq "dotnet") { "dotnet build" } elseif ($compiler.Command -eq "go") { "go build" } elseif ($compiler.Command -eq "python") { "python setup.py build" } elseif ($compiler.Command -eq "mvn") { "mvn package" } elseif ($compiler.Command -eq "bundle") { "bundle exec rake" } else { $compiler.Command })"
return $results
}
# Executar compilação
$commandBase = $compiler.Command
# Construir comando base
switch ($language) {
"Rust" {
$cmd = "cargo build"
if ($Output) {
$cmd = "cargo build --release -o $Output"
}
}
"Python" {
$cmd = "pip install -e ."
if ($config -and $config.Scripts) {
if ($config.Scripts.build) {
$cmd = "npm run build"
} elseif ($config.Scripts.install -match "python") {
$cmd = "pip install -e ."
}
}
}
"JavaScript" {
if ($config -and $config.Scripts) {
if ($config.Scripts.build) {
$cmd = "npm run build"
} elseif ($config.Scripts.dev) {
$cmd = "npm run dev"
} else {
$cmd = "npm run build"
}
} else {
$cmd = "npm run build"
}
}
"TypeScript" {
if ($config -and $config.Scripts) {
if ($config.Scripts.build) {
$cmd = "npm run build"
} elseif ($config.Scripts.dev) {
$cmd = "npm run dev"
} else {
$cmd = "npm run build"
}
} else {
$cmd = "npm run build"
}
}
"C" {
if ($configFile -eq "CMakeLists.txt") {
$cmd = "cmake --build build --config Release"
} elseif ($configFile -eq "Makefile") {
$cmd = "make"
} else {
$cmd = "gcc -o $Output $SourceFile"
}
}
"C++" {
if ($configFile -eq "CMakeLists.txt") {
$cmd = "cmake --build build --config Release"
} elseif ($configFile -eq "Makefile") {
$cmd = "make"
} else {
$cmd = "g++ -o $Output $SourceFile"
}
}
"Go" {
$cmd = "go build -o $Output ."
}
"Java" {
$cmd = "mvn package"
}
"VB.NET" {
$cmd = "dotnet build"
if ($Output) {
$cmd += " -o $Output"
}
}
"C#" {
$cmd = "dotnet build"
if ($Output) {
$cmd += " -o $Output"
}
}
"F#" {
$cmd = "dotnet build"
if ($Output) {
$cmd += " -o $Output"
}
}
"Ruby" {
$cmd = "bundle exec rake"
}
default {
$cmd = "build"
}
}
$results.Command = $cmd
Write-Host "Command: $cmd" -ForegroundColor Gray
if ($Verbose) {
Write-Host "Executing: $cmd" -ForegroundColor Cyan
}
try {
if ($Quiet) {
$null = Invoke-Expression $cmd
} else {
Invoke-Expression $cmd
}
} catch {
if ($Quiet) {
$results.Errors = $_.Exception.Message
return $results
}
Write-Host "❌ Compilation error: $_" -ForegroundColor Red
}
# Verificar resultado
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$results.Status = "success"
} elseif ($exitCode -eq 1) {
$results.Status = "partial"
} else {
$results.Status = "fail"
}
$results.Duration = (Get-Date).Subtract($startTime).TotalSeconds
$results.OutputPath = if ($Output) { $Output } else { "build/$($language).exe" }
if ($Quiet) {
return $results
}
Write-Host "✅ Build complete! Duration: $($results.Duration) seconds" -ForegroundColor Green
Write-Host "Output: $($results.OutputPath)" -ForegroundColor Gray
return $results
}
end {
if ($Verbose -and $results.Status -ne "fail") {
Write-Host "`n=== Build Summary ===" -ForegroundColor Cyan
Write-Host "Status: $($results.Status)" -ForegroundColor $(if ($results.Status -eq "success") { "Green" } elseif ($results.Status -eq "partial") { "Yellow" } else { "Red" })
Write-Host "Duration: $($results.Duration) seconds" -ForegroundColor Gray
Write-Host "Command: $($results.Command)" -ForegroundColor Gray
}
}
}
# Export all functions
Export-ModuleMember -Function Build-Project, Detect-Language, Get-Compiler, Check-Compiler-Available, Find-Compiler, Parse-Project-Config, Format-Build-Result
|