swagger_generator_flutter/example/as_dev_dependency/generate_api.bat

71 lines
2.0 KiB
Batchfile
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.

@echo off
REM Swagger API 代码生成脚本Windows
REM 用于示例项目的 API 代码生成
setlocal enabledelayedexpansion
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo 🚀 Swagger API 代码生成器
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo.
REM 步骤 1: 生成 API 代码
echo 📝 步骤 1/4: 生成 API 代码...
dart run swagger_generator_flutter generate --all
if !errorlevel! neq 0 (
echo ❌ API 代码生成失败!
exit /b 1
)
echo ✅ API 代码生成成功
echo.
REM 步骤 2: 运行 build_runner
echo 🔧 步骤 2/4: 运行 build_runner...
dart run build_runner build --delete-conflicting-outputs
if !errorlevel! neq 0 (
echo ⚠️ build_runner 执行失败(如果是首次运行,可能需要先修复基础类型)
echo 请检查 lib/common/api_response.dart 和 paged_response.dart
) else (
echo ✅ build_runner 执行成功
)
echo.
REM 步骤 3: 格式化代码
echo 📐 步骤 3/4: 格式化代码...
dart format lib/generated
echo ✅ 代码格式化完成
echo.
REM 步骤 4: 分析代码
echo 🔍 步骤 4/4: 分析代码...
dart analyze lib/generated --fatal-infos
if !errorlevel! neq 0 (
echo ⚠️ 代码分析发现问题,请检查
) else (
echo ✅ 代码分析通过
)
echo.
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo ✨ 代码生成完成!
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo.
echo 📂 生成的文件位置:
echo lib/generated/api/
echo lib/generated/api_models/
echo.
echo 📚 下一步:
echo 1. 查看生成的代码lib/generated/
echo 2. 在 main.dart 中取消注释 import 语句
echo 3. 运行应用flutter run
echo.
pause