1
+ #! /bin/bash
2
+ set -e
3
+
4
+ # Function to use flutter or fvm flutter
5
+ flutter_cmd () {
6
+ if command -v fvm & > /dev/null; then
7
+ fvm flutter " $@ "
8
+ else
9
+ flutter " $@ "
10
+ fi
11
+ }
12
+
13
+ echo " [1/6] Checking for Flutter..."
14
+ if ! command -v flutter & > /dev/null; then
15
+ echo " [ERROR] Flutter is not installed. Please install it before continuing: https://docs.flutter.dev/get-started/install"
16
+ exit 1
17
+ fi
18
+
19
+ echo " [2/6] Checking for FVM..."
20
+ if command -v fvm & > /dev/null; then
21
+ echo " FVM is installed. Ensuring project uses FVM-managed Flutter..."
22
+ if [ -f " .fvm/fvm_config.json" ]; then
23
+ FLUTTER_VERSION=$( grep -o ' "flutterSdkVersion": *"[^"]*"' .fvm/fvm_config.json | cut -d ' "' -f4)
24
+ echo " Project FVM Flutter version: $FLUTTER_VERSION "
25
+ fvm install " $FLUTTER_VERSION "
26
+ fvm use " $FLUTTER_VERSION "
27
+ echo " Using FVM Flutter version: $( fvm flutter --version | head -n 1) "
28
+ else
29
+ echo " [Warning] .fvm/fvm_config.json not found. Run 'fvm install stable' to initialize."
30
+ fi
31
+ else
32
+ echo " [Warning] FVM is not installed. Consider installing it for version management: https://fvm.app/"
33
+ fi
34
+
35
+ echo " [3/6] Checking for Node.js and npm..."
36
+ if ! command -v node & > /dev/null || ! command -v npm & > /dev/null; then
37
+ echo " [ERROR] Node.js and npm are required for JS tooling. Please install Node.js: https://nodejs.org/"
38
+ exit 1
39
+ fi
40
+
41
+ echo " [4/6] Installing Flutter/Dart dependencies..."
42
+ flutter_cmd pub get
43
+
44
+ echo " [5/6] Installing Node.js dependencies (if package.json exists)..."
45
+ if [ -f " package.json" ]; then
46
+ npm install
47
+ if grep -q ' "husky"' package.json; then
48
+ echo " Initializing Husky..."
49
+ npm run prepare
50
+ fi
51
+ fi
52
+
53
+ echo " [6/6] Ensuring .fvm/ is in .gitignore..."
54
+ if [ -f .gitignore ]; then
55
+ if ! grep -q ' ^.fvm/$' .gitignore; then
56
+ echo " .fvm/" >> .gitignore
57
+ echo " Added .fvm/ to .gitignore."
58
+ fi
59
+ fi
60
+
61
+ echo " \nSetup completed successfully!"
62
+ echo " ----------------------------------------"
63
+ echo " To run tests:"
64
+ echo " fvm flutter test # (or 'flutter test' if not using FVM)"
65
+ echo " To use Flutter, prefer:"
66
+ echo " fvm flutter <command>"
67
+ echo " ----------------------------------------"
68
+ echo " If using VSCode, restart your terminal to ensure FVM is picked up."
0 commit comments