set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
isSelfContained := "false"

@_show-dir:
  echo "Current Working Directory:"
  pwd
  echo

# 清空构建文件
clean: 
  rm -rf "server/bin"
  rm -rf "server/obj"
  rm -rf "server.test/bin"
  rm -rf "server.test/obj"
  rm -rf "dist"
  rm -rf "wwwroot"

update:
  npm install
  dotnet restore ./server/server.csproj
  git submodule update --init --remote --recursive

# 生成Restful API到网页客户端
gen-api:
  npm run gen-api

# 构建服务器，包含win与linux平台
[working-directory: "server"]
build-server self-contained=isSelfContained: _show-dir
  dotnet publish --self-contained {{self-contained}} -t:PublishAllRids
  npm run build
  rsync -avz --delete ../wwwroot/ ./bin/Release/net9.0/linux-x64/publish/wwwroot/
  rsync -avz --delete ../wwwroot/ ./bin/Release/net9.0/win-x64/publish/wwwroot/

run: run-server

run-server: (build-server "true")
  ./server/bin/Release/net9.0/linux-x64/publish/server

run-web:
  npm run build
  npm run preview

dev: dev-server

# 测试服务器
dev-server: _show-dir
  dotnet run --watch --project ./server/server.csproj

# 运行网页客户端
dev-web: 
  npm run dev
  
# 运行测试用例测试服务器
[working-directory: "server.test"]
test-server: _show-dir
  dotnet test --logger "console;verbosity=detailed"
