Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c34c619
Modular prebuild script
GermanPerelmuter Apr 14, 2025
9f3b6bb
Remove unused files from VCS, move functions.sh to files dir
GermanPerelmuter Apr 14, 2025
49b8c45
File location adjustments
GermanPerelmuter Apr 14, 2025
fa12a60
Adjusted core module prebuild script
GermanPerelmuter Apr 14, 2025
f2bf79d
Quickfix
GermanPerelmuter Apr 14, 2025
f7bc42f
Filenames cleanup, logic adjustments
GermanPerelmuter Apr 14, 2025
bca3885
Prettify output
GermanPerelmuter Apr 14, 2025
590c432
Adjusted script names
GermanPerelmuter Apr 14, 2025
6782aa9
Adjust script logic, improve output
GermanPerelmuter Apr 14, 2025
47d9e67
Adjust interpreter in use, minor fixes
GermanPerelmuter Apr 14, 2025
b5f7759
Script fixes
GermanPerelmuter Apr 14, 2025
c711521
Cosmetic adjustment
GermanPerelmuter Apr 14, 2025
0d24d69
Optimise function
GermanPerelmuter Apr 14, 2025
43c0245
Optimise script
GermanPerelmuter Apr 14, 2025
993b16b
Add --force flag to prebuild scripts
GermanPerelmuter Apr 15, 2025
056cfed
Move module_prebuild.sh and hash files to separate directory, add com…
GermanPerelmuter Apr 16, 2025
47f2c5a
Fix incorrect feature template
GermanPerelmuter Apr 16, 2025
9a4740c
Implement error handling in prebuild scripts
GermanPerelmuter Apr 16, 2025
17df653
Add temporarily fix for json_serializable
GermanPerelmuter Apr 16, 2025
e396c23
Move scripts to a separate folder, refactor modular prebuild approach
GermanPerelmuter Apr 17, 2025
6ba950f
Add help option
GermanPerelmuter Apr 17, 2025
66fd1f6
Print help in case of an unknown option
GermanPerelmuter Apr 17, 2025
f67048b
Remove unused code
GermanPerelmuter Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/.prebuild/module_prebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

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
4 changes: 4 additions & 0 deletions core_ui/.prebuild/module_prebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

flutter clean
flutter pub get
5 changes: 5 additions & 0 deletions data/.prebuild/module_prebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

flutter clean
flutter pub get
dart run build_runner build --delete-conflicting-outputs
4 changes: 4 additions & 0 deletions data/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions domain/.prebuild/module_prebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

flutter clean
flutter pub get
5 changes: 5 additions & 0 deletions feature/.prebuild/module_prebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

flutter clean
flutter pub get
dart run build_runner build --delete-conflicting-outputs
1 change: 1 addition & 0 deletions files/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ android/app/build
**/*.graphql.dart
**/*.gr.dart
*.env
**/*.prebuildhash

.vscode
4 changes: 4 additions & 0 deletions files/.prebuild/module_prebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

flutter clean
flutter pub get
52 changes: 0 additions & 52 deletions files/fast_prebuild_script_mac.sh

This file was deleted.

36 changes: 0 additions & 36 deletions files/prebuild_script.sh

This file was deleted.

93 changes: 93 additions & 0 deletions files/scripts/fast_prebuild_script_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

function print_usage() {
cat <<EOF
Usage: $(basename "$0") [options]

Options:
-f, --force Force run the module_prebuild.sh regardless of file changes.
-v, --verbose Enable verbose output (prints prebuild script output).
-h, --help Show this help message and exit.

Description:
This script walks through the project and runs a prebuild script (./.prebuild/module_prebuild.sh)
inside each module, only if the contents have changed (based on file hash comparison) — unless forced via -f.

Modules processed:
- core
- core_ui
- data
- domain
- features (each subdirectory)
- navigation
- root project directory
EOF
}

if [[ "$1" == "-h" || "$1" == "--help" ]]; then
print_usage
exit 0
fi

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"
print_usage
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"
)
2 changes: 1 addition & 1 deletion files/frontend-run.sh → files/scripts/frontend-run.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
docker compose up -d flutter-web-prod
72 changes: 72 additions & 0 deletions files/scripts/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/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=$?
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
}
Loading