由于我不耐烦了,所以我想为此编写一个小的 shell 脚本。我不知道是否有更简单的方法,但这对我有用。
我的项目具有以下文件夹结构:
project
pubspec.yaml
packages/
package1/
pubspec.yaml
package2/
pubspec.yaml
package3/
pubspec.yaml
我refresh.bash
在项目文件夹中创建了一个文件。这是它的样子:
# open project directory or exit if failed
cd PROJECT_PATH || exit
# check if project contains pubspec.yaml file
if [ -f "pubspec.yaml" ]; then
# check if packages folder exists
if [ -d "packages" ]; then
# open packages folder
cd "packages" || exit
# run for all subdirectories of packages folder
for d in */; do
# open subdirectory
cd "$d" || exit
# check if subdirectory contains pubspec.yaml file
if [ -f "pubspec.yaml" ]; then
# run pub get for subdirectory (package)
flutter pub get
fi
# exit subdirectory
cd ..
done
# exit packages directory
cd ..
fi
# run pub get for project directory
flutter pub get
else
echo "pubspec.yaml not found"
fi
替换PROJECT_PATH
为项目的路径。
为了能够运行这个脚本,我必须让它可执行。这可以通过以下命令完成:
chmod +x refresh.bash
在此之后,我运行脚本(在 bash 终端中):
./refresh.bash
注意:我不知道 shell 脚本是如何工作的,我从Shell Script Cheatsheet中得到了一些提示。所以,如果有任何问题,或者如果它可以更小,请建议我。这是我使用 shell 脚本的第一天。