Created
February 17, 2022 15:50
-
-
Save fabriciovergara/4b3931d346db4f0be401df521cc00de6 to your computer and use it in GitHub Desktop.
Flutter: Sync pubspec file in melos project with flavors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import glob | |
import ruamel.yaml | |
yaml = ruamel.yaml.YAML() | |
def main(): | |
# python3 pubspec_base_sync.py ../pubspec_base_android.yaml ../pubspec_base_android_huawei.yaml | |
base_path = '../pubspec_base.yaml' | |
modifiers_path = sys.argv[1:] | |
with open(base_path, 'r') as base_file: | |
base = yaml.load(base_file) | |
for modifier_path in modifiers_path: | |
with open(modifier_path, 'r') as modifier_file: | |
modifier_content = yaml.load(modifier_file) | |
base = sync_content(modifier_content, base) | |
for path in glob.glob('../packages/**/pubspec.yaml'): | |
with open(path, 'r') as read_file: | |
content = yaml.load(read_file) | |
content = sync_content(base, content) | |
with open(path, 'w') as write_file: | |
yaml.dump(content, write_file) | |
break | |
def sync_content(base, content): | |
for key_base, value_base in base.items(): | |
if content is not None and key_base in content: | |
if type(value_base) is str or type(value_base) is int: | |
content[key_base] = value_base | |
elif value_base is not None: | |
content[key_base] = sync_content(value_base, content[key_base]) | |
return content | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment