Files
cmbuyer/init.ps1
T

85 lines
3.3 KiB
PowerShell
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 pwsh
# cmbuyer 标准启动与验证入口(Windows PowerShell 版),与 init.sh 等价,二选一:
# - Windows 原生 PowerShell:./init.ps1
# - WSL / Git Bash:./init.sh
#
# 本项目是双产品结构:admin/(采购服务,Go)+ client/(采购工具,Python)。脚本按
# admin/go.mod 与 client/requirements.txt 两个初始化哨兵分别处理;未初始化的一端会跳过并
# 提示对应任务,不会把空目录误判为可运行项目,也不会静默通过。
#
# T-001 / T-002 / T-003 落地后,把下面的命令补全,并同步:
# docs/03-tech-stack.md、docs/00-ai-start-here.md、docs/current-state.md
$ErrorActionPreference = "Stop"
Set-Location -Path $PSScriptRoot
# Go 工具链固定用本机版本,避免自动下载
$env:GOTOOLCHAIN = "local"
$AdminDir = Join-Path $PSScriptRoot "admin"
$ClientDir = Join-Path $PSScriptRoot "client"
$Pending = @()
Write-Host "==> 当前目录: $($PWD.Path)"
# ------------------------------------------------------- 采购服务(admin/,Go)
if (Test-Path (Join-Path $AdminDir "go.mod") -PathType Leaf) {
Write-Host "==> 采购服务:admin/ 同步依赖"
Push-Location $AdminDir
try {
go mod download
Write-Host "==> 采购服务:admin/ 静态检查"
go vet ./...
Write-Host "==> 采购服务:admin/ 测试"
go test ./...
} finally {
Pop-Location
}
} else {
Write-Host "==> 采购服务:admin/go.mod 不存在,跳过。先做 T-001(初始化 admin/ Go 骨架)。"
$Pending += "T-001 初始化采购服务 admin/ Go 骨架"
}
# ---------------------------------------------------- 采购工具(client/,Python)
if (Test-Path (Join-Path $ClientDir "requirements.txt") -PathType Leaf) {
Write-Host "==> 采购工具:client/ 同步依赖"
Push-Location $ClientDir
try {
if (-not (Test-Path ".venv")) {
python -m venv .venv
}
& ".venv\Scripts\python.exe" -m pip install -q -r requirements.txt
Write-Host "==> 采购工具:client/ 语法检查"
& ".venv\Scripts\python.exe" -m compileall -q src tests
Write-Host "==> 采购工具:client/ 测试"
& ".venv\Scripts\python.exe" -m unittest discover -s tests -t .
} finally {
Pop-Location
}
} else {
Write-Host "==> 采购工具:client/requirements.txt 不存在,跳过。先做 T-002(初始化 client/ Python 骨架)。"
$Pending += "T-002 初始化采购工具 client/ Python 骨架"
}
# ------------------------------------------------------------------ 文档自检
Write-Host "==> 校验 agent 上下文清单"
python scripts/validate_agent_context.py
# -------------------------------------------------------------------- 汇总
Write-Host ""
if ($Pending.Count -gt 0) {
Write-Host "==> 尚未初始化的部分:"
foreach ($item in $Pending) { Write-Host " - $item" }
Write-Host ""
Write-Host "当前仓库只有文档。按 docs/06-tasks.md 领取上述任务后再运行本脚本。"
exit 3
}
Write-Host "==> 启动命令"
Write-Host " 采购服务:cd admin ; go run ./cmd/server"
Write-Host " 采购工具:cd client ; .venv\Scripts\python.exe src/main.py"
Write-Host ""
Write-Host "基础验证失败时先修基线,不要在坏的起点上继续叠新功能。"
Write-Host "真机连接与设备验收只能由人工完成,agent 不得据此把任务标为 DONE。"