Skip to content

Commit b4c99e2

Browse files
authored
Merge branch 'main' into Hot-Fix-For-Ask
2 parents 25343e4 + c10b524 commit b4c99e2

1 file changed

Lines changed: 143 additions & 52 deletions

File tree

β€Žfunctions/cauldron_update.fishβ€Ž

Lines changed: 143 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -93,82 +93,173 @@ function cauldron_update --description "Update Cauldron to the latest version"
9393

9494
echo "βœ“ Code updated successfully"
9595

96-
# Copy updated functions FIRST (before running migrations)
97-
echo "β†’ Updating functions..."
96+
# Show all pending installation tasks
97+
echo ""
98+
echo "πŸ“¦ Installation Tasks:"
99+
echo " β€’ Updating functions and data files"
100+
echo " β€’ Running database migrations"
101+
echo " β€’ Initializing personality system"
102+
if test -f "$CAULDRON_PATH/package.json"
103+
echo " β€’ Updating Node.js dependencies"
104+
end
105+
echo ""
106+
107+
# Create temp directory for parallel job status
108+
set -l temp_dir (mktemp -d)
98109
set -l functions_dir "$HOME/.config/cauldron/functions"
99110
mkdir -p "$functions_dir"
100111

101-
set -l updated_count 0
112+
# Job 1: Core update chain (functions β†’ data β†’ migrations β†’ personality)
113+
# This must be sequential due to dependencies
114+
set -l core_status "$temp_dir/core_status"
115+
set -l core_log "$temp_dir/core_log"
102116

103-
# Copy from functions/ directory
104-
for func_file in "$CAULDRON_PATH"/functions/*.fish
105-
if test -f "$func_file"
106-
cp -f "$func_file" "$functions_dir/" 2>/dev/null
107-
set updated_count (math $updated_count + 1)
117+
fish -c "
118+
set -l updated_count 0
119+
120+
# Copy functions
121+
for func_file in '$CAULDRON_PATH'/functions/*.fish
122+
if test -f \$func_file
123+
cp -f \$func_file '$functions_dir/' 2>/dev/null
124+
set updated_count (math \$updated_count + 1)
125+
end
108126
end
109-
end
110127
111-
# Copy from familiar/ directory if it exists
112-
if test -d "$CAULDRON_PATH/familiar"
113-
for func_file in "$CAULDRON_PATH"/familiar/*.fish
114-
if test -f "$func_file"
115-
cp -f "$func_file" "$functions_dir/" 2>/dev/null
116-
set updated_count (math $updated_count + 1)
128+
# Copy from familiar/ directory if it exists
129+
if test -d '$CAULDRON_PATH/familiar'
130+
for func_file in '$CAULDRON_PATH'/familiar/*.fish
131+
if test -f \$func_file
132+
cp -f \$func_file '$functions_dir/' 2>/dev/null
133+
set updated_count (math \$updated_count + 1)
134+
end
135+
end
136+
end
137+
138+
echo \"functions:\$updated_count\" >> '$core_log'
139+
140+
# Copy data files
141+
set -l data_dir (dirname '$CAULDRON_DATABASE')
142+
cp -f '$CAULDRON_PATH/data/palettes.json' \$data_dir/palettes.json 2>/dev/null
143+
cp -f '$CAULDRON_PATH/data/spinners.json' \$data_dir/spinners.json 2>/dev/null
144+
echo 'data:ok' >> '$core_log'
145+
146+
# Run migrations
147+
if test -f '$functions_dir/__run_migrations.fish'
148+
source '$functions_dir/__run_migrations.fish'
149+
end
150+
151+
if __run_migrations 2>&1 | tail -n 20 >> '$core_log'
152+
echo 'migrations:ok' >> '$core_log'
153+
154+
# Initialize personality system
155+
if test -f '$functions_dir/__init_personality_system.fish'
156+
source '$functions_dir/__init_personality_system.fish'
157+
end
158+
if test -f '$functions_dir/__ensure_builtin_personalities.fish'
159+
source '$functions_dir/__ensure_builtin_personalities.fish'
160+
end
161+
if functions -q __init_personality_system
162+
__init_personality_system 2>/dev/null
163+
echo 'personality:ok' >> '$core_log'
164+
else
165+
echo 'personality:skip' >> '$core_log'
117166
end
167+
else
168+
echo 'migrations:failed' >> '$core_log'
118169
end
170+
171+
echo 'done' > '$core_status'
172+
" &
173+
set -l core_pid $last_pid
174+
175+
# Job 2: Node.js dependencies (can run in parallel with core updates)
176+
set -l node_status "$temp_dir/node_status"
177+
set -l node_log "$temp_dir/node_log"
178+
set -l has_nodejs 0
179+
180+
if test -f "$CAULDRON_PATH/package.json"
181+
set has_nodejs 1
182+
fish -c "
183+
if command -q pnpm
184+
cd '$CAULDRON_PATH' && pnpm install >> '$node_log' 2>&1
185+
echo 'pnpm:ok' >> '$node_log'
186+
else if command -q npm
187+
cd '$CAULDRON_PATH' && npm install >> '$node_log' 2>&1
188+
echo 'npm:ok' >> '$node_log'
189+
else
190+
echo 'none:skip' >> '$node_log'
191+
end
192+
echo 'done' > '$node_status'
193+
" &
194+
set -l node_pid $last_pid
119195
end
120196

121-
echo "βœ“ Updated $updated_count functions"
197+
# Wait for jobs to complete with status updates
198+
set -l core_done 0
199+
set -l node_done 0
200+
set -l dots 0
122201

123-
# Copy updated data files
124-
echo "β†’ Updating data files..."
125-
set -l data_dir (dirname "$CAULDRON_DATABASE")
126-
cp -f "$CAULDRON_PATH/data/palettes.json" "$data_dir/palettes.json" 2>/dev/null
127-
cp -f "$CAULDRON_PATH/data/spinners.json" "$data_dir/spinners.json" 2>/dev/null
202+
echo "⏳ Installing in parallel..."
128203

129-
# NOW run migrations with the updated functions
130-
echo ""
131-
echo "β†’ Running database migrations..."
204+
while test $core_done -eq 0 -o \( $has_nodejs -eq 1 -a $node_done -eq 0 \)
205+
# Check core job
206+
if test $core_done -eq 0 -a -f "$core_status"
207+
set core_done 1
208+
echo " βœ“ Core updates completed"
209+
end
210+
211+
# Check node job
212+
if test $has_nodejs -eq 1 -a $node_done -eq 0 -a -f "$node_status"
213+
set node_done 1
214+
echo " βœ“ Node.js dependencies completed"
215+
end
132216

133-
# Reload the migration function from the updated location
134-
if test -f "$functions_dir/__run_migrations.fish"
135-
source "$functions_dir/__run_migrations.fish"
217+
# Still waiting, show progress
218+
if test $core_done -eq 0 -o \( $has_nodejs -eq 1 -a $node_done -eq 0 \)
219+
sleep 0.5
220+
end
136221
end
137222

138-
if not __run_migrations
139-
echo "Warning: Migrations failed"
140-
echo "Your database has been backed up"
141-
echo "You may need to run 'cauldron_repair' to fix issues"
142-
else
143-
echo "βœ“ Migrations completed"
223+
echo ""
224+
echo "πŸ“‹ Installation Summary:"
225+
226+
# Parse and display core results
227+
if test -f "$core_log"
228+
set -l func_count (grep '^functions:' "$core_log" | cut -d: -f2)
229+
if test -n "$func_count"
230+
echo " βœ“ Updated $func_count functions"
231+
end
144232

145-
# Initialize personality system to ensure all personalities exist
146-
if test -f "$functions_dir/__init_personality_system.fish"
147-
source "$functions_dir/__init_personality_system.fish"
233+
if grep -q '^data:ok' "$core_log"
234+
echo " βœ“ Data files updated"
148235
end
149-
if test -f "$functions_dir/__ensure_builtin_personalities.fish"
150-
source "$functions_dir/__ensure_builtin_personalities.fish"
236+
237+
if grep -q '^migrations:ok' "$core_log"
238+
echo " βœ“ Database migrations completed"
239+
else if grep -q '^migrations:failed' "$core_log"
240+
echo " ⚠ Migrations failed - database backed up"
241+
echo " You may need to run 'cauldron_repair' to fix issues"
151242
end
152-
if functions -q __init_personality_system
153-
__init_personality_system 2>/dev/null || true
154-
echo "βœ“ Personality system initialized"
243+
244+
if grep -q '^personality:ok' "$core_log"
245+
echo " βœ“ Personality system initialized"
155246
end
156247
end
157248

158-
# Update Node.js dependencies if needed
159-
if test -f "$CAULDRON_PATH/package.json"
160-
echo "β†’ Updating Node.js dependencies..."
161-
if command -q pnpm
162-
# Run in subshell to avoid changing current directory
163-
fish -c "cd '$CAULDRON_PATH'; pnpm install" >/dev/null 2>&1; or true
164-
echo "βœ“ Node dependencies updated"
165-
else if command -q npm
166-
# Run in subshell to avoid changing current directory
167-
fish -c "cd '$CAULDRON_PATH'; npm install" >/dev/null 2>&1; or true
168-
echo "βœ“ Node dependencies updated"
249+
# Parse and display node results
250+
if test $has_nodejs -eq 1 -a -f "$node_log"
251+
if grep -q 'pnpm:ok' "$node_log"
252+
echo " βœ“ Node dependencies updated (pnpm)"
253+
else if grep -q 'npm:ok' "$node_log"
254+
echo " βœ“ Node dependencies updated (npm)"
255+
else if grep -q 'none:skip' "$node_log"
256+
echo " ⚠ No package manager found (skipped Node.js dependencies)"
169257
end
170258
end
171259

260+
# Cleanup temp files
261+
rm -rf "$temp_dir" 2>/dev/null
262+
172263
# Show what changed
173264
echo ""
174265
echo "✨ Cauldron updated successfully!"

0 commit comments

Comments
Β (0)