import AppKit import Ch57Kit import SwiftUI @main struct Ch57Demo { @MainActor static func main() { print("[57.1] 设备数 = \(DeviceMatrix.required.count)") print("[57.2] 可用设备 = \(DeviceMatrix.available.count)") print("[57.3] destinations 数 = \(DeviceMatrix.destinations.count)") let command = TestCommand( project: "App.xcodeproj", scheme: "App", destinations: DeviceMatrix.destinations, resultBundle: "build/App.xcresult" ) print("[57.4] 命令有效 = \(command.isValid)") print("[57.5] 参数数 = \(command.arguments.count)") print("[57.6] 末项 = \(command.arguments.last ?? "nil")") let gates = [ QualityGate(name: "单元测试", passed: true, detail: "120 通过"), QualityGate(name: "UI 测试", passed: true, detail: "12 通过"), QualityGate(name: "体积", passed: true, detail: "安装 86MB"), QualityGate(name: "无障碍", passed: false, detail: "2 个标签缺失"), ] let summary = GateRunner.summarize(gates) print("[57.7] 通过 = \(summary.passed),失败 = \(summary.failed)") print("[57.8] 全部通过 = \(GateRunner.allPassed(gates))") let size = SizeReport(downloadMB: 42, installMB: 86) print("[57.9] 体积达标 = \(size.withinBudget)") print("[57.10] 预算占比 = \(String(format: "%.2f", size.ratio))") print("[57.11] 质量板渲染 = \(sizeOf(QualityBoard()))") print("[57.12] MemoryLayout = \(MemoryLayout.size) 字节") if let directory = ProcessInfo.processInfo.environment["SHOTS_DIR"] { write(QualityBoard(), name: "ios-quality-board.png", directory: directory) } } @MainActor private static func sizeOf(_ view: some View) -> String { guard let image = ImageRenderer(content: view).cgImage else { return "nil" } return "\(image.width)x\(image.height)" } @MainActor private static func write(_ view: some View, name: String, directory: String) { let renderer = ImageRenderer(content: view) renderer.scale = 2 guard let image = renderer.cgImage, let data = NSBitmapImageRep(cgImage: image).representation(using: .png, properties: [:]) else { print("[57.13] 截图失败:\(name)") return } let url = URL(fileURLWithPath: directory).appendingPathComponent(name) do { try FileManager.default.createDirectory( at: url.deletingLastPathComponent(), withIntermediateDirectories: true ) try data.write(to: url) print("[57.13] 截图 = \(name) \(image.width)x\(image.height)") } catch { print("[57.13] 截图失败:\(error)") } } }