regolith 0.1.26 → 0.1.28
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.
- checksums.yaml +4 -4
- data/lib/regolith/cli.rb +48 -7
- data/lib/regolith/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f69bb3b17c78b25057627158d7ff12fd6a6e13fae842bb0b0ac663614fffccd
|
4
|
+
data.tar.gz: d166ce29e11051e4ddbfbccf7c157ce76ebaf8ac773481db20015b74857ce427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 131432552c9bcfeab83d7a5e814dc27d2f8a819addccc168fa5c8b05e56f34ad9313923a98c1dafd7ccaa31d591847464164854e75b8b83b00d66f1c3e6a4264
|
7
|
+
data.tar.gz: 037d67f0cf5e6a24f50e24dc46599d9f006c1e8b0baf65ff35769487ff066863fa50ede63f51e3cff196b42d58e23f2d1626c6e6bf131bfd1e3a14d712a5d5e0
|
data/lib/regolith/cli.rb
CHANGED
@@ -177,7 +177,45 @@ module Regolith
|
|
177
177
|
puts "→ Next: regolith generate service <another_service> or regolith server"
|
178
178
|
end
|
179
179
|
|
180
|
-
# ---
|
180
|
+
# --- Port collision prevention ---
|
181
|
+
def port_available?(port)
|
182
|
+
# Check if port is free on the system
|
183
|
+
begin
|
184
|
+
server = TCPServer.new('127.0.0.1', port)
|
185
|
+
server.close
|
186
|
+
true
|
187
|
+
rescue Errno::EADDRINUSE, Errno::EACCES
|
188
|
+
false
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def find_available_port(config, starting_port = 3001)
|
193
|
+
used_ports = config['services'].values.map { |s| s['port'] }.compact
|
194
|
+
port = starting_port
|
195
|
+
|
196
|
+
loop do
|
197
|
+
if !used_ports.include?(port) && port_available?(port)
|
198
|
+
puts "🔌 Assigned port #{port}"
|
199
|
+
return port
|
200
|
+
end
|
201
|
+
|
202
|
+
if used_ports.include?(port)
|
203
|
+
puts "⚠️ Port #{port} already used by another Regolith service"
|
204
|
+
else
|
205
|
+
puts "⚠️ Port #{port} already in use by system"
|
206
|
+
end
|
207
|
+
|
208
|
+
port += 1
|
209
|
+
|
210
|
+
# Safety check - don't go crazy high
|
211
|
+
if port > 4000
|
212
|
+
puts "❌ Error: No available ports found in range #{starting_port}-4000"
|
213
|
+
exit 1
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# --- Helper to make Bootsnap optional ---
|
181
219
|
def make_bootsnap_optional(service_dir)
|
182
220
|
boot_rb_path = File.join(service_dir, "config", "boot.rb")
|
183
221
|
return unless File.exist?(boot_rb_path)
|
@@ -206,6 +244,7 @@ module Regolith
|
|
206
244
|
app_rb_content = File.read(app_rb_path)
|
207
245
|
|
208
246
|
cors_config = <<~RUBY
|
247
|
+
|
209
248
|
# Regolith configuration
|
210
249
|
config.middleware.insert_before 0, Rack::Cors do
|
211
250
|
allow do
|
@@ -218,12 +257,14 @@ module Regolith
|
|
218
257
|
config.regolith_service_port = #{port}
|
219
258
|
RUBY
|
220
259
|
|
221
|
-
#
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
260
|
+
# More precise regex - find the Application class and its specific end
|
261
|
+
# This handles the case where there's both a class and module end
|
262
|
+
app_rb_content.gsub!(/(class\s+Application\s*<\s*Rails::Application.*?)(^\s*end$)/m) do |match|
|
263
|
+
class_content = $1
|
264
|
+
class_end = $2
|
265
|
+
|
266
|
+
# Insert the config before the class end
|
267
|
+
"#{class_content}#{cors_config}\n#{class_end}"
|
227
268
|
end
|
228
269
|
|
229
270
|
File.write(app_rb_path, app_rb_content)
|
data/lib/regolith/version.rb
CHANGED