当前位置:   article > 正文

Flutter ios一键三连脚本

Flutter ios一键三连脚本

flutter运行ios时总得执行三个命令,中间还得等待,有没有脚本自动执行

## ios 执行命令
- flutter clean
- flutter pub get
- cd ios
- pod install
  • 1
  • 2
  • 3
  • 4
  • 5

有,项目根目录创建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" ]; then
  cd ios
  
  # Install CocoaPods dependencies
  echo "Installing CocoaPods dependencies..."
  pod install

  # Go back to the original directory
  cd "$current_dir"
  echo "Setup completed successfully."
else
  echo "Error: 'ios' directory does not exist."
fi

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

运行命令,会看到自动执行一键三连

cd shell
执行 ./setup.sh
  • 1
  • 2

还可以扩展比如总是要生成代码用 flutter pub run build_runner build
可以加到脚本,新建build.sh放如下代码

#!/bin/bash

echo "开始生成代码"
flutter pub run build_runner build 
#flutter pub run build_runner build --delete-conflicting-outputs
  • 1
  • 2
  • 3
  • 4
  • 5

运行

cd shell
执行 ./build.sh
  • 1
  • 2
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
  

闽ICP备14008679号