flutter运行ios时总得执行三个命令,中间还得等待,有没有脚本自动执行
## ios 执行命令
- flutter clean
- flutter pub get
- cd ios
- pod install
有,项目根目录创建shell 文件夹,新建setup.sh
setup.sh里面放如下代码
#!/bin/bash# ios 一键三连
set -e# Save current directory
current_dir=$(pwd)# Clean the Flutter project
echo "Cleaning Flutter project..."
flutter clean# Get all the dependencies
echo "Getting dependencies..."
flutter pub get# Navigate to the iOS directory which is assumed to be at the parent directory of where the script is located
echo "Navigating to the iOS directory..."
cd ..if [ -d "ios" ]; thencd ios# Install CocoaPods dependenciesecho "Installing CocoaPods dependencies..."pod install# Go back to the original directorycd "$current_dir"echo "Setup completed successfully."
elseecho "Error: 'ios' directory does not exist."
fi
运行命令,会看到自动执行一键三连
cd shell
执行 ./setup.sh
还可以扩展比如总是要生成代码用 flutter pub run build_runner build
可以加到脚本,新建build.sh放如下代码
#!/bin/bashecho "开始生成代码"
flutter pub run build_runner build
#flutter pub run build_runner build --delete-conflicting-outputs
运行
cd shell
执行 ./build.sh