dramaling-app/tools/phase.sh

270 lines
8.0 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.

#!/bin/bash
# 階段管理工具
# 使用方法: ./drama phase [命令]
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PROJECTS_FILE="$PROJECT_DIR/PROJECTS.md"
PROJECTS_DATA_DIR="$PROJECT_DIR/projects"
# 顏色定義
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
RED='\033[0;31m'
NC='\033[0m'
# 類型圖標函數 (Bash 3.2 兼容)
get_type_icon() {
case "$1" in
"FE") echo "🎨" ;;
"BE") echo "⚙️" ;;
"AI") echo "🤖" ;;
"MB") echo "📱" ;;
"DOC") echo "📚" ;;
"ENV") echo "🔧" ;;
"TEST") echo "🧪" ;;
*) echo "🔧" ;;
esac
}
# 狀態圖標函數
get_status_icon() {
case "$1" in
"pending") echo "⏳" ;;
"in-progress") echo "🔄" ;;
"completed") echo "✅" ;;
"blocked") echo "❌" ;;
"paused") echo "⏸️" ;;
*) echo "⏳" ;;
esac
}
# 確保必要文件和目錄存在
init_phase_structure() {
if [[ ! -f "$PROJECTS_FILE" ]]; then
echo -e "${RED}❌ PROJECTS.md 不存在${NC}"
exit 1
fi
if [[ ! -d "$PROJECTS_DATA_DIR" ]]; then
mkdir -p "$PROJECTS_DATA_DIR"
fi
}
# 列出所有階段
list_phases() {
local project_name="$1"
if [[ -z "$project_name" ]]; then
echo -e "${BLUE}📋 所有專案的階段列表${NC}"
echo "=================================="
# 從PROJECTS.md中提取階段信息
grep -E "^#### 階段[0-9]+:" "$PROJECTS_FILE" | while read -r line; do
phase_info=$(echo "$line" | sed 's/^#### //')
echo -e " ${GREEN}📊 $phase_info${NC}"
done
else
echo -e "${BLUE}📋 專案 '$project_name' 的階段列表${NC}"
echo "=================================="
local project_file="$PROJECTS_DATA_DIR/${project_name}.md"
if [[ -f "$project_file" ]]; then
grep -E "^### 階段[0-9]+:" "$project_file" | while read -r line; do
phase_info=$(echo "$line" | sed 's/^### //')
echo -e " ${GREEN}📊 $phase_info${NC}"
done
else
echo -e "${RED}❌ 專案 '$project_name' 不存在${NC}"
fi
fi
}
# 新增階段
add_phase() {
local project_name="$1"
local phase_name="$2"
if [[ -z "$project_name" || -z "$phase_name" ]]; then
echo -e "${RED}❌ 請提供專案名稱和階段名稱${NC}"
echo "使用方法: ./dl phase add \"專案名稱\" \"階段名稱\""
return 1
fi
local project_file="$PROJECTS_DATA_DIR/${project_name}.md"
if [[ ! -f "$project_file" ]]; then
echo -e "${RED}❌ 專案 '$project_name' 不存在${NC}"
echo "使用 ./dl project init \"$project_name\" 先建立專案"
return 1
fi
echo -e "${BLUE} 為專案 '$project_name' 新增階段: $phase_name${NC}"
# 計算新階段編號
local phase_count=$(grep -c "^### 階段[0-9]*:" "$project_file")
local new_phase_num=$((phase_count + 1))
# 在項目文件中新增階段
cat >> "$project_file" << EOF
### 階段$new_phase_num: $phase_name ⏳
- ⏳ \`ENV\` 請使用 ./drama phase items 新增執行項目...
EOF
echo -e "${GREEN}✅ 階段 '$phase_name' 新增完成${NC}"
echo " 💡 使用 ./dl phase items \"$project_name\" \"$phase_name\" 管理執行項目"
}
# 管理階段執行項目
manage_phase_items() {
local project_name="$1"
local phase_name="$2"
local item_type="$3"
local item_desc="$4"
if [[ -z "$project_name" || -z "$phase_name" ]]; then
echo -e "${RED}❌ 請提供專案名稱和階段名稱${NC}"
echo "使用方法: ./dl phase items \"專案名稱\" \"階段名稱\" [類型] [描述]"
return 1
fi
local project_file="$PROJECTS_DATA_DIR/${project_name}.md"
if [[ ! -f "$project_file" ]]; then
echo -e "${RED}❌ 專案 '$project_name' 不存在${NC}"
return 1
fi
if [[ -n "$item_type" && -n "$item_desc" ]]; then
# 新增執行項目
local type_icon=$(get_type_icon "$item_type")
echo -e "${BLUE} 新增執行項目到階段 '$phase_name'${NC}"
echo " ${type_icon} [$item_type] $item_desc"
# TODO: 實作新增項目到特定階段的邏輯
echo -e "${YELLOW}⚠️ 此功能開發中...${NC}"
else
# 顯示階段的執行項目
echo -e "${BLUE}📋 階段 '$phase_name' 的執行項目${NC}"
echo "=================================="
# 尋找並顯示階段的執行項目
local in_phase=false
while IFS= read -r line; do
if [[ "$line" =~ ^###.*$phase_name ]]; then
in_phase=true
continue
elif [[ "$line" =~ ^###.*階段[0-9]+: ]] && [[ "$in_phase" == true ]]; then
break
elif [[ "$in_phase" == true && "$line" =~ ^-.*\`.*\` ]]; then
echo " $line"
fi
done < "$project_file"
fi
}
# 開始執行階段
start_phase() {
local project_name="$1"
local phase_name="$2"
if [[ -z "$project_name" || -z "$phase_name" ]]; then
echo -e "${RED}❌ 請提供專案名稱和階段名稱${NC}"
echo "使用方法: ./dl phase start \"專案名稱\" \"階段名稱\""
return 1
fi
echo -e "${GREEN}🚀 開始執行階段: $phase_name${NC}"
echo -e "${BLUE}專案: $project_name${NC}"
echo ""
echo -e "${YELLOW}⚠️ 此功能開發中,將來會更新項目狀態...${NC}"
}
# 完成階段
complete_phase() {
local project_name="$1"
local phase_name="$2"
if [[ -z "$project_name" || -z "$phase_name" ]]; then
echo -e "${RED}❌ 請提供專案名稱和階段名稱${NC}"
echo "使用方法: ./dl phase complete \"專案名稱\" \"階段名稱\""
return 1
fi
echo -e "${GREEN}✅ 完成階段: $phase_name${NC}"
echo -e "${BLUE}專案: $project_name${NC}"
echo ""
echo -e "${YELLOW}⚠️ 此功能開發中,將來會更新項目狀態和產生報告...${NC}"
}
# 顯示階段狀態
show_phase_status() {
echo -e "${BLUE}📊 階段執行狀態總覽${NC}"
echo "=================================="
echo ""
echo -e "${GREEN}當前進行中的階段:${NC}"
echo " 🔄 環境配置 (Drama Ling 手機APP開發)"
echo ""
echo -e "${PURPLE}階段統計:${NC}"
echo " 📊 總階段數: 4"
echo " 🔄 進行中: 1"
echo " ⏳ 待執行: 3"
echo " ✅ 已完成: 0"
}
# 顯示幫助
show_help() {
echo -e "${BLUE}🚀 階段管理工具使用指南${NC}"
echo "=================================="
echo ""
echo -e "${PURPLE}階段管理命令:${NC}"
echo " list [專案名] - 列出階段"
echo " add \"專案\" \"階段名\" - 新增階段"
echo " items \"專案\" \"階段\" [類型] [描述] - 管理執行項目"
echo " start \"專案\" \"階段\" - 開始執行階段"
echo " complete \"專案\" \"階段\" - 完成階段"
echo " status - 查看階段狀態"
echo ""
echo -e "${PURPLE}範例:${NC}"
echo " ./dl phase add \"我的專案\" \"開發階段\""
echo " ./dl phase items \"我的專案\" \"開發階段\" FE \"建立登入頁面\""
echo " ./dl phase start \"我的專案\" \"開發階段\""
echo ""
echo -e "${BLUE}提示:${NC} 使用 ./dl project types 查看所有項目類型"
}
# 主邏輯
init_phase_structure
case "$1" in
"list")
list_phases "$2"
;;
"add")
add_phase "$2" "$3"
;;
"items")
manage_phase_items "$2" "$3" "$4" "$5"
;;
"start")
start_phase "$2" "$3"
;;
"complete")
complete_phase "$2" "$3"
;;
"status")
show_phase_status
;;
"help"|"--help"|"-h"|"")
show_help
;;
*)
echo -e "${RED}❌ 未知命令: $1${NC}"
echo ""
show_help
exit 1
;;
esac