-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
280 lines (229 loc) · 9.39 KB
/
deploy.py
File metadata and controls
280 lines (229 loc) · 9.39 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
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
#!/usr/bin/env python3
"""Master deploy script — builds all eVera platforms.
Usage:
python deploy.py # Build everything for current platform
python deploy.py --desktop # Desktop only (Electron + PyInstaller)
python deploy.py --mobile # Mobile only (React Native APK/IPA)
python deploy.py --desktop --mobile # Both
python deploy.py --platform win # Electron for specific platform
"""
from __future__ import annotations
import argparse
import platform
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).parent
SYSTEM = platform.system()
def header(text: str) -> None:
print(f"\n{'=' * 60}")
print(f" {text}")
print(f"{'=' * 60}\n")
def run(cmd: str | list, cwd: Path = ROOT, check: bool = True) -> int:
if isinstance(cmd, str):
print(f" $ {cmd}")
result = subprocess.run(cmd, shell=True, cwd=str(cwd))
else:
print(f" $ {' '.join(cmd)}")
result = subprocess.run(cmd, cwd=str(cwd))
if check and result.returncode != 0:
print(f" ❌ Command failed with exit code {result.returncode}")
return result.returncode
def check_prereqs() -> dict[str, bool]:
"""Check which build tools are available."""
prereqs = {}
# Python + PyInstaller
try:
subprocess.run([sys.executable, "-m", "PyInstaller", "--version"], capture_output=True, timeout=10)
prereqs["pyinstaller"] = True
except Exception:
prereqs["pyinstaller"] = False
# Node.js
try:
subprocess.run(["node", "--version"], capture_output=True, timeout=10)
prereqs["node"] = True
except Exception:
prereqs["node"] = False
# npx / electron-builder
try:
subprocess.run(["npx", "--version"], capture_output=True, timeout=10)
prereqs["npx"] = True
except Exception:
prereqs["npx"] = False
# React Native CLI
try:
subprocess.run(["npx", "react-native", "--version"], capture_output=True, timeout=10)
prereqs["react-native"] = True
except Exception:
prereqs["react-native"] = False
# Android SDK (check for ANDROID_HOME)
import os
prereqs["android_sdk"] = bool(os.environ.get("ANDROID_HOME") or os.environ.get("ANDROID_SDK_ROOT"))
# Xcode (macOS only)
if SYSTEM == "Darwin":
try:
subprocess.run(["xcodebuild", "-version"], capture_output=True, timeout=10)
prereqs["xcode"] = True
except Exception:
prereqs["xcode"] = False
else:
prereqs["xcode"] = False
return prereqs
def build_desktop(plat: str = "current") -> bool:
"""Build the Electron desktop app."""
header(f"🖥️ Building Desktop App ({plat})")
# Step 1: Install Electron dependencies
electron_dir = ROOT / "electron"
node_modules = electron_dir / "node_modules"
if not node_modules.exists():
print("📦 Installing Electron dependencies...")
if run("npm install", cwd=electron_dir) != 0:
return False
# Step 2: Build backend + Electron
print(f"\n🔨 Building for platform: {plat}")
build_js = electron_dir / "build.js"
if run(f"node {build_js} {plat}", cwd=ROOT) != 0:
return False
# Step 3: Show output
dist_dir = electron_dir / "dist"
if dist_dir.exists():
installers = (
list(dist_dir.glob("*.exe"))
+ list(dist_dir.glob("*.dmg"))
+ list(dist_dir.glob("*.AppImage"))
+ list(dist_dir.glob("*.deb"))
)
if installers:
print("\n✅ Desktop installers built:")
for f in installers:
size_mb = f.stat().st_size / 1024 / 1024
print(f" 📦 {f.name} ({size_mb:.1f} MB)")
else:
print(f"\n✅ Desktop build complete. Check: {dist_dir}")
return True
def build_mobile_android() -> bool:
"""Build the React Native Android APK."""
header("📱 Building Android APK")
mobile_dir = ROOT / "mobile"
node_modules = mobile_dir / "node_modules"
# Step 1: Install dependencies
if not node_modules.exists():
print("📦 Installing React Native dependencies...")
if run("npm install", cwd=mobile_dir) != 0:
return False
# Step 2: Build release APK
android_dir = mobile_dir / "android"
if not android_dir.exists() or not (android_dir / "gradlew").exists():
print("⚠️ Android native project not initialized.")
print(" Run: cd mobile && npx react-native init VeraMobile --template react-native-template-typescript")
print(" Then copy src/ files into the generated project.")
print("\n Alternatively, generate the APK with:")
print(" cd mobile/android && ./gradlew assembleRelease")
return False
gradlew = "gradlew.bat" if SYSTEM == "Windows" else "./gradlew"
if run(f"{gradlew} assembleRelease", cwd=android_dir) != 0:
return False
# Step 3: Show output
apk_path = android_dir / "app" / "build" / "outputs" / "apk" / "release" / "app-release.apk"
if apk_path.exists():
size_mb = apk_path.stat().st_size / 1024 / 1024
print(f"\n✅ Android APK built: {apk_path} ({size_mb:.1f} MB)")
else:
print("\n✅ Android build complete. Check: mobile/android/app/build/outputs/apk/")
return True
def build_mobile_ios() -> bool:
"""Build the React Native iOS IPA."""
header("🍎 Building iOS IPA")
if SYSTEM != "Darwin":
print("⚠️ iOS builds require macOS with Xcode.")
print(" Transfer the project to a Mac and run:")
print(" cd mobile/ios && pod install")
print(" cd mobile && npx react-native run-ios --configuration Release")
return False
mobile_dir = ROOT / "mobile"
ios_dir = mobile_dir / "ios"
# Install pods
if (ios_dir / "Podfile").exists():
print("📦 Installing CocoaPods...")
if run("pod install", cwd=ios_dir) != 0:
print("⚠️ pod install failed. Install CocoaPods: gem install cocoapods")
return False
# Build archive
print("🔨 Building iOS archive...")
if (
run(
"xcodebuild -workspace VeraMobile.xcworkspace -scheme VeraMobile "
"-configuration Release -archivePath build/VeraMobile.xcarchive archive",
cwd=ios_dir,
)
!= 0
):
return False
# Export IPA
print("📦 Exporting IPA...")
if (
run(
"xcodebuild -exportArchive -archivePath build/VeraMobile.xcarchive "
"-exportPath build/ipa -exportOptionsPlist ExportOptions.plist",
cwd=ios_dir,
)
!= 0
):
print("⚠️ IPA export failed. You may need to configure signing in Xcode.")
return False
print("\n✅ iOS IPA built. Check: mobile/ios/build/ipa/")
return True
def main() -> None:
parser = argparse.ArgumentParser(description="eVera Deploy — Build all platforms")
parser.add_argument("--desktop", action="store_true", help="Build desktop (Electron) installer")
parser.add_argument("--mobile", action="store_true", help="Build mobile (Android APK + iOS IPA)")
parser.add_argument("--android-only", action="store_true", help="Build Android APK only")
parser.add_argument("--ios-only", action="store_true", help="Build iOS IPA only")
parser.add_argument(
"--platform",
default="current",
choices=["win", "mac", "linux", "all", "current"],
help="Desktop platform target",
)
parser.add_argument("--skip-prereq-check", action="store_true", help="Skip prerequisite check")
args = parser.parse_args()
# Default: build everything
build_all = not (args.desktop or args.mobile or args.android_only or args.ios_only)
print(f"""
╔══════════════════════════════════════════════════════════╗
║ 🚀 eVera Deploy v0.5.0 ║
║ System: {SYSTEM:<49}║
║ Desktop: {"Yes" if (build_all or args.desktop) else "No":<48}║
║ Mobile: {"Yes" if (build_all or args.mobile) else "No":<48}║
╚══════════════════════════════════════════════════════════╝
""")
# Check prerequisites
if not args.skip_prereq_check:
header("🔍 Checking Prerequisites")
prereqs = check_prereqs()
for name, available in prereqs.items():
icon = "✅" if available else "❌"
print(f" {icon} {name}")
print()
results = {}
# Desktop build
if build_all or args.desktop:
results["desktop"] = build_desktop(args.platform)
# Mobile builds
if build_all or args.mobile or args.android_only:
results["android"] = build_mobile_android()
if build_all or args.mobile or args.ios_only:
results["ios"] = build_mobile_ios()
# Summary
header("📊 Build Summary")
for target, success in results.items():
icon = "✅" if success else "❌"
print(f" {icon} {target}")
if all(results.values()):
print("\n🎉 All builds completed successfully!")
else:
failed = [k for k, v in results.items() if not v]
print(f"\n⚠️ Some builds failed: {', '.join(failed)}")
sys.exit(1)
if __name__ == "__main__":
main()