build_webUI command does it all

This commit is contained in:
proddy
2025-11-15 14:21:50 +01:00
parent d2a8fbaf1e
commit bcde5bad63
2 changed files with 21 additions and 22 deletions

View File

@@ -10,11 +10,11 @@ def get_pnpm_executable():
"""Get the appropriate pnpm executable for the current platform.""" """Get the appropriate pnpm executable for the current platform."""
# Try different pnpm executable names # Try different pnpm executable names
pnpm_names = ['pnpm', 'pnpm.cmd', 'pnpm.exe'] pnpm_names = ['pnpm', 'pnpm.cmd', 'pnpm.exe']
for name in pnpm_names: for name in pnpm_names:
if shutil.which(name): if shutil.which(name):
return name return name
# Fallback to pnpm if not found # Fallback to pnpm if not found
return 'pnpm' return 'pnpm'
@@ -30,14 +30,14 @@ def run_command_in_directory(command, directory):
capture_output=True, capture_output=True,
text=True text=True
) )
if result.stdout: if result.stdout:
print(result.stdout) print(result.stdout)
if result.stderr: if result.stderr:
print(result.stderr) print(result.stderr)
return True return True
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print(f"Command failed: {command}") print(f"Command failed: {command}")
print(f"Error: {e}") print(f"Error: {e}")
@@ -54,36 +54,34 @@ def run_command_in_directory(command, directory):
def buildWeb(): def buildWeb():
interface_dir = Path("interface") interface_dir = Path("interface")
pnpm_exe = get_pnpm_executable() pnpm_exe = get_pnpm_executable()
# Set CI environment variable to make pnpm use silent mode # Set CI environment variable to make pnpm use silent mode
os.environ['CI'] = 'true' os.environ['CI'] = 'true'
print("Building web interface...") print("Building web interface...")
# Check if interface directory exists # Check if interface directory exists
if not interface_dir.exists(): if not interface_dir.exists():
print(f"Error: Interface directory '{interface_dir}' not found!") print(f"Error: Interface directory '{interface_dir}' not found!")
return False return False
# Check if pnpm is available # Check if pnpm is available
if not shutil.which(pnpm_exe): if not shutil.which(pnpm_exe):
print(f"Error: '{pnpm_exe}' not found in PATH!") print(f"Error: '{pnpm_exe}' not found in PATH!")
return False return False
try: try:
# Run pnpm commands in the interface directory # Run pnpm commands in the interface directory
commands = [ commands = [
f"{pnpm_exe} install", f"{pnpm_exe} install",
f"{pnpm_exe} typesafe-i18n", f"{pnpm_exe} build_webUI"
f"{pnpm_exe} build",
f"{pnpm_exe} webUI"
] ]
for command in commands: for command in commands:
print(f"Running: {command}") print(f"Running: {command}")
if not run_command_in_directory(command, interface_dir): if not run_command_in_directory(command, interface_dir):
return False return False
# Modify i18n-util.ts file # Modify i18n-util.ts file
i18n_file = interface_dir / "src" / "i18n" / "i18n-util.ts" i18n_file = interface_dir / "src" / "i18n" / "i18n-util.ts"
if i18n_file.exists(): if i18n_file.exists():
@@ -93,11 +91,12 @@ def buildWeb():
w.write(text) w.write(text)
print("Setting WebUI locale to 'en'") print("Setting WebUI locale to 'en'")
else: else:
print(f"Warning: {i18n_file} not found, skipping locale modification") print(
f"Warning: {i18n_file} not found, skipping locale modification")
print("Web interface build completed successfully!") print("Web interface build completed successfully!")
return True return True
except Exception as e: except Exception as e:
print(f"Error building web interface: {e}") print(f"Error building web interface: {e}")
return False return False
@@ -108,8 +107,9 @@ def build_webUI(*args, **kwargs):
if not success: if not success:
print("Web interface build failed!") print("Web interface build failed!")
env.Exit(1) env.Exit(1)
env.Exit(0) env.Exit(0)
# Create custom target that only runs the script and then exits, without continuing with the pio workflow # Create custom target that only runs the script and then exits, without continuing with the pio workflow
env.AddCustomTarget( env.AddCustomTarget(
name="build", name="build",
@@ -119,4 +119,3 @@ env.AddCustomTarget(
description="installs pnpm packages, updates libraries and builds web UI", description="installs pnpm packages, updates libraries and builds web UI",
always_build=True always_build=True
) )

View File

@@ -20,7 +20,7 @@ pnpm format
cd .. cd ..
cd interface cd interface
pnpm webUI pnpm build_webUI
cd .. cd ..
npx cspell "**" npx cspell "**"