code: def pl_app(
      source_dir: str, script_path: str, name: str, overwrite: bool
  ) -> None:
      source_dir = Path(source_dir).resolve()
      script_path = Path(script_path).resolve()
  
      if not source_dir.is_dir():
          click.echo(
              f"The given source directory does not exist: {source_dir}",
              err=True,
          )
          raise SystemExit(1)
  
      if not script_path.exists():
          click.echo(
              f"The given script path does not exist: {script_path}",
              err=True,
          )
          raise SystemExit(1)
  
      if not script_path.is_file():
          click.echo(
              f"The given script path must be a file, you passed: {script_path}",
              err=True,
          )
          raise SystemExit(1)
  
      if source_dir not in script_path.parents:
          click.echo(
              "The given script path must be a subpath of the source directory. Example:"
              " lightning init pl-app ./code ./code/scripts/train.py",
              err=True,
          )
          raise SystemExit(1)
  
      rel_script_path = script_path.relative_to(source_dir)
      cwd = Path.cwd()
      destination = cwd / name
  
      if destination.exists():
          if not overwrite:
              click.echo(
                  f"There is already an app with the name {name} in the current working directory. Choose a different"
                  f" name with `--name` or force to overwrite the existing folder by passing `--overwrite`.",
                  err=True,
              )
              raise SystemExit(1)
  
          shutil.rmtree(destination)
  
      template_dir = (
          Path(lightning.app.cli.__file__).parent / "pl-app-template"
      )
  
      with Status("[bold green]Copying app files"):
          shutil.copytree(
              template_dir,
              destination,
              ignore=shutil.ignore_patterns("node_modules", "build"),
          )
          if (template_dir / "ui" / "build").exists():
              shutil.copytree(
                  template_dir / "ui" / "build",
                  destination / "ui" / "build",
              )
          else:
              download_frontend(destination / "ui" / "build")
  
      with Status("[bold green]Copying source files"):
          shutil.copytree(
              source_dir,
              destination / "source",
              ignore=shutil.ignore_patterns(name),
          )
          project_file_from_template(
              template_dir,
              destination,
              "app.py",
              script_path=str(rel_script_path),
          )
          project_file_from_template(
              template_dir, destination, "setup.py", app_name=name
          )
  
      with Status("[bold green]Installing"):
          subprocess.call(
              ["pip", "install", "--quiet", "-e", str(destination)]
          )
          # TODO: download the ui files
  
      print_pretty_report(
          destination,
          ignore_patterns=_REPORT_IGNORE_PATTERNS,
          help_texts=_REPORT_HELP_TEXTS,
      )
  
imports: import pathlib
  import re
  import shutil
  import subprocess
  import sys
  import tarfile
  import urllib.request
  from pathlib import Path
  from tempfile import TemporaryDirectory
  from typing import Any, Dict, List, Optional
  import click
  from jinja2 import Environment, FileSystemLoader
  from rich import print
  from rich.panel import Panel
  from rich.status import Status
  from rich.text import Text
  from rich.tree import Tree
  import lightning.app
label_desc: Use image node_id 1 for calling a global function with example usage: pl_app(source_dir, script_path, name, overwrite) without return types