Skip to content

Commit

Permalink
af: Add Git hook for future iOS/macOS file changes [SDK-4698] (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Nov 21, 2023
1 parent b2370e5 commit 2773d30
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
staged_files=($(git diff --staged --name-only --diff-filter=ACDRT -- auth0_flutter/darwin))

# Only proceed if there are staged files from the 'darwin' directory
if [ ${#staged_files[@]} -eq 0 ]; then
exit 0
fi

scripts/generate-symlinks.sh
9 changes: 8 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

As a Flutter plugin can not be built as a standalone application, the only way to verify the compilation is to build the example application using `flutter build apk` or `flutter build ios` from inside `/auth0_flutter/example`.

## Configuring git hooks

The `.githooks` folder contains git hooks specific to this repository. To make sure these get called, after cloning run the following **from the repository root**:

```sh
git config core.hooksPath .githooks
```

## Running package tests

Run the unit tests for both packages using `flutter test` in **/auth0_flutter** and **/auth0_flutter_platform_interface** respectively.
Expand Down Expand Up @@ -30,4 +38,3 @@ With the environment variables defined, we can execute the integration tests usi
```
./gradlew connectedDebugAndroidTest
```

43 changes: 43 additions & 0 deletions scripts/generate-symlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

# This script generates symlinks for every file inside the 'darwin' directory
# of the auth0_flutter package, to the 'ios' and 'macos' directories.
# It's meant to be run from the repository root.

set -euo pipefail

repo_path=$(git rev-parse --show-toplevel)

if [ "$repo_path" != $PWD ]; then
echo 'This script must be run from the repository root'
exit 1
fi

base_dir='auth0_flutter'
darwin_dir='auth0_flutter/darwin'
files=($(find "$darwin_dir" -type f -print))
platforms=('ios' 'macos')

for platform in "${platforms[@]}"; do
rm -rf "$base_dir/$platform"
done

for file in "${files[@]}"; do
for platform in "${platforms[@]}"; do
target_file=$(echo "$file" | sed "s/darwin/$platform/")
target_dir=$(dirname "$target_file")

mkdir -p "$target_dir"

case "$file" in
# If it's a .gitignore file, copy it
(*'.gitignore') cp -v "$file" "$target_dir" ;;
# Else symlink it
(*) ln -sv "$repo_path/$file" "$target_file" ;;
esac
done
done

for platform in "${platforms[@]}"; do
git add "$base_dir/$platform"
done

0 comments on commit 2773d30

Please sign in to comment.