#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Использование: build-runner.sh [--path ПАПКА] [--target auto|make|npm|python] [--apply] Без --apply показывается только команда сборки. EOF } path="." target="auto" apply=0 while [[ $# -gt 0 ]]; do case "$1" in --path) path="${2:-}"; shift 2 ;; --target) target="${2:-}"; shift 2 ;; --apply) apply=1; shift ;; -h|--help) usage; exit 0 ;; *) echo "Неизвестный аргумент: $1" >&2; usage >&2; exit 2 ;; esac done die() { echo "$1" >&2; exit 2; } [[ -d "$path" ]] || die "Папка не найдена: $path" detected="" if [[ -f "$path/Makefile" || -f "$path/makefile" || -f "$path/GNUmakefile" ]]; then detected="make" elif [[ -f "$path/package.json" ]] && grep -Eq '"build"[[:space:]]*:' "$path/package.json"; then detected="npm" elif [[ -f "$path/pyproject.toml" || -f "$path/setup.py" ]]; then detected="python" fi [[ -n "$detected" ]] || die "Не найден Makefile, npm-скрипт build или Python-пакет." [[ "$target" == "auto" ]] && target="$detected" [[ "$target" == "$detected" ]] || die "Цель $target не соответствует найденному проекту ($detected)." case "$target" in make) command -v make >/dev/null 2>&1 || die "Не найден make." echo "Команда: make -C $path" if [[ "$apply" -eq 1 ]]; then make -C "$path" fi ;; npm) command -v npm >/dev/null 2>&1 || die "Не найден npm." echo "Команда: npm --prefix $path run build" if [[ "$apply" -eq 1 ]]; then npm --prefix "$path" run build fi ;; python) command -v python3 >/dev/null 2>&1 || die "Не найден python3." python3 -c 'import build' >/dev/null 2>&1 || die "Установите пакет build: python3 -m pip install build" echo "Команда: python3 -m build $path" if [[ "$apply" -eq 1 ]]; then python3 -m build "$path" fi ;; *) die "Неизвестная цель: $target" ;; esac if [[ "$apply" -eq 0 ]]; then echo "Это предпросмотр. Для запуска добавьте --apply." fi