Files
platforms/scripts/build-frontend.sh
2026-07-31 15:21:31 +08:00

62 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
require_command() {
local command_name="$1"
if ! command -v "${command_name}" >/dev/null 2>&1; then
echo "缺少命令:${command_name}" >&2
exit 1
fi
}
build_project() {
local project_name="$1"
local project_dir="$2"
local package_manager="$3"
if [[ ! -f "${project_dir}/package.json" ]]; then
echo "未找到 ${project_name} 的 package.json${project_dir}" >&2
exit 1
fi
if [[ ! -d "${project_dir}/node_modules" ]]; then
echo "${project_name} 依赖尚未安装,请先在 ${project_dir} 安装依赖。" >&2
exit 1
fi
echo
echo "开始构建:${project_name}"
(
cd "${project_dir}"
case "${package_manager}" in
pnpm)
pnpm build
;;
npm)
npm run build
;;
*)
echo "不支持的包管理器:${package_manager}" >&2
exit 1
;;
esac
)
echo "构建完成:${project_name}"
}
require_command pnpm
require_command npm
build_project "平台总后台" "${PROJECT_ROOT}/frontend/platform_admin" pnpm
build_project "气站管理后台" "${PROJECT_ROOT}/frontend/gas_admin" pnpm
build_project "配送点管理后台" "${PROJECT_ROOT}/frontend/delivery_admin" pnpm
build_project "和气门户首页" "${PROJECT_ROOT}/frontend/site" npm
echo
echo "四个前端项目全部构建完成。"