def rename_app(new_app_name: str, loglevel: constants.LogLevel):
    """Rename the app directory.

    Args:
        new_app_name: The new name for the app.
        loglevel: The log level to use.

    Raises:
        Exit: If the command is not ran in the root dir or the app module cannot be imported.
    """
    # Set the log level.
    console.set_log_level(loglevel)

    if not constants.Config.FILE.exists():
        console.error(
            "No rxconfig.py found. Make sure you are in the root directory of your app."
        )
        raise click.exceptions.Exit(1)

    sys.path.insert(0, str(Path.cwd()))

    config = get_config()
    module_path = importlib.util.find_spec(config.module)
    if module_path is None:
        console.error(f"Could not find module {config.module}.")
        raise click.exceptions.Exit(1)

    if not module_path.origin:
        console.error(f"Could not find origin for module {config.module}.")
        raise click.exceptions.Exit(1)
    console.info(f"Renaming app directory to {new_app_name}.")
    process_directory(
        Path.cwd(),
        config.app_name,
        new_app_name,
        exclude_dirs=[constants.Dirs.WEB, constants.Dirs.APP_ASSETS],
    )

    rename_path_up_tree(Path(module_path.origin), config.app_name, new_app_name)

    console.success(f"App directory renamed to [bold]{new_app_name}[/bold].")
Rename the app directory.

    Args:
        new_app_name: The new name for the app.
        loglevel: The log level to use.

    Raises:
        Exit: If the command is not ran in the root dir or the app module cannot be imported.
    
reflex/utils/prerequisites.py