Export Error Handling + Improved CLI (#1359)
This commit is contained in:
parent
4a661a5395
commit
be9120b251
@ -9,10 +9,10 @@ import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Optional, Union
|
||||
|
||||
from rich.progress import Progress
|
||||
from rich.progress import MofNCompleteColumn, Progress, TimeElapsedColumn
|
||||
|
||||
from reflex import constants
|
||||
from reflex.utils import path_ops, prerequisites
|
||||
from reflex.utils import console, path_ops, prerequisites
|
||||
from reflex.utils.processes import new_process
|
||||
|
||||
|
||||
@ -109,36 +109,54 @@ def export_app(
|
||||
generate_sitemap(deploy_url)
|
||||
|
||||
# Create a progress object
|
||||
progress = Progress()
|
||||
progress = Progress(
|
||||
*Progress.get_default_columns()[:-1],
|
||||
MofNCompleteColumn(),
|
||||
TimeElapsedColumn(),
|
||||
)
|
||||
|
||||
checkpoints = [
|
||||
"Linting and checking ",
|
||||
"Compiled successfully",
|
||||
"Route (pages)",
|
||||
"Collecting page data",
|
||||
"automatically rendered as static HTML",
|
||||
'Copying "static build" directory',
|
||||
'Copying "public" directory',
|
||||
"Finalizing page optimization",
|
||||
"Export successful",
|
||||
]
|
||||
|
||||
# Add a single task to the progress object
|
||||
task = progress.add_task("Building app... ", total=500)
|
||||
task = progress.add_task("Creating Production Build: ", total=len(checkpoints))
|
||||
|
||||
# Start the subprocess with the progress bar.
|
||||
with progress, new_process(
|
||||
[prerequisites.get_package_manager(), "run", "export"],
|
||||
cwd=constants.WEB_DIR,
|
||||
) as export_process:
|
||||
assert export_process.stdout is not None, "No stdout for export process."
|
||||
for line in export_process.stdout:
|
||||
# Print the line in debug mode.
|
||||
if loglevel == constants.LogLevel.DEBUG:
|
||||
print(line, end="")
|
||||
try:
|
||||
with progress, new_process(
|
||||
[prerequisites.get_package_manager(), "run", "export"],
|
||||
cwd=constants.WEB_DIR,
|
||||
) as export_process:
|
||||
assert export_process.stdout is not None, "No stdout for export process."
|
||||
for line in export_process.stdout:
|
||||
if loglevel == constants.LogLevel.DEBUG:
|
||||
print(line, end="")
|
||||
|
||||
# Check for special strings and update the progress bar.
|
||||
if "Linting and checking " in line:
|
||||
progress.update(task, advance=100)
|
||||
elif "Compiled successfully" in line:
|
||||
progress.update(task, advance=100)
|
||||
elif "Route (pages)" in line:
|
||||
progress.update(task, advance=100)
|
||||
elif "automatically rendered as static HTML" in line:
|
||||
progress.update(task, advance=100)
|
||||
elif "Export successful" in line:
|
||||
progress.update(task, completed=500)
|
||||
break # Exit the loop if the completion message is found
|
||||
# Check for special strings and update the progress bar.
|
||||
for special_string in checkpoints:
|
||||
if special_string in line:
|
||||
if special_string == "Export successful":
|
||||
progress.update(task, completed=len(checkpoints))
|
||||
break # Exit the loop if the completion message is found
|
||||
else:
|
||||
progress.update(task, advance=1)
|
||||
break
|
||||
|
||||
print("Export process completed.")
|
||||
except Exception as e:
|
||||
console.print(f"[red]Export process errored: {e}")
|
||||
console.print(
|
||||
"[red]Run in with [bold]--loglevel debug[/bold] to see the full error."
|
||||
)
|
||||
os._exit(1)
|
||||
|
||||
# Zip up the app.
|
||||
if zip:
|
||||
|
Loading…
Reference in New Issue
Block a user