From c34c61993e59d6f0796eb4672758dc92776f2e02 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 10:37:31 +0200 Subject: [PATCH 01/23] Modular prebuild script --- .gitignore | 121 +++++++++++++++++ core/prebuild.sh | 7 + core_ui/prebuild.sh | 6 + data/prebuild.sh | 7 + domain/prebuild.sh | 6 + feature/prebuild.sh | 7 + files/fast_prebuild_script_mac.sh | 57 ++------ ...uild_script.sh => slow_prebuild_script.sh} | 0 functions.sh | 122 ++++++++++++++++++ navigation/prebuild.sh | 7 + prebuild.sh | 6 + 11 files changed, 299 insertions(+), 47 deletions(-) create mode 100644 .gitignore create mode 100755 core/prebuild.sh create mode 100755 core_ui/prebuild.sh create mode 100755 data/prebuild.sh create mode 100755 domain/prebuild.sh create mode 100755 feature/prebuild.sh rename files/{prebuild_script.sh => slow_prebuild_script.sh} (100%) create mode 100755 functions.sh create mode 100755 navigation/prebuild.sh create mode 100755 prebuild.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cfcf1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,121 @@ +# Miscellaneous +*.class +*.lock +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# Visual Studio Code related +.classpath +.project +.settings/ +.vscode/ + +# Flutter repo-specific +/bin/cache/ +/bin/mingit/ +/dev/benchmarks/mega_gallery/ +/dev/bots/.recipe_deps +/dev/bots/android_tools/ +/dev/docs/doc/ +/dev/docs/flutter.docs.zip +/dev/docs/lib/ +/dev/docs/pubspec.yaml +/dev/integration_tests/**/xcuserdata +/dev/integration_tests/**/Pods +/packages/flutter/coverage/ +version + +# packages file containing multi-root paths +.packages.generated + +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +build/ +flutter_*.png +linked_*.ds +unlinked.ds +unlinked_spec.ds +**ios/Flutter/.last_build_id + +# Android related +**/android/**/gradle-wrapper.jar +**/android/.gradle +**/android/captures/ +**/android/gradlew +**/android/gradlew.bat +**/android/local.properties +**/android/**/GeneratedPluginRegistrant.java + +# Keystores +**/android/keystores/release/ +**/ios/Certs/ + +# iOS/XCode related +**/ios/**/*.mode1v3 +**/ios/**/*.mode2v3 +**/ios/**/*.moved-aside +**/ios/**/*.pbxuser +**/ios/**/*.perspectivev3 +**/ios/**/*sync/ +**/ios/**/.sconsign.dblite +**/ios/**/.tags* +**/ios/**/.vagrant/ +**/ios/**/DerivedData/ +**/ios/**/Icon? +**/ios/**/Pods/ +**/ios/**/.symlinks/ +**/ios/**/profile +**/ios/**/xcuserdata +**/ios/.generated/ +**/ios/Flutter/App.framework +**/ios/Flutter/Flutter.framework +**/ios/Flutter/Flutter.podspec +**/ios/Flutter/Generated.xcconfig +**/ios/Flutter/app.flx +**/ios/Flutter/app.zip +**/ios/Flutter/flutter_assets/ +**/ios/Flutter/flutter_export_environment.sh +**/ios/ServiceDefinitions.json +**/ios/Runner/GeneratedPluginRegistrant.* + +# macOS +**/macos/Flutter/GeneratedPluginRegistrant.swift +**/macos/Flutter/Flutter-Debug.xcconfig +**/macos/Flutter/Flutter-Release.xcconfig +**/macos/Flutter/Flutter-Profile.xcconfig + +# Coverage +coverage/ + +# Symbols +app.*.symbols + +# Exceptions to above rules. +!**/ios/**/default.mode1v3 +!**/ios/**/default.mode2v3 +!**/ios/**/default.pbxuser +!**/ios/**/default.perspectivev3 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +!/dev/ci/**/Gemfile.lock + +# Prebuild +**/hash1 +**/hash2 \ No newline at end of file diff --git a/core/prebuild.sh b/core/prebuild.sh new file mode 100755 index 0000000..67ba78a --- /dev/null +++ b/core/prebuild.sh @@ -0,0 +1,7 @@ +#!/bin/zsh + +echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" + +flutter clean +flutter pub get +dart run build_runner build --delete-conflicting-outputs \ No newline at end of file diff --git a/core_ui/prebuild.sh b/core_ui/prebuild.sh new file mode 100755 index 0000000..e68efe7 --- /dev/null +++ b/core_ui/prebuild.sh @@ -0,0 +1,6 @@ +#!/bin/zsh + +echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" + +flutter clean +flutter pub get diff --git a/data/prebuild.sh b/data/prebuild.sh new file mode 100755 index 0000000..67ba78a --- /dev/null +++ b/data/prebuild.sh @@ -0,0 +1,7 @@ +#!/bin/zsh + +echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" + +flutter clean +flutter pub get +dart run build_runner build --delete-conflicting-outputs \ No newline at end of file diff --git a/domain/prebuild.sh b/domain/prebuild.sh new file mode 100755 index 0000000..e68efe7 --- /dev/null +++ b/domain/prebuild.sh @@ -0,0 +1,6 @@ +#!/bin/zsh + +echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" + +flutter clean +flutter pub get diff --git a/feature/prebuild.sh b/feature/prebuild.sh new file mode 100755 index 0000000..67ba78a --- /dev/null +++ b/feature/prebuild.sh @@ -0,0 +1,7 @@ +#!/bin/zsh + +echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" + +flutter clean +flutter pub get +dart run build_runner build --delete-conflicting-outputs \ No newline at end of file diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh index cd1c2cd..dd65a0a 100644 --- a/files/fast_prebuild_script_mac.sh +++ b/files/fast_prebuild_script_mac.sh @@ -1,52 +1,15 @@ -#!/bin/bash -allDirs() { - count=$(find . -name "pubspec.yaml" -exec dirname {} \; | wc -l) - find . -name "pubspec.yaml" -exec dirname {} \; | xargs -n 1 -P "$count" -I {} bash -c ' - ( - cd "{}" || exit - echo -e "\033[1;32mRunning flutter clean and pub get in {}\033[0m" - flutter clean - flutter pub get - ) - ' -} +#!/bin/zsh -echo_styled() { - echo -e "\033[1;$2m$1\033[0m" -} +source functions.sh -flutter clean +run_prebuild_if_needed core +run_prebuild_if_needed core_ui +run_prebuild_if_needed data +run_prebuild_if_needed domain -allDirs +count=$(find ./features -mindepth 1 -maxdepth 1 -type d | wc -l) +find ./features -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c 'source functions.sh; run_prebuild_if_needed "$@"' _ {} -# Generate localization keys -( - cd "core" || exit - echo_styled "Generating localization keys in core" 33 -dart run easy_localization:generate -f keys -o locale_keys.g.dart -O lib/src/localization/generated -S resources/lang -) +run_prebuild_if_needed navigation -# Generate data layer files -( - cd "data" || exit - echo_styled "Generating data layer files in data" 33 - dart run build_runner build --delete-conflicting-outputs -) - -# Generate core_ui layer files -( - cd "core_ui" || exit - echo_styled "Generating core_ui layer files in core_ui" 33 - dart run build_runner build --delete-conflicting-outputs -) - -# Generate feature layer files -( - cd "features" || exit - count=$(find . -mindepth 1 -maxdepth 1 -type d | wc -l) - find . -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c ' - cd "{}" && - echo -e "\033[1;33mRunning build_runner in {}\033[0m" && - dart run build_runner build --delete-conflicting-outputs - ' -) \ No newline at end of file +run_prebuild_if_needed . diff --git a/files/prebuild_script.sh b/files/slow_prebuild_script.sh similarity index 100% rename from files/prebuild_script.sh rename to files/slow_prebuild_script.sh diff --git a/functions.sh b/functions.sh new file mode 100755 index 0000000..03815b0 --- /dev/null +++ b/functions.sh @@ -0,0 +1,122 @@ +readonly HASH_1="hash1" +readonly HASH_2="hash2" + +__calculate_hash() { + local file_path="$1" + sha256sum "$file_path" | awk '{ print $1 }' +} + +__print_usage() { + echo "Usage: __build_file_hashes -d -o " + echo " -d Directory to scan" + echo " -o Output file to store results" + exit 1 +} + +__build_file_hashes() { + local directory="" + local output_file="" + + while getopts "d:o:" opt; do + case "$opt" in + d) directory="$OPTARG" ;; + o) output_file="$OPTARG" ;; + *) __print_usage ;; + esac + done + + if [ -z "$directory" ] || [ -z "$output_file" ]; then + __print_usage + fi + + if [ ! -d "$directory" ]; then + echo "Error: Directory '$directory' does not exist." >&2 + return 1 + fi + + if [ ! -f "$output_file" ]; then + touch "$output_file" + if [ $? -ne 0 ]; then + echo "Error: Unable to create output file '$output_file'" >&2 + return 1 + fi + fi + + truncate -s 0 "$output_file" + + find "$directory" -type f | while read -r file; do + if [ ! -r "$file" ]; then + echo "Error: Unable to read file '$file'" >&2 + continue + fi + + file_hash=$(__calculate_hash "$file") + + if [ $? -ne 0 ]; then + echo "Error: Failed to calculate hash for '$file'" >&2 + continue + fi + + echo "$file $file_hash" >> "$output_file" + done + + sort -o "$output_file" "$output_file" +} + +__check_for_mismatches() { + local new_file="" + local old_file="" + + while [[ "$#" -gt 0 ]]; do + case "$1" in + -n|--new_file) new_file="$2"; shift 2 ;; + -o|--old_file) old_file="$2"; shift 2 ;; + *) echo "Unknown parameter: $1"; return 1 ;; + esac + done + + if [ -z "$new_file" ] || [ -z "$old_file" ]; then + echo "Error: Both -n (new_file) and -o (old_file) are required." >&2 + return 1 + fi + + if [ ! -f "$new_file" ]; then + echo "Error: New file '$new_file' does not exist." >&2 + return 1 + fi + + if [ ! -f "$old_file" ]; then + echo "Error: Old file '$old_file' does not exist." >&2 + return 1 + fi + + while IFS=' ' read -r new_path new_hash; do + old_hash=$(grep "^$new_path " "$old_file" | awk '{print $2}') + + if [ -z "$old_hash" ] || [ "$old_hash" != "$new_hash" ]; then + return 0 + fi + done < "$new_file" + + return 1 +} + +run_prebuild_if_needed() { + local dir="$1" + + cd "$dir" || exit + + [ ! -f "$HASH_1" ] && touch "$HASH_1" + [ ! -f "$HASH_2" ] && touch "$HASH_2" + + cp "$HASH_2" "$HASH_1" + __build_file_hashes -d lib -o "$HASH_2" + + if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then + sh prebuild.sh + else + echo "Skipping $dir prebuild.sh" + fi + + cp "$HASH_2" "$HASH_1" +} diff --git a/navigation/prebuild.sh b/navigation/prebuild.sh new file mode 100755 index 0000000..67ba78a --- /dev/null +++ b/navigation/prebuild.sh @@ -0,0 +1,7 @@ +#!/bin/zsh + +echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" + +flutter clean +flutter pub get +dart run build_runner build --delete-conflicting-outputs \ No newline at end of file diff --git a/prebuild.sh b/prebuild.sh new file mode 100755 index 0000000..e68efe7 --- /dev/null +++ b/prebuild.sh @@ -0,0 +1,6 @@ +#!/bin/zsh + +echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" + +flutter clean +flutter pub get From 9f3b6bb6e1cd9d37b4a501186bfea2c8fd78cc9f Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 10:43:17 +0200 Subject: [PATCH 02/23] Remove unused files from VCS, move functions.sh to files dir --- .gitignore | 121 ----------------------------- files/.gitignore | 2 + functions.sh => files/functions.sh | 0 3 files changed, 2 insertions(+), 121 deletions(-) delete mode 100644 .gitignore rename functions.sh => files/functions.sh (100%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 0cfcf1e..0000000 --- a/.gitignore +++ /dev/null @@ -1,121 +0,0 @@ -# Miscellaneous -*.class -*.lock -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# Visual Studio Code related -.classpath -.project -.settings/ -.vscode/ - -# Flutter repo-specific -/bin/cache/ -/bin/mingit/ -/dev/benchmarks/mega_gallery/ -/dev/bots/.recipe_deps -/dev/bots/android_tools/ -/dev/docs/doc/ -/dev/docs/flutter.docs.zip -/dev/docs/lib/ -/dev/docs/pubspec.yaml -/dev/integration_tests/**/xcuserdata -/dev/integration_tests/**/Pods -/packages/flutter/coverage/ -version - -# packages file containing multi-root paths -.packages.generated - -# Flutter/Dart/Pub related -**/doc/api/ -.dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies -.packages -.pub-cache/ -.pub/ -build/ -flutter_*.png -linked_*.ds -unlinked.ds -unlinked_spec.ds -**ios/Flutter/.last_build_id - -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java - -# Keystores -**/android/keystores/release/ -**/ios/Certs/ - -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Flutter.podspec -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* - -# macOS -**/macos/Flutter/GeneratedPluginRegistrant.swift -**/macos/Flutter/Flutter-Debug.xcconfig -**/macos/Flutter/Flutter-Release.xcconfig -**/macos/Flutter/Flutter-Profile.xcconfig - -# Coverage -coverage/ - -# Symbols -app.*.symbols - -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages -!/dev/ci/**/Gemfile.lock - -# Prebuild -**/hash1 -**/hash2 \ No newline at end of file diff --git a/files/.gitignore b/files/.gitignore index bc7a84b..b328d65 100644 --- a/files/.gitignore +++ b/files/.gitignore @@ -50,5 +50,7 @@ android/app/build **/*.graphql.dart **/*.gr.dart *.env +**/hash1 +**/hash2 .vscode \ No newline at end of file diff --git a/functions.sh b/files/functions.sh similarity index 100% rename from functions.sh rename to files/functions.sh From 49b8c45a7a80edfef7f663f5578fc9cc419fb07a Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 10:50:37 +0200 Subject: [PATCH 03/23] File location adjustments --- prebuild.sh => files/prebuild.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename prebuild.sh => files/prebuild.sh (100%) diff --git a/prebuild.sh b/files/prebuild.sh similarity index 100% rename from prebuild.sh rename to files/prebuild.sh From fa12a602396ce75574a4bac48910da1d4c93cefa Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 10:51:48 +0200 Subject: [PATCH 04/23] Adjusted core module prebuild script --- core/prebuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/prebuild.sh b/core/prebuild.sh index 67ba78a..3211284 100755 --- a/core/prebuild.sh +++ b/core/prebuild.sh @@ -4,4 +4,4 @@ echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" flutter clean flutter pub get -dart run build_runner build --delete-conflicting-outputs \ No newline at end of file +dart run easy_localization:generate -f keys -o locale_keys.g.dart -O lib/src/localization/generated -S resources/lang \ No newline at end of file From f2bf79d0a10d2da78ff1e4e09feb3858a29f2529 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 10:54:35 +0200 Subject: [PATCH 05/23] Quickfix --- files/functions.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/files/functions.sh b/files/functions.sh index 03815b0..4619f6f 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -104,19 +104,22 @@ __check_for_mismatches() { run_prebuild_if_needed() { local dir="$1" - cd "$dir" || exit + ( + cd "$dir" || exit - [ ! -f "$HASH_1" ] && touch "$HASH_1" - [ ! -f "$HASH_2" ] && touch "$HASH_2" + [ ! -f "$HASH_1" ] && touch "$HASH_1" + [ ! -f "$HASH_2" ] && touch "$HASH_2" - cp "$HASH_2" "$HASH_1" - __build_file_hashes -d lib -o "$HASH_2" + cp "$HASH_2" "$HASH_1" + __build_file_hashes -d lib -o "$HASH_2" - if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then - sh prebuild.sh - else - echo "Skipping $dir prebuild.sh" - fi + if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then + sh prebuild.sh + else + echo "Skipping $dir prebuild.sh" + fi - cp "$HASH_2" "$HASH_1" + cp "$HASH_2" "$HASH_1" + ) } + From f7bc42fee376bcc82fb7577048430f24617c2ce8 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 11:11:36 +0200 Subject: [PATCH 06/23] Filenames cleanup, logic adjustments --- files/.gitignore | 3 +-- files/functions.sh | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/files/.gitignore b/files/.gitignore index b328d65..0e85ce3 100644 --- a/files/.gitignore +++ b/files/.gitignore @@ -50,7 +50,6 @@ android/app/build **/*.graphql.dart **/*.gr.dart *.env -**/hash1 -**/hash2 +**/*.prebuildhash .vscode \ No newline at end of file diff --git a/files/functions.sh b/files/functions.sh index 4619f6f..93e291e 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -1,5 +1,5 @@ -readonly HASH_1="hash1" -readonly HASH_2="hash2" +readonly HASH_1="hash1.prebuildhash" +readonly HASH_2="hash2.prebuildhash" __calculate_hash() { local file_path="$1" @@ -115,11 +115,11 @@ run_prebuild_if_needed() { if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then sh prebuild.sh + __build_file_hashes -d lib -o "$HASH_2" + cp "$HASH_2" "$HASH_1" else echo "Skipping $dir prebuild.sh" fi - - cp "$HASH_2" "$HASH_1" ) } From bca3885634f48f7bd18352df86cd0b3af9a0677a Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 11:29:42 +0200 Subject: [PATCH 07/23] Prettify output --- core/prebuild.sh | 2 -- core_ui/prebuild.sh | 2 -- data/prebuild.sh | 2 -- domain/prebuild.sh | 2 -- feature/prebuild.sh | 2 -- files/fast_prebuild_script_mac.sh | 1 - files/functions.sh | 3 ++- files/prebuild.sh | 2 -- navigation/prebuild.sh | 2 -- 9 files changed, 2 insertions(+), 16 deletions(-) diff --git a/core/prebuild.sh b/core/prebuild.sh index 3211284..76c2d6c 100755 --- a/core/prebuild.sh +++ b/core/prebuild.sh @@ -1,7 +1,5 @@ #!/bin/zsh -echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" - flutter clean flutter pub get dart run easy_localization:generate -f keys -o locale_keys.g.dart -O lib/src/localization/generated -S resources/lang \ No newline at end of file diff --git a/core_ui/prebuild.sh b/core_ui/prebuild.sh index e68efe7..bfa0584 100755 --- a/core_ui/prebuild.sh +++ b/core_ui/prebuild.sh @@ -1,6 +1,4 @@ #!/bin/zsh -echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" - flutter clean flutter pub get diff --git a/data/prebuild.sh b/data/prebuild.sh index 67ba78a..b7ed5bc 100755 --- a/data/prebuild.sh +++ b/data/prebuild.sh @@ -1,7 +1,5 @@ #!/bin/zsh -echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" - flutter clean flutter pub get dart run build_runner build --delete-conflicting-outputs \ No newline at end of file diff --git a/domain/prebuild.sh b/domain/prebuild.sh index e68efe7..bfa0584 100755 --- a/domain/prebuild.sh +++ b/domain/prebuild.sh @@ -1,6 +1,4 @@ #!/bin/zsh -echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" - flutter clean flutter pub get diff --git a/feature/prebuild.sh b/feature/prebuild.sh index 67ba78a..b7ed5bc 100755 --- a/feature/prebuild.sh +++ b/feature/prebuild.sh @@ -1,7 +1,5 @@ #!/bin/zsh -echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" - flutter clean flutter pub get dart run build_runner build --delete-conflicting-outputs \ No newline at end of file diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh index dd65a0a..07a98b5 100644 --- a/files/fast_prebuild_script_mac.sh +++ b/files/fast_prebuild_script_mac.sh @@ -11,5 +11,4 @@ count=$(find ./features -mindepth 1 -maxdepth 1 -type d | wc -l) find ./features -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c 'source functions.sh; run_prebuild_if_needed "$@"' _ {} run_prebuild_if_needed navigation - run_prebuild_if_needed . diff --git a/files/functions.sh b/files/functions.sh index 93e291e..337b92d 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -114,11 +114,12 @@ run_prebuild_if_needed() { __build_file_hashes -d lib -o "$HASH_2" if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then + echo "\x1B[36m 🛠 Running $dir prebuild.sh \x1B[0m" sh prebuild.sh __build_file_hashes -d lib -o "$HASH_2" cp "$HASH_2" "$HASH_1" else - echo "Skipping $dir prebuild.sh" + echo "\x1B[32m ✅ Skipping $dir prebuild.sh \x1B[0m" fi ) } diff --git a/files/prebuild.sh b/files/prebuild.sh index e68efe7..bfa0584 100755 --- a/files/prebuild.sh +++ b/files/prebuild.sh @@ -1,6 +1,4 @@ #!/bin/zsh -echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" - flutter clean flutter pub get diff --git a/navigation/prebuild.sh b/navigation/prebuild.sh index 67ba78a..b7ed5bc 100755 --- a/navigation/prebuild.sh +++ b/navigation/prebuild.sh @@ -1,7 +1,5 @@ #!/bin/zsh -echo "\033[1;36mRunning prebuild.sh in $(realpath "$0")\033[0m" - flutter clean flutter pub get dart run build_runner build --delete-conflicting-outputs \ No newline at end of file From 590c432ea535027d85a3586113b5687a452a0934 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 11:37:25 +0200 Subject: [PATCH 08/23] Adjusted script names --- core/{prebuild.sh => module_prebuild.sh} | 0 core_ui/{prebuild.sh => module_prebuild.sh} | 0 data/{prebuild.sh => module_prebuild.sh} | 0 domain/{prebuild.sh => module_prebuild.sh} | 0 feature/{prebuild.sh => module_prebuild.sh} | 0 files/functions.sh | 7 ++-- files/{prebuild.sh => module_prebuild.sh} | 0 files/prebuild_script.sh | 15 ++++++++ files/slow_prebuild_script.sh | 36 ------------------- .../{prebuild.sh => module_prebuild.sh} | 0 10 files changed, 19 insertions(+), 39 deletions(-) rename core/{prebuild.sh => module_prebuild.sh} (100%) rename core_ui/{prebuild.sh => module_prebuild.sh} (100%) rename data/{prebuild.sh => module_prebuild.sh} (100%) rename domain/{prebuild.sh => module_prebuild.sh} (100%) rename feature/{prebuild.sh => module_prebuild.sh} (100%) rename files/{prebuild.sh => module_prebuild.sh} (100%) create mode 100755 files/prebuild_script.sh delete mode 100755 files/slow_prebuild_script.sh rename navigation/{prebuild.sh => module_prebuild.sh} (100%) diff --git a/core/prebuild.sh b/core/module_prebuild.sh similarity index 100% rename from core/prebuild.sh rename to core/module_prebuild.sh diff --git a/core_ui/prebuild.sh b/core_ui/module_prebuild.sh similarity index 100% rename from core_ui/prebuild.sh rename to core_ui/module_prebuild.sh diff --git a/data/prebuild.sh b/data/module_prebuild.sh similarity index 100% rename from data/prebuild.sh rename to data/module_prebuild.sh diff --git a/domain/prebuild.sh b/domain/module_prebuild.sh similarity index 100% rename from domain/prebuild.sh rename to domain/module_prebuild.sh diff --git a/feature/prebuild.sh b/feature/module_prebuild.sh similarity index 100% rename from feature/prebuild.sh rename to feature/module_prebuild.sh diff --git a/files/functions.sh b/files/functions.sh index 337b92d..576aba8 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -1,5 +1,6 @@ readonly HASH_1="hash1.prebuildhash" readonly HASH_2="hash2.prebuildhash" +readonly MODULE_PREBUILD="module_prebuild.sh" __calculate_hash() { local file_path="$1" @@ -114,12 +115,12 @@ run_prebuild_if_needed() { __build_file_hashes -d lib -o "$HASH_2" if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then - echo "\x1B[36m 🛠 Running $dir prebuild.sh \x1B[0m" - sh prebuild.sh + echo "\x1B[36m=======> 🛠 Running $dir $MODULE_PREBUILD \x1B[0m" + sh "$MODULE_PREBUILD" __build_file_hashes -d lib -o "$HASH_2" cp "$HASH_2" "$HASH_1" else - echo "\x1B[32m ✅ Skipping $dir prebuild.sh \x1B[0m" + echo "\x1B[32m=======> ✅ Skipping $dir $MODULE_PREBUILD \x1B[0m" fi ) } diff --git a/files/prebuild.sh b/files/module_prebuild.sh similarity index 100% rename from files/prebuild.sh rename to files/module_prebuild.sh diff --git a/files/prebuild_script.sh b/files/prebuild_script.sh new file mode 100755 index 0000000..7a9f831 --- /dev/null +++ b/files/prebuild_script.sh @@ -0,0 +1,15 @@ +#!/bin/zsh + +source functions.sh + +run_prebuild_if_needed core +run_prebuild_if_needed core_ui +run_prebuild_if_needed data +run_prebuild_if_needed domain + +for dir in ./features/*(/); do + run_prebuild_if_needed "$dir" +done + +run_prebuild_if_needed navigation +run_prebuild_if_needed . diff --git a/files/slow_prebuild_script.sh b/files/slow_prebuild_script.sh deleted file mode 100755 index a9f5d09..0000000 --- a/files/slow_prebuild_script.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# run function in all dirs -# expects a function name -allDirs() { - dirs=() - while IFS='' read -r line; do dirs+=("$line"); done < <(find . -maxdepth 2 -type d) - for dir in "${dirs[@]}"; do - $1 "$dir" - done -} - -runGet() { - cd "$1" || return - if [ -f "pubspec.yaml" ]; then - flutter clean && flutter pub get - fi - cd - >/dev/null || return -} - -flutter clean - -allDirs "runGet" - -# generate localization keys -cd "core" || exit -dart run easy_localization:generate -f keys -o locale_keys.g.dart -O lib/src/localization/generated -S resources/lang - -# generate data layer files -cd "../data" || exit -dart run build_runner build --delete-conflicting-outputs - -# generate auto route modules -if [ -d '../features' ]; then - cd "../features" - find . -mindepth 1 -maxdepth 1 -type d -exec sh -c 'cd "$0" && echo "$0" && dart run build_runner build --delete-conflicting-outputs' {} \; -fi \ No newline at end of file diff --git a/navigation/prebuild.sh b/navigation/module_prebuild.sh similarity index 100% rename from navigation/prebuild.sh rename to navigation/module_prebuild.sh From 6782aa9ab22cc4bbd31f6755250ce7824d7e7c9d Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 12:08:37 +0200 Subject: [PATCH 09/23] Adjust script logic, improve output --- files/functions.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/files/functions.sh b/files/functions.sh index 576aba8..f34eeac 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -109,18 +109,22 @@ run_prebuild_if_needed() { cd "$dir" || exit [ ! -f "$HASH_1" ] && touch "$HASH_1" - [ ! -f "$HASH_2" ] && touch "$HASH_2" - cp "$HASH_2" "$HASH_1" + if [ -f "$HASH_2" ]; then + cp "$HASH_2" "$HASH_1" + else + touch "$HASH_2" + fi + __build_file_hashes -d lib -o "$HASH_2" if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then - echo "\x1B[36m=======> 🛠 Running $dir $MODULE_PREBUILD \x1B[0m" + echo "\x1B[36m🔵Running $dir $MODULE_PREBUILD \x1B[0m" sh "$MODULE_PREBUILD" __build_file_hashes -d lib -o "$HASH_2" cp "$HASH_2" "$HASH_1" else - echo "\x1B[32m=======> ✅ Skipping $dir $MODULE_PREBUILD \x1B[0m" + echo "\x1B[32m🟢Skipping $dir $MODULE_PREBUILD \x1B[0m" fi ) } From 47d9e6709c6f3b58d0a5df47aeab6623dc70c3ca Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 12:40:38 +0200 Subject: [PATCH 10/23] Adjust interpreter in use, minor fixes --- core/module_prebuild.sh | 2 +- core_ui/module_prebuild.sh | 2 +- data/module_prebuild.sh | 2 +- domain/module_prebuild.sh | 2 +- feature/module_prebuild.sh | 2 +- files/fast_prebuild_script_mac.sh | 4 ++-- files/frontend-run.sh | 2 +- files/functions.sh | 4 ++-- files/module_prebuild.sh | 2 +- files/prebuild_script.sh | 2 +- navigation/module_prebuild.sh | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) mode change 100644 => 100755 files/fast_prebuild_script_mac.sh mode change 100644 => 100755 files/frontend-run.sh diff --git a/core/module_prebuild.sh b/core/module_prebuild.sh index 76c2d6c..33c31a6 100755 --- a/core/module_prebuild.sh +++ b/core/module_prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash flutter clean flutter pub get diff --git a/core_ui/module_prebuild.sh b/core_ui/module_prebuild.sh index bfa0584..18b5537 100755 --- a/core_ui/module_prebuild.sh +++ b/core_ui/module_prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash flutter clean flutter pub get diff --git a/data/module_prebuild.sh b/data/module_prebuild.sh index b7ed5bc..bb1a71e 100755 --- a/data/module_prebuild.sh +++ b/data/module_prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash flutter clean flutter pub get diff --git a/domain/module_prebuild.sh b/domain/module_prebuild.sh index bfa0584..18b5537 100755 --- a/domain/module_prebuild.sh +++ b/domain/module_prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash flutter clean flutter pub get diff --git a/feature/module_prebuild.sh b/feature/module_prebuild.sh index b7ed5bc..bb1a71e 100755 --- a/feature/module_prebuild.sh +++ b/feature/module_prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash flutter clean flutter pub get diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh old mode 100644 new mode 100755 index 07a98b5..1ba4225 --- a/files/fast_prebuild_script_mac.sh +++ b/files/fast_prebuild_script_mac.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash source functions.sh @@ -11,4 +11,4 @@ count=$(find ./features -mindepth 1 -maxdepth 1 -type d | wc -l) find ./features -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c 'source functions.sh; run_prebuild_if_needed "$@"' _ {} run_prebuild_if_needed navigation -run_prebuild_if_needed . +run_prebuild_if_needed . \ No newline at end of file diff --git a/files/frontend-run.sh b/files/frontend-run.sh old mode 100644 new mode 100755 index 50e59f8..6b5329c --- a/files/frontend-run.sh +++ b/files/frontend-run.sh @@ -3,4 +3,4 @@ export DEPLOYMENT_ENV="$1" docker build --build-arg="RUN_FILE=lib/main.dart" --no-cache -t flutter-web:$DEPLOYMENT_ENV . -docker compose up -d flutter-web-prod \ No newline at end of file +docker compose up -d flutter-web-prod diff --git a/files/functions.sh b/files/functions.sh index f34eeac..ad6271a 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -119,12 +119,12 @@ run_prebuild_if_needed() { __build_file_hashes -d lib -o "$HASH_2" if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then - echo "\x1B[36m🔵Running $dir $MODULE_PREBUILD \x1B[0m" + echo -e "\x1B[36m🔵Running $dir $MODULE_PREBUILD \x1B[0m" sh "$MODULE_PREBUILD" __build_file_hashes -d lib -o "$HASH_2" cp "$HASH_2" "$HASH_1" else - echo "\x1B[32m🟢Skipping $dir $MODULE_PREBUILD \x1B[0m" + echo -e "\x1B[32m🟢Skipping $dir $MODULE_PREBUILD \x1B[0m" fi ) } diff --git a/files/module_prebuild.sh b/files/module_prebuild.sh index bfa0584..18b5537 100755 --- a/files/module_prebuild.sh +++ b/files/module_prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash flutter clean flutter pub get diff --git a/files/prebuild_script.sh b/files/prebuild_script.sh index 7a9f831..80deb38 100755 --- a/files/prebuild_script.sh +++ b/files/prebuild_script.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash source functions.sh diff --git a/navigation/module_prebuild.sh b/navigation/module_prebuild.sh index b7ed5bc..bb1a71e 100755 --- a/navigation/module_prebuild.sh +++ b/navigation/module_prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash flutter clean flutter pub get From b5f7759bcfa0882fb7669087142a7d78f54a84df Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 13:43:30 +0200 Subject: [PATCH 11/23] Script fixes --- files/fast_prebuild_script_mac.sh | 11 ++++++++--- files/functions.sh | 14 +++++++------- files/prebuild_script.sh | 10 +++++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh index 1ba4225..0119c8d 100755 --- a/files/fast_prebuild_script_mac.sh +++ b/files/fast_prebuild_script_mac.sh @@ -7,8 +7,13 @@ run_prebuild_if_needed core_ui run_prebuild_if_needed data run_prebuild_if_needed domain -count=$(find ./features -mindepth 1 -maxdepth 1 -type d | wc -l) -find ./features -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c 'source functions.sh; run_prebuild_if_needed "$@"' _ {} +if [ -d 'features' ]; then + count=$(find 'features' -mindepth 1 -maxdepth 1 -type d | wc -l) + find 'features' -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c ' + source functions.sh + run_prebuild_if_needed "$0" + ' {} +fi run_prebuild_if_needed navigation -run_prebuild_if_needed . \ No newline at end of file +run_prebuild_if_needed . diff --git a/files/functions.sh b/files/functions.sh index ad6271a..68cdfe4 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -18,11 +18,11 @@ __build_file_hashes() { local directory="" local output_file="" - while getopts "d:o:" opt; do - case "$opt" in - d) directory="$OPTARG" ;; - o) output_file="$OPTARG" ;; - *) __print_usage ;; + while [ $# -gt 0 ]; do + case "$1" in + -d) directory="$2"; shift 2 ;; + -o) output_file="$2"; shift 2 ;; + *) echo "Unknown option: $1"; __print_usage; return 1 ;; esac done @@ -119,12 +119,12 @@ run_prebuild_if_needed() { __build_file_hashes -d lib -o "$HASH_2" if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then - echo -e "\x1B[36m🔵Running $dir $MODULE_PREBUILD \x1B[0m" + echo -e "\x1B[32m🟢Running $dir $MODULE_PREBUILD \x1B[0m" sh "$MODULE_PREBUILD" __build_file_hashes -d lib -o "$HASH_2" cp "$HASH_2" "$HASH_1" else - echo -e "\x1B[32m🟢Skipping $dir $MODULE_PREBUILD \x1B[0m" + echo -e "\x1B[36m🔵Skipping $dir $MODULE_PREBUILD \x1B[0m" fi ) } diff --git a/files/prebuild_script.sh b/files/prebuild_script.sh index 80deb38..b34d01b 100755 --- a/files/prebuild_script.sh +++ b/files/prebuild_script.sh @@ -7,9 +7,13 @@ run_prebuild_if_needed core_ui run_prebuild_if_needed data run_prebuild_if_needed domain -for dir in ./features/*(/); do - run_prebuild_if_needed "$dir" -done +if [ -d 'features' ]; then + for dir in ./features/*; do + if [ -d "$dir" ]; then + run_prebuild_if_needed "$dir" + fi + done +fi run_prebuild_if_needed navigation run_prebuild_if_needed . From c711521dbe011f130ffa7aa39de5fb9a91abd0c9 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 13:49:34 +0200 Subject: [PATCH 12/23] Cosmetic adjustment --- files/prebuild_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/prebuild_script.sh b/files/prebuild_script.sh index b34d01b..25d0e99 100755 --- a/files/prebuild_script.sh +++ b/files/prebuild_script.sh @@ -8,7 +8,7 @@ run_prebuild_if_needed data run_prebuild_if_needed domain if [ -d 'features' ]; then - for dir in ./features/*; do + for dir in features/*; do if [ -d "$dir" ]; then run_prebuild_if_needed "$dir" fi From 0d24d69c5817f7ab8663382365bd75a26984cde5 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 14:10:36 +0200 Subject: [PATCH 13/23] Optimise function --- files/functions.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/files/functions.sh b/files/functions.sh index 68cdfe4..369a116 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -91,13 +91,12 @@ __check_for_mismatches() { return 1 fi - while IFS=' ' read -r new_path new_hash; do - old_hash=$(grep "^$new_path " "$old_file" | awk '{print $2}') + new_hash=$(sha256sum "$new_file" | awk '{print $1}') + old_hash=$(sha256sum "$old_file" | awk '{print $1}') - if [ -z "$old_hash" ] || [ "$old_hash" != "$new_hash" ]; then - return 0 - fi - done < "$new_file" + if [ "$new_hash" != "$old_hash" ]; then + return 0 + fi return 1 } From 43c02458c09c8cd61d3fbc60121605f2c065f735 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Mon, 14 Apr 2025 16:14:56 +0200 Subject: [PATCH 14/23] Optimise script --- files/fast_prebuild_script_mac.sh | 8 +++++-- files/functions.sh | 36 ++++++++++--------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh index 0119c8d..e9dbf29 100755 --- a/files/fast_prebuild_script_mac.sh +++ b/files/fast_prebuild_script_mac.sh @@ -2,15 +2,19 @@ source functions.sh +export -f run_prebuild_if_needed +export -f __build_file_hashes +export -f __check_for_mismatches +export -f __calculate_hash + run_prebuild_if_needed core run_prebuild_if_needed core_ui run_prebuild_if_needed data run_prebuild_if_needed domain if [ -d 'features' ]; then - count=$(find 'features' -mindepth 1 -maxdepth 1 -type d | wc -l) + count=$(nproc 2>/dev/null || sysctl -n hw.ncpu) find 'features' -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c ' - source functions.sh run_prebuild_if_needed "$0" ' {} fi diff --git a/files/functions.sh b/files/functions.sh index 369a116..ee213a6 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -1,3 +1,7 @@ +export HASH_1="hash1.prebuildhash" +export HASH_2="hash2.prebuildhash" +export MODULE_PREBUILD="module_prebuild.sh" + readonly HASH_1="hash1.prebuildhash" readonly HASH_2="hash2.prebuildhash" readonly MODULE_PREBUILD="module_prebuild.sh" @@ -35,33 +39,15 @@ __build_file_hashes() { return 1 fi - if [ ! -f "$output_file" ]; then - touch "$output_file" - if [ $? -ne 0 ]; then - echo "Error: Unable to create output file '$output_file'" >&2 - return 1 - fi - fi - - truncate -s 0 "$output_file" - - find "$directory" -type f | while read -r file; do - if [ ! -r "$file" ]; then - echo "Error: Unable to read file '$file'" >&2 - continue - fi - - file_hash=$(__calculate_hash "$file") + local hash + hash=$(find "$directory" -type f -exec sha256sum {} \; | sort | sha256sum | awk '{ print $1 }') - if [ $? -ne 0 ]; then - echo "Error: Failed to calculate hash for '$file'" >&2 - continue - fi - - echo "$file $file_hash" >> "$output_file" - done + if [ $? -ne 0 ]; then + echo "Error: Failed to calculate directory hash for '$directory'" >&2 + return 1 + fi - sort -o "$output_file" "$output_file" + echo "$hash" > "$output_file" } __check_for_mismatches() { From 993b16ba6b0d27f44f43366e31a96076b075652b Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Tue, 15 Apr 2025 13:09:17 +0200 Subject: [PATCH 15/23] Add --force flag to prebuild scripts --- files/fast_prebuild_script_mac.sh | 16 ++++++++++++++++ files/functions.sh | 23 ++++++++++++++++++++--- files/prebuild_script.sh | 15 +++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh index e9dbf29..488d568 100755 --- a/files/fast_prebuild_script_mac.sh +++ b/files/fast_prebuild_script_mac.sh @@ -2,6 +2,22 @@ source functions.sh +FORCE_PREBUILD=false + +while [[ $# -gt 0 ]]; do + case "$1" in + --force) + FORCE_PREBUILD=true + shift + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +export FORCE_PREBUILD export -f run_prebuild_if_needed export -f __build_file_hashes export -f __check_for_mismatches diff --git a/files/functions.sh b/files/functions.sh index ee213a6..e16b2cd 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -88,7 +88,25 @@ __check_for_mismatches() { } run_prebuild_if_needed() { - local dir="$1" + local force_run="" + local dir="" + + while [[ $# -gt 0 ]]; do + case "$1" in + --force) + force_run=true + shift + ;; + *) + dir="$1" + shift + ;; + esac + done + + if [[ -z "$force_run" ]]; then + force_run="${FORCE_PREBUILD:-false}" + fi ( cd "$dir" || exit @@ -103,7 +121,7 @@ run_prebuild_if_needed() { __build_file_hashes -d lib -o "$HASH_2" - if __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then + if $force_run || __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then echo -e "\x1B[32m🟢Running $dir $MODULE_PREBUILD \x1B[0m" sh "$MODULE_PREBUILD" __build_file_hashes -d lib -o "$HASH_2" @@ -113,4 +131,3 @@ run_prebuild_if_needed() { fi ) } - diff --git a/files/prebuild_script.sh b/files/prebuild_script.sh index 25d0e99..41a786b 100755 --- a/files/prebuild_script.sh +++ b/files/prebuild_script.sh @@ -2,6 +2,21 @@ source functions.sh +FORCE_PREBUILD=false + +while [[ $# -gt 0 ]]; do + case "$1" in + --force) + FORCE_PREBUILD=true + shift + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + run_prebuild_if_needed core run_prebuild_if_needed core_ui run_prebuild_if_needed data From 056cfed3d887469857a0bd217743cf0cfbcec78a Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Wed, 16 Apr 2025 10:40:44 +0200 Subject: [PATCH 16/23] Move module_prebuild.sh and hash files to separate directory, add compact flag for prebuild scripts --- core/{ => .prebuild}/module_prebuild.sh | 0 core_ui/{ => .prebuild}/module_prebuild.sh | 0 data/{ => .prebuild}/module_prebuild.sh | 0 domain/{ => .prebuild}/module_prebuild.sh | 0 files/{ => .prebuild}/module_prebuild.sh | 0 files/fast_prebuild_script_mac.sh | 6 ++++ files/functions.sh | 30 ++++++++++++++----- files/prebuild_script.sh | 21 +++++++++---- navigation/{ => .prebuild}/module_prebuild.sh | 0 9 files changed, 45 insertions(+), 12 deletions(-) rename core/{ => .prebuild}/module_prebuild.sh (100%) rename core_ui/{ => .prebuild}/module_prebuild.sh (100%) rename data/{ => .prebuild}/module_prebuild.sh (100%) rename domain/{ => .prebuild}/module_prebuild.sh (100%) rename files/{ => .prebuild}/module_prebuild.sh (100%) rename navigation/{ => .prebuild}/module_prebuild.sh (100%) diff --git a/core/module_prebuild.sh b/core/.prebuild/module_prebuild.sh similarity index 100% rename from core/module_prebuild.sh rename to core/.prebuild/module_prebuild.sh diff --git a/core_ui/module_prebuild.sh b/core_ui/.prebuild/module_prebuild.sh similarity index 100% rename from core_ui/module_prebuild.sh rename to core_ui/.prebuild/module_prebuild.sh diff --git a/data/module_prebuild.sh b/data/.prebuild/module_prebuild.sh similarity index 100% rename from data/module_prebuild.sh rename to data/.prebuild/module_prebuild.sh diff --git a/domain/module_prebuild.sh b/domain/.prebuild/module_prebuild.sh similarity index 100% rename from domain/module_prebuild.sh rename to domain/.prebuild/module_prebuild.sh diff --git a/files/module_prebuild.sh b/files/.prebuild/module_prebuild.sh similarity index 100% rename from files/module_prebuild.sh rename to files/.prebuild/module_prebuild.sh diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh index 488d568..f0b333c 100755 --- a/files/fast_prebuild_script_mac.sh +++ b/files/fast_prebuild_script_mac.sh @@ -3,6 +3,7 @@ source functions.sh FORCE_PREBUILD=false +COMPACT_PREBUILD=false while [[ $# -gt 0 ]]; do case "$1" in @@ -10,6 +11,10 @@ while [[ $# -gt 0 ]]; do FORCE_PREBUILD=true shift ;; + --compact) + COMPACT_PREBUILD=true + shift + ;; *) echo "Unknown option: $1" exit 1 @@ -18,6 +23,7 @@ while [[ $# -gt 0 ]]; do done export FORCE_PREBUILD +export COMPACT_PREBUILD export -f run_prebuild_if_needed export -f __build_file_hashes export -f __check_for_mismatches diff --git a/files/functions.sh b/files/functions.sh index e16b2cd..ea5110a 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -1,10 +1,14 @@ +#!/bin/bash + export HASH_1="hash1.prebuildhash" export HASH_2="hash2.prebuildhash" export MODULE_PREBUILD="module_prebuild.sh" +export PREBUILD_DIR=".prebuild" readonly HASH_1="hash1.prebuildhash" readonly HASH_2="hash2.prebuildhash" readonly MODULE_PREBUILD="module_prebuild.sh" +readonly PREBUILD_DIR=".prebuild" __calculate_hash() { local file_path="$1" @@ -89,6 +93,7 @@ __check_for_mismatches() { run_prebuild_if_needed() { local force_run="" + local compact_output="" local dir="" while [[ $# -gt 0 ]]; do @@ -97,6 +102,10 @@ run_prebuild_if_needed() { force_run=true shift ;; + --compact) + compact_output=true + shift + ;; *) dir="$1" shift @@ -104,12 +113,11 @@ run_prebuild_if_needed() { esac done - if [[ -z "$force_run" ]]; then - force_run="${FORCE_PREBUILD:-false}" - fi + [[ -z "$force_run" ]] && force_run="${FORCE_PREBUILD:-false}" + [[ -z "$compact_output" ]] && compact_output="${COMPACT_PREBUILD:-false}" ( - cd "$dir" || exit + cd "$dir/$PREBUILD_DIR" || exit [ ! -f "$HASH_1" ] && touch "$HASH_1" @@ -119,12 +127,20 @@ run_prebuild_if_needed() { touch "$HASH_2" fi - __build_file_hashes -d lib -o "$HASH_2" + __build_file_hashes -d ../lib -o "$HASH_2" if $force_run || __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then echo -e "\x1B[32m🟢Running $dir $MODULE_PREBUILD \x1B[0m" - sh "$MODULE_PREBUILD" - __build_file_hashes -d lib -o "$HASH_2" + cd ../ + + if $compact_output; then + sh "$PREBUILD_DIR/$MODULE_PREBUILD" > /dev/null + else + sh "$PREBUILD_DIR/$MODULE_PREBUILD" + fi + + cd "$PREBUILD_DIR" + __build_file_hashes -d ../lib -o "$HASH_2" cp "$HASH_2" "$HASH_1" else echo -e "\x1B[36m🔵Skipping $dir $MODULE_PREBUILD \x1B[0m" diff --git a/files/prebuild_script.sh b/files/prebuild_script.sh index 41a786b..f0b333c 100755 --- a/files/prebuild_script.sh +++ b/files/prebuild_script.sh @@ -3,6 +3,7 @@ source functions.sh FORCE_PREBUILD=false +COMPACT_PREBUILD=false while [[ $# -gt 0 ]]; do case "$1" in @@ -10,6 +11,10 @@ while [[ $# -gt 0 ]]; do FORCE_PREBUILD=true shift ;; + --compact) + COMPACT_PREBUILD=true + shift + ;; *) echo "Unknown option: $1" exit 1 @@ -17,17 +22,23 @@ while [[ $# -gt 0 ]]; do esac done +export FORCE_PREBUILD +export COMPACT_PREBUILD +export -f run_prebuild_if_needed +export -f __build_file_hashes +export -f __check_for_mismatches +export -f __calculate_hash + run_prebuild_if_needed core run_prebuild_if_needed core_ui run_prebuild_if_needed data run_prebuild_if_needed domain if [ -d 'features' ]; then - for dir in features/*; do - if [ -d "$dir" ]; then - run_prebuild_if_needed "$dir" - fi - done + count=$(nproc 2>/dev/null || sysctl -n hw.ncpu) + find 'features' -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c ' + run_prebuild_if_needed "$0" + ' {} fi run_prebuild_if_needed navigation diff --git a/navigation/module_prebuild.sh b/navigation/.prebuild/module_prebuild.sh similarity index 100% rename from navigation/module_prebuild.sh rename to navigation/.prebuild/module_prebuild.sh From 47f2c5adbda41b090a0fadbbe0896f66387dad90 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Wed, 16 Apr 2025 10:46:37 +0200 Subject: [PATCH 17/23] Fix incorrect feature template --- feature/{ => .prebuild}/module_prebuild.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename feature/{ => .prebuild}/module_prebuild.sh (100%) diff --git a/feature/module_prebuild.sh b/feature/.prebuild/module_prebuild.sh similarity index 100% rename from feature/module_prebuild.sh rename to feature/.prebuild/module_prebuild.sh From 9a4740cebe4ee1c0eee6da13d81e329ffe79cd4a Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Wed, 16 Apr 2025 11:33:02 +0200 Subject: [PATCH 18/23] Implement error handling in prebuild scripts --- files/functions.sh | 171 ++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 88 deletions(-) diff --git a/files/functions.sh b/files/functions.sh index ea5110a..b8fc06c 100755 --- a/files/functions.sh +++ b/files/functions.sh @@ -1,94 +1,89 @@ #!/bin/bash -export HASH_1="hash1.prebuildhash" -export HASH_2="hash2.prebuildhash" -export MODULE_PREBUILD="module_prebuild.sh" -export PREBUILD_DIR=".prebuild" - readonly HASH_1="hash1.prebuildhash" readonly HASH_2="hash2.prebuildhash" readonly MODULE_PREBUILD="module_prebuild.sh" readonly PREBUILD_DIR=".prebuild" -__calculate_hash() { - local file_path="$1" - sha256sum "$file_path" | awk '{ print $1 }' -} +export PREBUILD_DIR HASH_1 HASH_2 MODULE_PREBUILD + +readonly COLOR_GREEN="\x1B[32m" +readonly COLOR_BLUE="\x1B[36m" +readonly COLOR_RED="\x1B[31m" +readonly COLOR_RESET="\x1B[0m" + +export COLOR_GREEN COLOR_BLUE COLOR_RED COLOR_RESET -__print_usage() { - echo "Usage: __build_file_hashes -d -o " - echo " -d Directory to scan" - echo " -o Output file to store results" - exit 1 +__calculate_hash() { + local file_path="$1" + sha256sum "$file_path" | awk '{ print $1 }' } __build_file_hashes() { - local directory="" - local output_file="" - - while [ $# -gt 0 ]; do - case "$1" in - -d) directory="$2"; shift 2 ;; - -o) output_file="$2"; shift 2 ;; - *) echo "Unknown option: $1"; __print_usage; return 1 ;; - esac - done - - if [ -z "$directory" ] || [ -z "$output_file" ]; then - __print_usage - fi + local directory="" + local output_file="" - if [ ! -d "$directory" ]; then - echo "Error: Directory '$directory' does not exist." >&2 - return 1 - fi + while [ $# -gt 0 ]; do + case "$1" in + -d) directory="$2"; shift 2 ;; + -o) output_file="$2"; shift 2 ;; + *) echo "Unknown option: $1" ;; + esac + done - local hash - hash=$(find "$directory" -type f -exec sha256sum {} \; | sort | sha256sum | awk '{ print $1 }') + if [ -z "$directory" ] || [ -z "$output_file" ]; then + echo "Error: Both -d (directory) and -o (output_file) are required." >&2 + return 1 + fi - if [ $? -ne 0 ]; then - echo "Error: Failed to calculate directory hash for '$directory'" >&2 - return 1 - fi + if [ ! -d "$directory" ]; then + echo "Error: Directory '$directory' does not exist." >&2 + return 1 + fi - echo "$hash" > "$output_file" + local hash + hash=$(find "$directory" -type f -exec sha256sum {} \; | sort | sha256sum | awk '{ print $1 }') + + if [ $? -ne 0 ]; then + echo "Error: Failed to calculate directory hash for '$directory'" >&2 + return 1 + fi + + echo "$hash" > "$output_file" } __check_for_mismatches() { - local new_file="" - local old_file="" - - while [[ "$#" -gt 0 ]]; do - case "$1" in - -n|--new_file) new_file="$2"; shift 2 ;; - -o|--old_file) old_file="$2"; shift 2 ;; - *) echo "Unknown parameter: $1"; return 1 ;; - esac - done - - if [ -z "$new_file" ] || [ -z "$old_file" ]; then - echo "Error: Both -n (new_file) and -o (old_file) are required." >&2 - return 1 - fi + local new_file="" + local old_file="" - if [ ! -f "$new_file" ]; then - echo "Error: New file '$new_file' does not exist." >&2 - return 1 - fi - - if [ ! -f "$old_file" ]; then - echo "Error: Old file '$old_file' does not exist." >&2 - return 1 - fi + while [[ "$#" -gt 0 ]]; do + case "$1" in + -n|--new_file) new_file="$2"; shift 2 ;; + -o|--old_file) old_file="$2"; shift 2 ;; + *) echo "Unknown parameter: $1"; return 1 ;; + esac + done - new_hash=$(sha256sum "$new_file" | awk '{print $1}') - old_hash=$(sha256sum "$old_file" | awk '{print $1}') + if [ -z "$new_file" ] || [ -z "$old_file" ]; then + echo "Error: Both -n (new_file) and -o (old_file) are required." >&2 + return 1 + fi - if [ "$new_hash" != "$old_hash" ]; then - return 0 - fi + if [ ! -f "$new_file" ]; then + echo "Error: New file '$new_file' does not exist." >&2 + return 1 + fi + if [ ! -f "$old_file" ]; then + echo "Error: Old file '$old_file' does not exist." >&2 return 1 + fi + + local new_hash old_hash + new_hash=$(sha256sum "$new_file" | awk '{print $1}') + old_hash=$(sha256sum "$old_file" | awk '{print $1}') + + [[ "$new_hash" != "$old_hash" ]] } run_prebuild_if_needed() { @@ -98,18 +93,9 @@ run_prebuild_if_needed() { while [[ $# -gt 0 ]]; do case "$1" in - --force) - force_run=true - shift - ;; - --compact) - compact_output=true - shift - ;; - *) - dir="$1" - shift - ;; + --force) force_run=true; shift ;; + --compact) compact_output=true; shift ;; + *) dir="$1"; shift ;; esac done @@ -117,20 +103,29 @@ run_prebuild_if_needed() { [[ -z "$compact_output" ]] && compact_output="${COMPACT_PREBUILD:-false}" ( - cd "$dir/$PREBUILD_DIR" || exit + set -euo pipefail + + handle_error() { + echo -e "${COLOR_RED}🔴Error occurred while processing '$dir'. Cleaning up hash files and skipping module${COLOR_RESET}" + [[ -n "${abs_hash_1:-}" && -f "$abs_hash_1" ]] && rm -f "$abs_hash_1" + [[ -n "${abs_hash_2:-}" && -f "$abs_hash_2" ]] && rm -f "$abs_hash_2" + exit 0 + } + + trap 'handle_error' ERR + + cd "$dir/$PREBUILD_DIR" [ ! -f "$HASH_1" ] && touch "$HASH_1" + [ -f "$HASH_2" ] && cp "$HASH_2" "$HASH_1" || touch "$HASH_2" - if [ -f "$HASH_2" ]; then - cp "$HASH_2" "$HASH_1" - else - touch "$HASH_2" - fi + abs_hash_1="$(realpath "$HASH_1")" + abs_hash_2="$(realpath "$HASH_2")" __build_file_hashes -d ../lib -o "$HASH_2" if $force_run || __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then - echo -e "\x1B[32m🟢Running $dir $MODULE_PREBUILD \x1B[0m" + echo -e "${COLOR_GREEN}🟢Running $dir $MODULE_PREBUILD${COLOR_RESET}" cd ../ if $compact_output; then @@ -143,7 +138,7 @@ run_prebuild_if_needed() { __build_file_hashes -d ../lib -o "$HASH_2" cp "$HASH_2" "$HASH_1" else - echo -e "\x1B[36m🔵Skipping $dir $MODULE_PREBUILD \x1B[0m" + echo -e "${COLOR_BLUE}🔵Skipping $dir $MODULE_PREBUILD${COLOR_RESET}" fi ) } From 17df65347928f9951a463fe6385a050d4d21f844 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Wed, 16 Apr 2025 11:52:06 +0200 Subject: [PATCH 19/23] Add temporarily fix for json_serializable --- data/pubspec.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/pubspec.yaml b/data/pubspec.yaml index 0f597f2..a69d3d1 100644 --- a/data/pubspec.yaml +++ b/data/pubspec.yaml @@ -25,3 +25,7 @@ dev_dependencies: build_runner: ^2.4.8 json_serializable: ^6.8.0 + +# TODO: Remove when fixed (https://github.com/google/json_serializable.dart/issues/1485) +dependency_overrides: + analyzer: 7.3.0 From e396c235b6f26e8ab7704366da3ff06da3d928c6 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Thu, 17 Apr 2025 16:11:17 +0200 Subject: [PATCH 20/23] Move scripts to a separate folder, refactor modular prebuild approach --- files/fast_prebuild_script_mac.sh | 45 ------- files/functions.sh | 144 ---------------------- files/prebuild_script.sh | 45 ------- files/scripts/fast_prebuild_script_mac.sh | 60 +++++++++ files/{ => scripts}/frontend-run.sh | 0 files/scripts/functions.sh | 73 +++++++++++ files/scripts/prebuild_script.sh | 56 +++++++++ 7 files changed, 189 insertions(+), 234 deletions(-) delete mode 100755 files/fast_prebuild_script_mac.sh delete mode 100755 files/functions.sh delete mode 100755 files/prebuild_script.sh create mode 100755 files/scripts/fast_prebuild_script_mac.sh rename files/{ => scripts}/frontend-run.sh (100%) create mode 100755 files/scripts/functions.sh create mode 100755 files/scripts/prebuild_script.sh diff --git a/files/fast_prebuild_script_mac.sh b/files/fast_prebuild_script_mac.sh deleted file mode 100755 index f0b333c..0000000 --- a/files/fast_prebuild_script_mac.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -source functions.sh - -FORCE_PREBUILD=false -COMPACT_PREBUILD=false - -while [[ $# -gt 0 ]]; do - case "$1" in - --force) - FORCE_PREBUILD=true - shift - ;; - --compact) - COMPACT_PREBUILD=true - shift - ;; - *) - echo "Unknown option: $1" - exit 1 - ;; - esac -done - -export FORCE_PREBUILD -export COMPACT_PREBUILD -export -f run_prebuild_if_needed -export -f __build_file_hashes -export -f __check_for_mismatches -export -f __calculate_hash - -run_prebuild_if_needed core -run_prebuild_if_needed core_ui -run_prebuild_if_needed data -run_prebuild_if_needed domain - -if [ -d 'features' ]; then - count=$(nproc 2>/dev/null || sysctl -n hw.ncpu) - find 'features' -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c ' - run_prebuild_if_needed "$0" - ' {} -fi - -run_prebuild_if_needed navigation -run_prebuild_if_needed . diff --git a/files/functions.sh b/files/functions.sh deleted file mode 100755 index b8fc06c..0000000 --- a/files/functions.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/bash - -readonly HASH_1="hash1.prebuildhash" -readonly HASH_2="hash2.prebuildhash" -readonly MODULE_PREBUILD="module_prebuild.sh" -readonly PREBUILD_DIR=".prebuild" - -export PREBUILD_DIR HASH_1 HASH_2 MODULE_PREBUILD - -readonly COLOR_GREEN="\x1B[32m" -readonly COLOR_BLUE="\x1B[36m" -readonly COLOR_RED="\x1B[31m" -readonly COLOR_RESET="\x1B[0m" - -export COLOR_GREEN COLOR_BLUE COLOR_RED COLOR_RESET - -__calculate_hash() { - local file_path="$1" - sha256sum "$file_path" | awk '{ print $1 }' -} - -__build_file_hashes() { - local directory="" - local output_file="" - - while [ $# -gt 0 ]; do - case "$1" in - -d) directory="$2"; shift 2 ;; - -o) output_file="$2"; shift 2 ;; - *) echo "Unknown option: $1" ;; - esac - done - - if [ -z "$directory" ] || [ -z "$output_file" ]; then - echo "Error: Both -d (directory) and -o (output_file) are required." >&2 - return 1 - fi - - if [ ! -d "$directory" ]; then - echo "Error: Directory '$directory' does not exist." >&2 - return 1 - fi - - local hash - hash=$(find "$directory" -type f -exec sha256sum {} \; | sort | sha256sum | awk '{ print $1 }') - - if [ $? -ne 0 ]; then - echo "Error: Failed to calculate directory hash for '$directory'" >&2 - return 1 - fi - - echo "$hash" > "$output_file" -} - -__check_for_mismatches() { - local new_file="" - local old_file="" - - while [[ "$#" -gt 0 ]]; do - case "$1" in - -n|--new_file) new_file="$2"; shift 2 ;; - -o|--old_file) old_file="$2"; shift 2 ;; - *) echo "Unknown parameter: $1"; return 1 ;; - esac - done - - if [ -z "$new_file" ] || [ -z "$old_file" ]; then - echo "Error: Both -n (new_file) and -o (old_file) are required." >&2 - return 1 - fi - - if [ ! -f "$new_file" ]; then - echo "Error: New file '$new_file' does not exist." >&2 - return 1 - fi - - if [ ! -f "$old_file" ]; then - echo "Error: Old file '$old_file' does not exist." >&2 - return 1 - fi - - local new_hash old_hash - new_hash=$(sha256sum "$new_file" | awk '{print $1}') - old_hash=$(sha256sum "$old_file" | awk '{print $1}') - - [[ "$new_hash" != "$old_hash" ]] -} - -run_prebuild_if_needed() { - local force_run="" - local compact_output="" - local dir="" - - while [[ $# -gt 0 ]]; do - case "$1" in - --force) force_run=true; shift ;; - --compact) compact_output=true; shift ;; - *) dir="$1"; shift ;; - esac - done - - [[ -z "$force_run" ]] && force_run="${FORCE_PREBUILD:-false}" - [[ -z "$compact_output" ]] && compact_output="${COMPACT_PREBUILD:-false}" - - ( - set -euo pipefail - - handle_error() { - echo -e "${COLOR_RED}🔴Error occurred while processing '$dir'. Cleaning up hash files and skipping module${COLOR_RESET}" - [[ -n "${abs_hash_1:-}" && -f "$abs_hash_1" ]] && rm -f "$abs_hash_1" - [[ -n "${abs_hash_2:-}" && -f "$abs_hash_2" ]] && rm -f "$abs_hash_2" - exit 0 - } - - trap 'handle_error' ERR - - cd "$dir/$PREBUILD_DIR" - - [ ! -f "$HASH_1" ] && touch "$HASH_1" - [ -f "$HASH_2" ] && cp "$HASH_2" "$HASH_1" || touch "$HASH_2" - - abs_hash_1="$(realpath "$HASH_1")" - abs_hash_2="$(realpath "$HASH_2")" - - __build_file_hashes -d ../lib -o "$HASH_2" - - if $force_run || __check_for_mismatches -o "$HASH_1" -n "$HASH_2"; then - echo -e "${COLOR_GREEN}🟢Running $dir $MODULE_PREBUILD${COLOR_RESET}" - cd ../ - - if $compact_output; then - sh "$PREBUILD_DIR/$MODULE_PREBUILD" > /dev/null - else - sh "$PREBUILD_DIR/$MODULE_PREBUILD" - fi - - cd "$PREBUILD_DIR" - __build_file_hashes -d ../lib -o "$HASH_2" - cp "$HASH_2" "$HASH_1" - else - echo -e "${COLOR_BLUE}🔵Skipping $dir $MODULE_PREBUILD${COLOR_RESET}" - fi - ) -} diff --git a/files/prebuild_script.sh b/files/prebuild_script.sh deleted file mode 100755 index f0b333c..0000000 --- a/files/prebuild_script.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -source functions.sh - -FORCE_PREBUILD=false -COMPACT_PREBUILD=false - -while [[ $# -gt 0 ]]; do - case "$1" in - --force) - FORCE_PREBUILD=true - shift - ;; - --compact) - COMPACT_PREBUILD=true - shift - ;; - *) - echo "Unknown option: $1" - exit 1 - ;; - esac -done - -export FORCE_PREBUILD -export COMPACT_PREBUILD -export -f run_prebuild_if_needed -export -f __build_file_hashes -export -f __check_for_mismatches -export -f __calculate_hash - -run_prebuild_if_needed core -run_prebuild_if_needed core_ui -run_prebuild_if_needed data -run_prebuild_if_needed domain - -if [ -d 'features' ]; then - count=$(nproc 2>/dev/null || sysctl -n hw.ncpu) - find 'features' -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c ' - run_prebuild_if_needed "$0" - ' {} -fi - -run_prebuild_if_needed navigation -run_prebuild_if_needed . diff --git a/files/scripts/fast_prebuild_script_mac.sh b/files/scripts/fast_prebuild_script_mac.sh new file mode 100755 index 0000000..a4d76e5 --- /dev/null +++ b/files/scripts/fast_prebuild_script_mac.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +source functions.sh + +export -f echo_styled +export -f module_flow + +FORCE=false +VERBOSE=false + +export FORCE +export VERBOSE + +while [[ $# -gt 0 ]]; do + case "$1" in + -f|--force) FORCE=true; shift ;; + -v|--verbose) VERBOSE=true; shift ;; + *) echo "Unknown option: $1"; exit 1 ;; + esac +done + +[ ! -f "pubspec.yaml" ] && cd ../ + +( + cd core || exit + module_flow -g "lib" -g "*.yaml" -g "resources" +) + +( + cd core_ui || exit + module_flow -g "lib" -g "*.yaml" +) + +( + cd data || exit + module_flow -g "lib" -g "*.yaml" +) + +( + cd domain || exit + module_flow -g "lib" -g "*.yaml" +) + +( + cd features || exit + count=$(nproc 2>/dev/null || sysctl -n hw.ncpu) + find . -mindepth 1 -maxdepth 1 -type d | xargs -n 1 -P "$count" -I {} bash -c ' + cd "${0}" && + module_flow -g "lib" -g "*.yaml" + ' {} +) + +( + cd navigation || exit + module_flow -g "lib" -g "*.yaml" +) + +( + module_flow -g "lib" -g "*.yaml" +) diff --git a/files/frontend-run.sh b/files/scripts/frontend-run.sh similarity index 100% rename from files/frontend-run.sh rename to files/scripts/frontend-run.sh diff --git a/files/scripts/functions.sh b/files/scripts/functions.sh new file mode 100755 index 0000000..2202f78 --- /dev/null +++ b/files/scripts/functions.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +export COLOR_RED=31 +export COLOR_GREEN=32 +export COLOR_BLUE=36 + +function echo_styled() { + echo -e "\033[1;$2m$1\033[0m" +} + +function module_flow() { + set -eo pipefail + + local PREBUILD_DIR=".prebuild" + local HASH_FILE="hash.prebuildhash" + local PREBUILD_FILE="module_prebuild.sh" + + local globs=() + + function on_error() { + local exit_code=$? + local line_no=$1 + echo_styled "🔴Error while processing $(pwd)" "$COLOR_RED" + [[ -n "${abs_hash:-}" && -f "$abs_hash" ]] && rm -f "$abs_hash" + exit $exit_code + } + + trap 'on_error' ERR + + while [[ "$#" -gt 0 ]]; do + case "$1" in + -g) globs+=("$2"); shift 2 ;; + *) echo "Unknown parameter: $1"; return 1 ;; + esac + done + + if [ ${#globs[@]} -eq 0 ]; then + echo "Error: At least one -g (globs) is required." >&2 + return 1 + fi + + local merged="${globs[@]}" + local hash=$(find $merged -type f -exec sha256sum {} \; | sort | sha256sum | awk '{ print $1 }') + + cd "$PREBUILD_DIR" + + [ ! -f "$HASH_FILE" ] && touch "$HASH_FILE" + + abs_hash="$(realpath "$HASH_FILE")" + + local old_hash=$(<$HASH_FILE) + echo "$hash" > "$HASH_FILE" + + if $FORCE || [ "$hash" != "$old_hash" ]; then + echo_styled "🟢Running $PREBUILD_FILE inside $(pwd)" "$COLOR_GREEN" + + cd ../ + + if $VERBOSE; then + sh "./$PREBUILD_DIR/$PREBUILD_FILE" + else + sh "./$PREBUILD_DIR/$PREBUILD_FILE" > /dev/null + fi + + local new_hash=$(find $merged -type f -exec sha256sum {} \; | sort | sha256sum | awk '{ print $1 }') + cd "$PREBUILD_DIR" + echo "$new_hash" > "$HASH_FILE" + else + echo_styled "🔵Skipping $PREBUILD_FILE inside $(pwd)" "$COLOR_BLUE" + fi + + trap - ERR +} \ No newline at end of file diff --git a/files/scripts/prebuild_script.sh b/files/scripts/prebuild_script.sh new file mode 100755 index 0000000..3c2bb8c --- /dev/null +++ b/files/scripts/prebuild_script.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +source functions.sh + +export -f echo_styled +export -f module_flow + +FORCE=false +VERBOSE=false + +export FORCE +export VERBOSE + +while [[ $# -gt 0 ]]; do + case "$1" in + -f|--force) FORCE=true; shift ;; + -v|--verbose) VERBOSE=true; shift ;; + *) echo "Unknown option: $1"; exit 1 ;; + esac +done + +[ ! -f "pubspec.yaml" ] && cd ../ + +( + cd core || exit + module_flow -g "lib" -g "*.yaml" -g "resources" +) + +( + cd core_ui || exit + module_flow -g "lib" -g "*.yaml" +) + +( + cd data || exit + module_flow -g "lib" -g "*.yaml" +) + +( + cd domain || exit + module_flow -g "lib" -g "*.yaml" +) + +( + cd features || exit + find . -mindepth 1 -maxdepth 1 -type d -exec bash -c 'cd "$0" && module_flow -g "lib" -g "*.yaml"' {} \; +) + +( + cd navigation || exit + module_flow -g "lib" -g "*.yaml" +) + +( + module_flow -g "lib" -g "*.yaml" +) From 6ba950f40e171062f31f68ff8a194127dfb2c982 Mon Sep 17 00:00:00 2001 From: GermanPerelmuter Date: Thu, 17 Apr 2025 16:36:16 +0200 Subject: [PATCH 21/23] Add help option --- files/scripts/fast_prebuild_script_mac.sh | 26 +++++++++++++++++++++++ files/scripts/prebuild_script.sh | 26 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/files/scripts/fast_prebuild_script_mac.sh b/files/scripts/fast_prebuild_script_mac.sh index a4d76e5..f9f35f3 100755 --- a/files/scripts/fast_prebuild_script_mac.sh +++ b/files/scripts/fast_prebuild_script_mac.sh @@ -1,5 +1,31 @@ #!/bin/bash +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + cat < Date: Thu, 17 Apr 2025 16:46:51 +0200 Subject: [PATCH 22/23] Print help in case of an unknown option --- files/scripts/fast_prebuild_script_mac.sh | 13 ++++++++++--- files/scripts/prebuild_script.sh | 15 +++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/files/scripts/fast_prebuild_script_mac.sh b/files/scripts/fast_prebuild_script_mac.sh index f9f35f3..426cda0 100755 --- a/files/scripts/fast_prebuild_script_mac.sh +++ b/files/scripts/fast_prebuild_script_mac.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [[ "$1" == "-h" || "$1" == "--help" ]]; then +function print_usage() { cat < Date: Thu, 17 Apr 2025 16:52:54 +0200 Subject: [PATCH 23/23] Remove unused code --- files/scripts/functions.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/files/scripts/functions.sh b/files/scripts/functions.sh index 2202f78..e081bf2 100755 --- a/files/scripts/functions.sh +++ b/files/scripts/functions.sh @@ -19,7 +19,6 @@ function module_flow() { function on_error() { local exit_code=$? - local line_no=$1 echo_styled "🔴Error while processing $(pwd)" "$COLOR_RED" [[ -n "${abs_hash:-}" && -f "$abs_hash" ]] && rm -f "$abs_hash" exit $exit_code