agent-flutter 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-flutter",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Portable Flutter skill/rule pack initializer for multiple AI IDEs.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -30,6 +30,7 @@ FLUTTER_VERSION="stable"
30
30
  PARENT_DIR="$(pwd)"
31
31
  FORCE=0
32
32
  NON_INTERACTIVE=0
33
+ FVM_BIN=""
33
34
 
34
35
  while [[ $# -gt 0 ]]; do
35
36
  case "$1" in
@@ -126,22 +127,99 @@ normalize_project_name() {
126
127
  printf '%s' "$value"
127
128
  }
128
129
 
129
- ensure_fvm() {
130
- if [[ -d "$HOME/.pub-cache/bin" ]]; then
131
- export PATH="$HOME/.pub-cache/bin:$PATH"
132
- fi
133
- if command -v fvm >/dev/null 2>&1; then
130
+ append_path_once() {
131
+ local target="$1"
132
+ [[ -n "$target" ]] || return
133
+ [[ -d "$target" ]] || return
134
+ case ":$PATH:" in
135
+ *":$target:"*) ;;
136
+ *) export PATH="$PATH:$target" ;;
137
+ esac
138
+ }
139
+
140
+ ensure_dart() {
141
+ if command -v dart >/dev/null 2>&1; then
134
142
  return
135
143
  fi
144
+
145
+ if command -v flutter >/dev/null 2>&1; then
146
+ local flutter_cmd=""
147
+ local flutter_bin=""
148
+ local flutter_dart_bin=""
149
+ flutter_cmd="$(command -v flutter)"
150
+ flutter_bin="$(cd "$(dirname "$flutter_cmd")" && pwd)"
151
+ flutter_dart_bin="$flutter_bin/cache/dart-sdk/bin"
152
+ append_path_once "$flutter_dart_bin"
153
+ fi
154
+
155
+ append_path_once "/opt/homebrew/opt/dart/libexec/bin"
156
+ append_path_once "/usr/local/opt/dart/libexec/bin"
157
+
136
158
  if ! command -v dart >/dev/null 2>&1; then
137
- echo "Error: fvm not found and dart not available to install fvm." >&2
159
+ cat >&2 <<'EOF'
160
+ Error: dart command not found.
161
+ Please install Dart (or Flutter) and ensure dart is available in PATH.
162
+ Example (macOS with Homebrew):
163
+ brew tap dart-lang/dart
164
+ brew install dart
165
+ EOF
138
166
  exit 1
139
167
  fi
168
+ }
169
+
170
+ discover_working_fvm() {
171
+ local candidates=()
172
+ local candidate=""
173
+ local pub_cache_fvm="$HOME/.pub-cache/bin/fvm"
174
+
175
+ if command -v fvm >/dev/null 2>&1; then
176
+ candidates+=("$(command -v fvm)")
177
+ fi
178
+
179
+ if command -v which >/dev/null 2>&1; then
180
+ while IFS= read -r candidate; do
181
+ [[ -n "$candidate" ]] || continue
182
+ candidates+=("$candidate")
183
+ done < <(which -a fvm 2>/dev/null | awk '!seen[$0]++')
184
+ fi
185
+
186
+ if [[ -x "$pub_cache_fvm" ]]; then
187
+ candidates+=("$pub_cache_fvm")
188
+ fi
189
+
190
+ for candidate in "${candidates[@]}"; do
191
+ if "$candidate" --version >/dev/null 2>&1; then
192
+ FVM_BIN="$candidate"
193
+ return 0
194
+ fi
195
+ done
196
+
197
+ return 1
198
+ }
199
+
200
+ run_fvm() {
201
+ "$FVM_BIN" "$@"
202
+ }
203
+
204
+ ensure_fvm() {
205
+ append_path_once "$HOME/.pub-cache/bin"
206
+
207
+ if discover_working_fvm; then
208
+ return
209
+ fi
210
+
211
+ ensure_dart
212
+
213
+ if discover_working_fvm; then
214
+ return
215
+ fi
216
+
140
217
  echo "Installing FVM..."
141
218
  dart pub global activate fvm >/dev/null
142
- export PATH="$PATH:$HOME/.pub-cache/bin"
143
- if ! command -v fvm >/dev/null 2>&1; then
144
- echo "Error: fvm installation failed." >&2
219
+ append_path_once "$HOME/.pub-cache/bin"
220
+
221
+ if ! discover_working_fvm; then
222
+ echo "Error: FVM installation failed or fvm is not runnable." >&2
145
223
  exit 1
146
224
  fi
147
225
  }
@@ -188,9 +266,9 @@ ensure_fvm
188
266
  mkdir -p "$PROJECT_DIR"
189
267
  cd "$PROJECT_DIR"
190
268
 
191
- fvm use "$FLUTTER_VERSION" --force
269
+ run_fvm use "$FLUTTER_VERSION" --force
192
270
 
193
- create_args=(fvm flutter create . --org "$ORG_ID" --project-name "$APP_PACKAGE_NAME")
271
+ create_args=(run_fvm flutter create . --org "$ORG_ID" --project-name "$APP_PACKAGE_NAME")
194
272
  if [[ "$FORCE" -eq 1 ]]; then
195
273
  create_args+=(--overwrite)
196
274
  fi
@@ -209,8 +287,8 @@ cat >.vscode/settings.json <<'JSON'
209
287
  }
210
288
  JSON
211
289
 
212
- fvm flutter pub add get flutter_bloc equatable dio retrofit json_annotation flutter_dotenv flutter_svg intl
213
- fvm flutter pub add --dev build_runner retrofit_generator json_serializable
290
+ run_fvm flutter pub add get flutter_bloc equatable dio retrofit json_annotation flutter_dotenv flutter_svg intl
291
+ run_fvm flutter pub add --dev build_runner retrofit_generator json_serializable
214
292
 
215
293
  mkdir -p \
216
294
  lib/src/api \
@@ -497,8 +575,8 @@ ensure_line_in_file .gitignore ".env"
497
575
  ensure_line_in_file .gitignore ".env.staging"
498
576
  ensure_line_in_file .gitignore ".env.prod"
499
577
 
500
- if command -v fvm >/dev/null 2>&1; then
501
- fvm dart format lib >/dev/null || true
578
+ if [[ -n "$FVM_BIN" ]]; then
579
+ run_fvm dart format lib >/dev/null || true
502
580
  fi
503
581
 
504
582
  echo ""