-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·370 lines (312 loc) · 12.1 KB
/
install.sh
File metadata and controls
executable file
·370 lines (312 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/bin/bash
# Flutter Skill One-Click Installation Script
# Supports macOS and Linux
set -e
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
printf '%b\n' "${BLUE}Flutter Skill One-Click Installation${NC}"
echo ""
# Detect operating system
OS="$(uname -s)"
case "${OS}" in
Linux*) MACHINE=Linux;;
Darwin*) MACHINE=Mac;;
*) MACHINE="UNKNOWN:${OS}"
esac
if [ "$MACHINE" = "UNKNOWN:${OS}" ]; then
printf '%b\n' "${RED}[X] Unsupported operating system: ${OS}${NC}"
exit 1
fi
# ========== Helper Functions ==========
# Install tool priority rules directly (no dependency on CLI)
install_tool_priority_rules() {
local PROMPTS_DIR="$HOME/.claude/prompts"
local TARGET_FILE="$PROMPTS_DIR/flutter-tool-priority.md"
if [ -f "$TARGET_FILE" ]; then
printf '%b\n' " ${GREEN}[OK] Tool priority rules already installed${NC}"
return 0
fi
mkdir -p "$PROMPTS_DIR"
# Try downloading from GitHub
local URL="https://raw.githubusercontent.com/ai-dashboad/flutter-skill/main/docs/prompts/tool-priority.md"
if command -v curl &> /dev/null; then
if curl -fsSL "$URL" -o "$TARGET_FILE" 2>/dev/null; then
printf '%b\n' " ${GREEN}[OK] Tool priority rules installed${NC}"
return 0
fi
elif command -v wget &> /dev/null; then
if wget -qO "$TARGET_FILE" "$URL" 2>/dev/null; then
printf '%b\n' " ${GREEN}[OK] Tool priority rules installed${NC}"
return 0
fi
fi
# Fallback: try using the CLI if available
if command -v flutter-skill &> /dev/null; then
flutter-skill setup --silent 2>/dev/null && printf '%b\n' " ${GREEN}[OK] Tool priority rules installed${NC}" && return 0
elif command -v flutter-skill &> /dev/null; then
flutter-skill setup --silent 2>/dev/null && printf '%b\n' " ${GREEN}[OK] Tool priority rules installed${NC}" && return 0
fi
printf '%b\n' " ${YELLOW}[!] Could not install tool priority rules automatically${NC}"
echo " Run manually: flutter-skill setup"
return 0
}
# Add flutter-skill MCP entry to a JSON settings file using python3
# Usage: add_mcp_to_json <file_path> <command_name>
add_mcp_to_json() {
local FILE_PATH="$1"
local CMD_NAME="$2"
python3 -c "
import json, sys, os
file_path = sys.argv[1]
cmd = sys.argv[2]
entry = {'command': cmd, 'args': ['server']}
if os.path.exists(file_path):
with open(file_path) as f:
try:
data = json.load(f)
except:
data = {}
else:
os.makedirs(os.path.dirname(file_path), exist_ok=True)
data = {}
if 'mcpServers' not in data:
data['mcpServers'] = {}
data['mcpServers']['flutter-skill'] = entry
with open(file_path, 'w') as f:
json.dump(data, f, indent=2)
f.write('\n')
" "$FILE_PATH" "$CMD_NAME" 2>/dev/null
}
# Configure IDE MCP settings (auto-write)
configure_ide() {
local CMD_NAME="$1" # flutter-skill or flutter-skill
echo ""
printf '%b\n' "${BLUE}Configuring IDE integration...${NC}"
# Claude Code
local CLAUDE_DIR="$HOME/.claude"
local CLAUDE_SETTINGS="$CLAUDE_DIR/settings.json"
if [ -d "$CLAUDE_DIR" ]; then
if [ -f "$CLAUDE_SETTINGS" ] && grep -q "flutter-skill\|flutter_skill" "$CLAUDE_SETTINGS" 2>/dev/null; then
printf '%b\n' " ${GREEN}[OK] Claude Code: already configured${NC}"
else
if command -v python3 &> /dev/null; then
add_mcp_to_json "$CLAUDE_SETTINGS" "$CMD_NAME"
printf '%b\n' " ${GREEN}[OK] Claude Code: configured${NC}"
else
printf '%b\n' " ${YELLOW}[!] Claude Code: python3 not found, manual config needed${NC}"
echo " Add to $CLAUDE_SETTINGS:"
echo " {\"mcpServers\":{\"flutter-skill\":{\"command\":\"$CMD_NAME\",\"args\":[\"server\"]}}}"
fi
fi
fi
# Cursor
local CURSOR_DIR="$HOME/.cursor"
local CURSOR_CONFIG="$CURSOR_DIR/mcp.json"
if [ -d "$CURSOR_DIR" ]; then
if [ -f "$CURSOR_CONFIG" ] && grep -q "flutter-skill\|flutter_skill" "$CURSOR_CONFIG" 2>/dev/null; then
printf '%b\n' " ${GREEN}[OK] Cursor: already configured${NC}"
else
if command -v python3 &> /dev/null; then
add_mcp_to_json "$CURSOR_CONFIG" "$CMD_NAME"
printf '%b\n' " ${GREEN}[OK] Cursor: configured${NC}"
else
printf '%b\n' " ${YELLOW}[!] Cursor: python3 not found, manual config needed${NC}"
echo " Add to $CURSOR_CONFIG:"
echo " {\"mcpServers\":{\"flutter-skill\":{\"command\":\"$CMD_NAME\",\"args\":[\"server\"]}}}"
fi
fi
fi
}
# Add to PATH for detected shells (zsh, bash, fish)
add_to_path() {
local BIN_DIR="$1"
local CONFIGS_UPDATED=0
# zsh
if [ -f "$HOME/.zshrc" ]; then
if ! grep -q 'export PATH="$HOME/bin:$PATH"' "$HOME/.zshrc" 2>/dev/null; then
echo "" >> "$HOME/.zshrc"
echo '# Flutter Skill' >> "$HOME/.zshrc"
echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.zshrc"
printf '%b\n' " ${GREEN}[OK] Added to PATH: ~/.zshrc${NC}"
CONFIGS_UPDATED=$((CONFIGS_UPDATED + 1))
fi
fi
# bash
if [ -f "$HOME/.bashrc" ]; then
if ! grep -q 'export PATH="$HOME/bin:$PATH"' "$HOME/.bashrc" 2>/dev/null; then
echo "" >> "$HOME/.bashrc"
echo '# Flutter Skill' >> "$HOME/.bashrc"
echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc"
printf '%b\n' " ${GREEN}[OK] Added to PATH: ~/.bashrc${NC}"
CONFIGS_UPDATED=$((CONFIGS_UPDATED + 1))
fi
elif [ -f "$HOME/.bash_profile" ]; then
if ! grep -q 'export PATH="$HOME/bin:$PATH"' "$HOME/.bash_profile" 2>/dev/null; then
echo "" >> "$HOME/.bash_profile"
echo '# Flutter Skill' >> "$HOME/.bash_profile"
echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bash_profile"
printf '%b\n' " ${GREEN}[OK] Added to PATH: ~/.bash_profile${NC}"
CONFIGS_UPDATED=$((CONFIGS_UPDATED + 1))
fi
fi
# fish
if [ -d "$HOME/.config/fish" ]; then
local FISH_CONFIG="$HOME/.config/fish/config.fish"
if [ ! -f "$FISH_CONFIG" ] || ! grep -q 'flutter-skill\|flutter_skill' "$FISH_CONFIG" 2>/dev/null; then
mkdir -p "$HOME/.config/fish"
echo "" >> "$FISH_CONFIG"
echo '# Flutter Skill' >> "$FISH_CONFIG"
echo "fish_add_path $BIN_DIR" >> "$FISH_CONFIG"
printf '%b\n' " ${GREEN}[OK] Added to PATH: ~/.config/fish/config.fish${NC}"
CONFIGS_UPDATED=$((CONFIGS_UPDATED + 1))
fi
fi
if [ $CONFIGS_UPDATED -eq 0 ]; then
printf '%b\n' " ${YELLOW}[!] Could not detect shell config file${NC}"
echo " Add this to your shell config:"
echo " export PATH=\"$BIN_DIR:\$PATH\""
fi
}
# Verify installation works
verify_install() {
local CMD_NAME="$1"
echo ""
printf '%b\n' "${BLUE}Verifying installation...${NC}"
if command -v "$CMD_NAME" &> /dev/null; then
local VERSION_OUTPUT
VERSION_OUTPUT=$("$CMD_NAME" --version 2>/dev/null) || true
# Only show version if it looks like a version number
if echo "$VERSION_OUTPUT" | grep -qE '^[0-9]+\.[0-9]+'; then
printf '%b\n' " ${GREEN}[OK] $CMD_NAME v${VERSION_OUTPUT}${NC}"
else
printf '%b\n' " ${GREEN}[OK] $CMD_NAME installed${NC}"
fi
return 0
else
printf '%b\n' " ${YELLOW}[!] $CMD_NAME not found in PATH${NC}"
echo " You may need to restart your terminal"
return 1
fi
}
# Show post-install summary
show_summary() {
local CMD_NAME="$1"
echo ""
printf '%b\n' "${GREEN}============================================${NC}"
printf '%b\n' "${GREEN} Installation complete!${NC}"
printf '%b\n' "${GREEN}============================================${NC}"
echo ""
echo " Quick Start:"
echo " 1. Launch your Flutter app:"
printf '%b\n' " ${CYAN}$CMD_NAME launch /path/to/flutter/app${NC}"
echo ""
echo " 2. Or configure as MCP server in your IDE:"
printf '%b\n' " ${CYAN}{ \"command\": \"$CMD_NAME\", \"args\": [\"server\"] }${NC}"
echo ""
echo " 3. Check environment health:"
printf '%b\n' " ${CYAN}$CMD_NAME doctor${NC}"
echo ""
echo " Docs: https://pub.dev/packages/flutter_skill"
echo ""
}
# ========== Installation Methods ==========
printf '%b\n' "${YELLOW}Detecting best installation method...${NC}"
echo ""
# Method 1: npm (Recommended - pre-compiled binary, fastest startup)
if command -v npm &> /dev/null; then
printf '%b\n' "${GREEN}[OK] npm detected, installing via npm (recommended)${NC}"
echo ""
if command -v flutter-skill &> /dev/null || command -v flutter-skill &> /dev/null; then
printf '%b\n' "${YELLOW}Updating flutter-skill to latest version...${NC}"
fi
echo "Running: npm install -g flutter-skill"
npm install -g flutter-skill
CMD="flutter-skill"
if command -v flutter-skill &> /dev/null; then
CMD="flutter-skill"
fi
verify_install "$CMD"
echo ""
printf '%b\n' "${BLUE}Setting up tool priority rules...${NC}"
install_tool_priority_rules
configure_ide "$CMD"
show_summary "$CMD"
exit 0
fi
# Method 2: Homebrew (macOS/Linux)
if [ "$MACHINE" = "Mac" ] && command -v brew &> /dev/null; then
printf '%b\n' "${GREEN}[OK] Homebrew detected, installing via brew${NC}"
echo ""
echo "Running: brew tap ai-dashboad/flutter-skill && brew install flutter-skill"
brew tap ai-dashboad/flutter-skill
brew install flutter-skill
verify_install "flutter-skill"
echo ""
printf '%b\n' "${BLUE}Setting up tool priority rules...${NC}"
install_tool_priority_rules
configure_ide "flutter-skill"
show_summary "flutter-skill"
exit 0
fi
# Method 3: Install from source (requires Dart/Flutter)
if command -v dart &> /dev/null || command -v flutter &> /dev/null; then
printf '%b\n' "${YELLOW}[!] npm or Homebrew not detected${NC}"
printf '%b\n' "${YELLOW}Installing from source using Dart (requires Flutter SDK)${NC}"
echo ""
if ! command -v flutter &> /dev/null; then
printf '%b\n' "${RED}[X] Error: Flutter SDK not found${NC}"
echo ""
echo "Please install Flutter first: https://flutter.dev/docs/get-started/install"
echo ""
echo "Or use one of the following methods:"
echo " npm install -g flutter-skill (recommended)"
echo " brew install flutter-skill (macOS)"
exit 1
fi
INSTALL_DIR="$HOME/.flutter-skill-src"
if [ ! -d "$INSTALL_DIR" ]; then
echo "Cloning repository to $INSTALL_DIR ..."
git clone https://github.com/ai-dashboad/flutter-skill.git "$INSTALL_DIR"
else
echo "Updating source code..."
cd "$INSTALL_DIR"
git pull origin main
fi
cd "$INSTALL_DIR"
echo "Installing dependencies..."
flutter pub get
echo "Creating executable..."
mkdir -p "$HOME/bin"
cat > "$HOME/bin/flutter-skill" << 'WRAPPER_EOF'
#!/bin/bash
FLUTTER_SKILL_DIR="$HOME/.flutter-skill-src"
cd "$FLUTTER_SKILL_DIR"
dart run bin/flutter_skill.dart "$@"
WRAPPER_EOF
chmod +x "$HOME/bin/flutter-skill"
echo ""
printf '%b\n' "${BLUE}Configuring PATH...${NC}"
add_to_path "$HOME/bin"
verify_install "flutter-skill" || printf '%b\n' " ${YELLOW}Run: source ~/.zshrc (or restart terminal)${NC}"
echo ""
printf '%b\n' "${BLUE}Setting up tool priority rules...${NC}"
install_tool_priority_rules
configure_ide "flutter-skill"
show_summary "flutter-skill"
exit 0
fi
# No installation method found
printf '%b\n' "${RED}[X] Error: No available installation method found${NC}"
echo ""
echo "Please install one of the following tools:"
echo " 1. npm (recommended) - https://nodejs.org/"
echo " 2. Homebrew (macOS) - https://brew.sh/"
echo " 3. Flutter SDK - https://flutter.dev/"
echo ""
echo "Then run this script again"
exit 1