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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0ac619eb909b91c979771e9238eb1706bca5c53c77c1891c3fff99d2e82fd8c
4
- data.tar.gz: 415b5a6f37bd51b5e0067f4ecf18880d27a555780e79e347d26f6e27d341a59d
3
+ metadata.gz: 0f69bb3b17c78b25057627158d7ff12fd6a6e13fae842bb0b0ac663614fffccd
4
+ data.tar.gz: d166ce29e11051e4ddbfbccf7c157ce76ebaf8ac773481db20015b74857ce427
5
5
  SHA512:
6
- metadata.gz: 1e70b07ed8e9bb4caf3713824b655e53e23525fe7ac0824d5ce26f6b2dfff9869472346197f5c1d89f1852f3a68d3d5cae07df7e4a4e02936531941a1a30777b
7
- data.tar.gz: d2166421a7ac77330c152a44b1eab6295fa1494738c5c6095d01803e39d2d8bf667275cce8e60c5795ae25de879dc4476565468fdfd96f709b712bdf3eb726cd
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
- # --- FIXED: Helper to make Bootsnap optional ---
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
- # Find the end of the Application class and insert before it
222
- if app_rb_content =~ /^(\s*)end\s*$/
223
- app_rb_content.gsub!(/^(\s*)end\s*$/) do |match|
224
- indent = $1
225
- "#{cors_config}\n#{indent}end"
226
- end
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)
@@ -1,4 +1,4 @@
1
1
  # lib/regolith/version.rb
2
2
  module Regolith
3
- VERSION = "0.1.26"
3
+ VERSION = "0.1.28"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regolith
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Regolith Team