Files
superport_v2/tool/sync_stock_docs.sh

99 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# 이 스크립트는 결재 문서를 백엔드(superport_api_v2)와 동기화하거나 차이를 점검한다.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
BACKEND_ROOT="$(cd "$PROJECT_ROOT/.." && pwd)/superport_api_v2"
FILES=(
"stock_approval_system_api_v4.md"
"stock_approval_system_spec_v4.md"
)
show_usage() {
cat <<'EOF'
사용법: tool/sync_stock_docs.sh [--check]
--check 백엔드 문서와 현재 문서의 차이를 검사한다.
차이가 있으면 diff를 출력하고 종료 코드 1을 반환한다.
인자가 없으면 백엔드 문서를 복사하여 현재 리포지터리 doc/ 경로로 동기화한다.
EOF
}
require_files() {
local missing=0
for file in "${FILES[@]}"; do
local source_path="$BACKEND_ROOT/$file"
if [[ ! -f "$source_path" ]]; then
echo "오류: 백엔드 문서를 찾을 수 없습니다 -> $source_path" >&2
missing=1
fi
done
if [[ $missing -ne 0 ]]; then
exit 1
fi
}
sync_files() {
require_files
for file in "${FILES[@]}"; do
local source_path="$BACKEND_ROOT/$file"
local target_path="$PROJECT_ROOT/doc/$file"
mkdir -p "$(dirname "$target_path")"
cp "$source_path" "$target_path"
echo "동기화 완료: $file"
done
}
check_diff() {
require_files
local diff_found=0
for file in "${FILES[@]}"; do
local source_path="$BACKEND_ROOT/$file"
local target_path="$PROJECT_ROOT/doc/$file"
if ! diff -u "$target_path" "$source_path" >/dev/null; then
echo "차이 발견: $file"
diff -u "$target_path" "$source_path" || true
diff_found=1
fi
done
if [[ $diff_found -ne 0 ]]; then
exit 1
fi
echo "모든 문서가 일치합니다."
}
main() {
if [[ $# -gt 1 ]]; then
show_usage
exit 1
fi
if [[ $# -eq 1 ]]; then
case "$1" in
--check)
check_diff
return
;;
-*)
show_usage
exit 1
;;
*)
show_usage
exit 1
;;
esac
fi
sync_files
}
main "$@"