Monorepo for Aesthetic.Computer
aesthetic.computer
1#!/usr/bin/env fish
2# Aesthetic Computer Electron - Mac Development Script
3# Usage: ./dev.fish [options]
4#
5# Options:
6# --prod Start in production mode (aesthetic.computer)
7# --dev Start in dev mode (localhost:8888)
8# --shell Start with shell/terminal view
9# --inspect Enable DevTools on port 9229 (default)
10# --no-inspect Disable DevTools/CDP
11# --watch Watch for changes and auto-restart
12# --build Build DMG before running
13# --piece=NAME Start with specific piece (default: prompt)
14#
15# Examples:
16# ./dev.fish # Run dev mode with inspector
17# ./dev.fish --prod # Run production mode
18# ./dev.fish --watch # Watch mode with auto-restart
19# ./dev.fish --build --prod # Build DMG then run production
20
21set -l script_dir (dirname (status -f))
22cd $script_dir
23
24# Colors
25set -l cyan (set_color cyan)
26set -l green (set_color green)
27set -l yellow (set_color yellow)
28set -l red (set_color red)
29set -l magenta (set_color magenta)
30set -l normal (set_color normal)
31
32echo "$magenta🎨 Aesthetic Computer Electron - Dev Environment$normal"
33echo ""
34
35# Parse arguments
36set -l mode "dev"
37set -l inspect true
38set -l watch false
39set -l build false
40set -l piece "prompt"
41set -l extra_args
42
43for arg in $argv
44 switch $arg
45 case "--prod" "--production"
46 set mode "prod"
47 case "--dev" "--development"
48 set mode "dev"
49 case "--shell"
50 set extra_args $extra_args "--shell"
51 case "--inspect"
52 set inspect true
53 case "--no-inspect"
54 set inspect false
55 case "--watch"
56 set watch true
57 case "--build"
58 set build true
59 case "--piece=*"
60 set piece (string replace "--piece=" "" $arg)
61 case "*"
62 set extra_args $extra_args $arg
63 end
64end
65
66# Build electron args
67set -l electron_args "."
68if test "$mode" = "dev"
69 set electron_args $electron_args "--dev"
70end
71if test -n "$piece"
72 set electron_args $electron_args "--piece=$piece"
73end
74set electron_args $electron_args $extra_args
75
76# Inspector args
77set -l inspect_args
78if test "$inspect" = true
79 set inspect_args "--inspect=9229" "--remote-debugging-port=9222"
80 echo "$cyan📡 DevTools Inspector:$normal http://localhost:9229"
81 echo "$cyan🔗 CDP (Chrome DevTools Protocol):$normal http://localhost:9222"
82 echo ""
83end
84
85# Get electron path
86set -l electron_bin "./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron"
87
88if not test -f $electron_bin
89 echo "$red✗ Electron not found. Running npm install...$normal"
90 npm install
91end
92
93# Build if requested
94if test "$build" = true
95 echo "$yellow🔨 Building macOS DMG...$normal"
96 npm run build:mac
97 echo ""
98end
99
100# Show mode
101if test "$mode" = "dev"
102 echo "$yellow🔧 Mode: DEVELOPMENT (localhost:8888)$normal"
103else
104 echo "$green🚀 Mode: PRODUCTION (aesthetic.computer)$normal"
105end
106echo ""
107
108# Function to run electron
109function run_electron
110 echo "$cyan▶ Starting Electron...$normal"
111 echo " $electron_bin $inspect_args $electron_args"
112 echo ""
113
114 # Run with CDP ports
115 $electron_bin $inspect_args $electron_args
116 return $status
117end
118
119# Watch mode using fswatch
120if test "$watch" = true
121 echo "$magenta👁 Watch mode enabled - will restart on file changes$normal"
122 echo " Watching: main.js, preload.js, webview-preload.js, renderer/"
123 echo " Press Ctrl+C to stop"
124 echo ""
125
126 # Start electron in background
127 set -l electron_pid
128
129 function restart_electron
130 if test -n "$electron_pid"
131 echo ""
132 echo "$yellow♻️ Restarting Electron...$normal"
133 kill $electron_pid 2>/dev/null
134 sleep 0.5
135 end
136
137 $electron_bin $inspect_args $electron_args &
138 set -g electron_pid $last_pid
139 echo "$green✓ Electron started (PID: $electron_pid)$normal"
140 end
141
142 function cleanup
143 echo ""
144 echo "$cyan🛑 Stopping...$normal"
145 if test -n "$electron_pid"
146 kill $electron_pid 2>/dev/null
147 end
148 exit 0
149 end
150
151 trap cleanup SIGINT SIGTERM
152
153 # Initial start
154 restart_electron
155
156 # Watch for changes
157 if command -v fswatch >/dev/null
158 fswatch -o main.js preload.js webview-preload.js offscreen-manager.js "renderer/" | while read -l event
159 restart_electron
160 end
161 else
162 echo "$yellow⚠ fswatch not installed. Install with: brew install fswatch$normal"
163 echo " Running without watch - press Ctrl+C and re-run to pick up changes"
164 wait $electron_pid
165 end
166else
167 # Normal run with restart loop
168 set -l restart_count 0
169
170 while true
171 if test $restart_count -gt 0
172 echo ""
173 echo "$yellow♻️ Restarting Electron (restart #$restart_count)...$normal"
174 sleep 1
175 end
176
177 run_electron
178 set -l exit_code $status
179
180 if test $exit_code -eq 42
181 # Exit code 42 = intentional reboot request
182 set restart_count (math $restart_count + 1)
183 echo "$green✓ Reboot request received$normal"
184 else
185 echo ""
186 echo "$cyan✓ Electron exited with code $exit_code$normal"
187 break
188 end
189 end
190end
191
192echo "$magenta👋 Goodbye!$normal"