Skip to content

Commit 0ba6009

Browse files
author
Taniya Mathur
committed
Add real-time progress display for npm install in publish.py
1 parent 7e97747 commit 0ba6009

File tree

1 file changed

+65
-12
lines changed

1 file changed

+65
-12
lines changed

publish.py

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,64 @@ def log_error_details(self, component, error_output):
116116
f"[red]❌ {component} build failed (use --verbose for details)[/red]"
117117
)
118118

119-
def run_subprocess_with_logging(self, cmd, component_name, cwd=None):
119+
def run_subprocess_with_logging(self, cmd, component_name, cwd=None, realtime=False):
120120
"""Run subprocess with standardized logging"""
121-
result = subprocess.run(cmd, capture_output=True, text=True, cwd=cwd)
122-
if result.returncode != 0:
123-
error_msg = f"""Command failed: {" ".join(cmd)}
121+
if realtime:
122+
# Real-time output for long-running processes like npm install
123+
self.console.print(f"[cyan]Running: {' '.join(cmd)}[/cyan]")
124+
125+
try:
126+
process = subprocess.Popen(
127+
cmd,
128+
stdout=subprocess.PIPE,
129+
stderr=subprocess.STDOUT,
130+
text=True,
131+
cwd=cwd,
132+
bufsize=1,
133+
universal_newlines=True
134+
)
135+
136+
output_lines = []
137+
while True:
138+
output = process.stdout.readline()
139+
if output == '' and process.poll() is not None:
140+
break
141+
if output:
142+
line = output.strip()
143+
output_lines.append(line)
144+
# Show progress for npm commands
145+
if 'npm' in ' '.join(cmd):
146+
if any(keyword in line.lower() for keyword in ['downloading', 'installing', 'added', 'updated', 'audited']):
147+
self.console.print(f"[dim] {line}[/dim]")
148+
elif 'warn' in line.lower():
149+
self.console.print(f"[yellow] {line}[/yellow]")
150+
elif 'error' in line.lower():
151+
self.console.print(f"[red] {line}[/red]")
152+
153+
return_code = process.poll()
154+
155+
if return_code != 0:
156+
error_msg = f"""Command failed: {" ".join(cmd)}
157+
Working directory: {cwd or os.getcwd()}
158+
Return code: {return_code}
159+
160+
OUTPUT:
161+
{chr(10).join(output_lines)}"""
162+
print(error_msg)
163+
self.log_error_details(component_name, error_msg)
164+
return False, error_msg
165+
166+
return True, None # Success, no result object needed for real-time
167+
168+
except Exception as e:
169+
error_msg = f"Failed to execute command: {' '.join(cmd)}\nError: {str(e)}"
170+
self.log_error_details(component_name, error_msg)
171+
return False, error_msg
172+
else:
173+
# Original behavior - capture all output
174+
result = subprocess.run(cmd, capture_output=True, text=True, cwd=cwd)
175+
if result.returncode != 0:
176+
error_msg = f"""Command failed: {" ".join(cmd)}
124177
Working directory: {cwd or os.getcwd()}
125178
Return code: {result.returncode}
126179
@@ -129,10 +182,10 @@ def run_subprocess_with_logging(self, cmd, component_name, cwd=None):
129182
130183
STDERR:
131184
{result.stderr}"""
132-
print(error_msg)
133-
self.log_error_details(component_name, error_msg)
134-
return False, error_msg
135-
return True, result
185+
print(error_msg)
186+
self.log_error_details(component_name, error_msg)
187+
return False, error_msg
188+
return True, result
136189

137190
def print_error_summary(self):
138191
"""Print summary of all build errors"""
@@ -1123,18 +1176,18 @@ def validate_ui_build(self):
11231176
return
11241177

11251178
# Run npm install first
1126-
self.log_verbose("Running npm install for UI dependencies...")
1179+
self.console.print("[cyan]📦 Installing UI dependencies (this may take a while)...[/cyan]")
11271180
success, result = self.run_subprocess_with_logging(
1128-
["npm", "install"], "UI npm install", ui_dir
1181+
["npm", "install"], "UI npm install", ui_dir, realtime=True
11291182
)
11301183

11311184
if not success:
11321185
raise Exception("npm install failed")
11331186

11341187
# Run npm run build to validate ESLint/Prettier
1135-
self.log_verbose("Running npm run build for UI validation...")
1188+
self.console.print("[cyan]🔨 Building UI (validating ESLint/Prettier)...[/cyan]")
11361189
success, result = self.run_subprocess_with_logging(
1137-
["npm", "run", "build"], "UI build validation", ui_dir
1190+
["npm", "run", "build"], "UI build validation", ui_dir, realtime=True
11381191
)
11391192

11401193
if not success:

0 commit comments

Comments
 (0)