label = "OnCall.Plugin"

is_ci=config.tilt_subcommand == "ci"
grafana_plugin_dir="../../grafana-plugin"

# On CI dependencies are installed separately so we just build prod bundle to be consumed by Grafana dev server
if is_ci:
    local_resource(
        "build-ui",
        labels=[label],
        dir=grafana_plugin_dir,
        cmd="pnpm build",
        allow_parallel=True,
    )

# Locally we install dependencies and we run watch mode
if not is_ci:
    local_resource(
        "build-ui",
        labels=[label],
        dir=grafana_plugin_dir,
        cmd="pnpm install",
        serve_dir=grafana_plugin_dir,
        serve_cmd="pnpm dev",
        allow_parallel=True,
    )

local_resource(
    'build-oncall-plugin-backend',
    labels=[label],
    dir="../../grafana-plugin",
    cmd="mage buildAll",
    deps=['../../grafana-plugin/pkg/plugin']
)

local_resource(
    'restart-oncall-plugin-backend',
    labels=[label],
    dir="../../dev/scripts",
    cmd="chmod +x ./restart_backend_plugin.sh && ./restart_backend_plugin.sh",
    resource_deps=["grafana", "build-oncall-plugin-backend"],
    deps=['../../grafana-plugin/pkg/plugin']
)