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 pathlib import Path
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
from rich.progress import Progress
|
from rich.progress import MofNCompleteColumn, Progress, TimeElapsedColumn
|
||||||
|
|
||||||
from reflex import constants
|
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
|
from reflex.utils.processes import new_process
|
||||||
|
|
||||||
|
|
||||||
@ -109,36 +109,54 @@ def export_app(
|
|||||||
generate_sitemap(deploy_url)
|
generate_sitemap(deploy_url)
|
||||||
|
|
||||||
# Create a progress object
|
# 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
|
# 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.
|
# Start the subprocess with the progress bar.
|
||||||
with progress, new_process(
|
try:
|
||||||
[prerequisites.get_package_manager(), "run", "export"],
|
with progress, new_process(
|
||||||
cwd=constants.WEB_DIR,
|
[prerequisites.get_package_manager(), "run", "export"],
|
||||||
) as export_process:
|
cwd=constants.WEB_DIR,
|
||||||
assert export_process.stdout is not None, "No stdout for export process."
|
) as export_process:
|
||||||
for line in export_process.stdout:
|
assert export_process.stdout is not None, "No stdout for export process."
|
||||||
# Print the line in debug mode.
|
for line in export_process.stdout:
|
||||||
if loglevel == constants.LogLevel.DEBUG:
|
if loglevel == constants.LogLevel.DEBUG:
|
||||||
print(line, end="")
|
print(line, end="")
|
||||||
|
|
||||||
# Check for special strings and update the progress bar.
|
# Check for special strings and update the progress bar.
|
||||||
if "Linting and checking " in line:
|
for special_string in checkpoints:
|
||||||
progress.update(task, advance=100)
|
if special_string in line:
|
||||||
elif "Compiled successfully" in line:
|
if special_string == "Export successful":
|
||||||
progress.update(task, advance=100)
|
progress.update(task, completed=len(checkpoints))
|
||||||
elif "Route (pages)" in line:
|
break # Exit the loop if the completion message is found
|
||||||
progress.update(task, advance=100)
|
else:
|
||||||
elif "automatically rendered as static HTML" in line:
|
progress.update(task, advance=1)
|
||||||
progress.update(task, advance=100)
|
break
|
||||||
elif "Export successful" in line:
|
|
||||||
progress.update(task, completed=500)
|
|
||||||
break # Exit the loop if the completion message is found
|
|
||||||
|
|
||||||
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.
|
# Zip up the app.
|
||||||
if zip:
|
if zip:
|
||||||
|
Loading…
Reference in New Issue
Block a user