-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
83 lines (65 loc) · 2.4 KB
/
Copy pathbuild.py
File metadata and controls
83 lines (65 loc) · 2.4 KB
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
#!/usr/bin/env python3
"""Compila o instalador Windows do Stapp."""
from __future__ import annotations
import argparse
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
WEB_DIR = ROOT / "web"
NODE_MODULES = WEB_DIR / "node_modules"
INSTALLER_DIR = WEB_DIR / "src-tauri" / "target" / "release" / "bundle" / "nsis"
def command_path(name: str) -> str:
candidates = [f"{name}.cmd", name] if sys.platform == "win32" else [name]
for candidate in candidates:
found = shutil.which(candidate)
if found:
return found
raise RuntimeError(
f"'{name}' nao foi encontrado no PATH. Instale o Node.js e o pnpm antes de continuar."
)
def run(command: list[str]) -> None:
print(f"\n> {' '.join(command)}", flush=True)
subprocess.run(command, cwd=WEB_DIR, check=True)
def newest_installer() -> Path:
installers = list(INSTALLER_DIR.glob("*-setup.exe"))
if not installers:
raise RuntimeError(f"A build terminou, mas nenhum instalador apareceu em {INSTALLER_DIR}")
return max(installers, key=lambda path: path.stat().st_mtime)
def main() -> int:
parser = argparse.ArgumentParser(description="Compila o instalador .exe do Stapp.")
parser.add_argument(
"--install",
action="store_true",
help="reinstala as dependencias do frontend antes da build",
)
parser.add_argument(
"--check",
action="store_true",
help="executa todos os testes antes de gerar o instalador",
)
args = parser.parse_args()
if not WEB_DIR.is_dir():
raise RuntimeError(f"Diretorio do frontend nao encontrado: {WEB_DIR}")
pnpm = command_path("pnpm")
if args.install or not NODE_MODULES.is_dir():
run([pnpm, "install", "--frozen-lockfile"])
if args.check:
run([pnpm, "test"])
run([pnpm, "app:build"])
installer = newest_installer()
size_mb = installer.stat().st_size / (1024 * 1024)
print("\nBuild concluida.")
print(f"Instalador: {installer}")
print(f"Tamanho: {size_mb:.1f} MB")
return 0
if __name__ == "__main__":
try:
raise SystemExit(main())
except KeyboardInterrupt:
print("\nBuild cancelada.", file=sys.stderr)
raise SystemExit(130)
except (RuntimeError, subprocess.CalledProcessError) as error:
print(f"\nErro: {error}", file=sys.stderr)
raise SystemExit(1)