Skip to content

Instantly share code, notes, and snippets.

@YuheiNakasaka
Created June 1, 2021 04:46
Show Gist options
  • Save YuheiNakasaka/64d61507c525dcdf3392efd115174adc to your computer and use it in GitHub Desktop.
Save YuheiNakasaka/64d61507c525dcdf3392efd115174adc to your computer and use it in GitHub Desktop.
This script cleans flutter projects by deleting caches and build outputs.
import os
import subprocess
import sys
# This script cleans flutter projects by deleting caches and build outputs.
# Example:
# $ python flutter_clean.py /Users/razokulover/src/github.com/YuheiNakasaka
def rm_ios_files(abs_path):
if os.path.exists(abs_path + "/ios/Flutter/Flutter.framework"):
subprocess.run(["cd " + abs_path + " && " +
"rm -fr " + abs_path + "/ios/Flutter/Flutter.framework"], shell=True)
if os.path.exists(abs_path + "/ios/Flutter/Flutter.podspec"):
subprocess.run(["cd " + abs_path + " && " +
"rm -fr " + abs_path + "/ios/Flutter/Flutter.podspec"], shell=True)
if os.path.exists(abs_path + "/ios/Flutter/.last_build_id"):
subprocess.run(["cd " + abs_path + " && " +
"rm -fr " + abs_path + "/ios/Flutter/.last_build_id"], shell=True)
if os.path.exists(abs_path + "/ios/.symlinks"):
subprocess.run(["cd " + abs_path + " && " +
"rm -fr " + abs_path + "/ios/.symlinks"], shell=True)
if os.path.exists(abs_path + "/ios/Pods"):
subprocess.run(["cd " + abs_path + " && " +
"rm -fr " + abs_path + "/ios/Pods"], shell=True)
args = sys.argv
if len(args) == 2:
target_dir = args[1]
dirs = os.listdir(target_dir)
for dir in dirs:
abs_path = target_dir + "/" + dir
if os.path.isdir(abs_path) and os.path.exists(abs_path + "/pubspec.yaml"):
print(abs_path)
subprocess.run(["cd " + abs_path + " && " +
"flutter " + "clean"], shell=True)
rm_ios_files(abs_path)
if os.path.exists(abs_path + "/example"):
subprocess.run(["cd " + abs_path + "/example" + " && " +
"flutter " + "clean"], shell=True)
rm_ios_files(abs_path + "/example")
else:
print("python flutter_clean.py <absoluete path>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment