regolith 0.1.25 → 0.1.27

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: d447572c7f8e6230414cfb4b13ffeb32de77ec6f79612bfaccb620e9140466bc
4
- data.tar.gz: 16c7e26aad9c1f8261d9a27a5acdaf86fb5a80321fcac227ee79ac7aeeade7af
3
+ metadata.gz: 973264713948f2e5db2ff16f9e3b8c1d3a8655658315965fd40ddd4e977d9a6e
4
+ data.tar.gz: 5643b91bcf2e95c3f2e47851409e28c2c0993a72fea4f7ab42d18911fa0314a9
5
5
  SHA512:
6
- metadata.gz: efb74771a03f353f38818391cdb8acf34d6ecc7081443a270e714b286a846917528da0adea6dd675924166790a2a81215b710ce2d817e0769a985ff1edb0f8cf
7
- data.tar.gz: 22ec3dafdab950d8d25b2d7ab92c8db6e7c41361603756524f955c01782d8fdd26fe8ce1aad4f2ecfb68d49d55aa9b4e067b0bca2b15401a0c9339478e1fef54
6
+ metadata.gz: e934b3a272665af2195a4a0987705605477f2a0ff0fc53f38406c19ccbb50d94fef8696df638272d31cf0f18431d1207445a4d894d797c1b77abd5708c6d5b26
7
+ data.tar.gz: f6d5df82730c20811d366b100aa9d666cd1662e060aa71387c2b571014d36105952ee5d7d90bf8afd3b1e2cf844070e0dcf7b4d2214339b76d600e9d6407c900
data/lib/regolith/cli.rb CHANGED
@@ -3,6 +3,7 @@ require 'yaml'
3
3
  require 'erb'
4
4
  require 'timeout'
5
5
  require 'rubygems'
6
+ require 'socket'
6
7
 
7
8
  module Regolith
8
9
  class CLI
@@ -85,7 +86,7 @@ module Regolith
85
86
  def generate_service(service_name)
86
87
  puts "🔧 Creating service '#{service_name}'..."
87
88
  config = load_regolith_config
88
- port = 3001 + (config['services']&.size || 0)
89
+ port = find_available_port(config)
89
90
  service_dir = "services/#{service_name}_service"
90
91
 
91
92
  puts " → Generating Rails API app..."
@@ -176,7 +177,45 @@ module Regolith
176
177
  puts "→ Next: regolith generate service <another_service> or regolith server"
177
178
  end
178
179
 
179
- # --- 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 ---
180
219
  def make_bootsnap_optional(service_dir)
181
220
  boot_rb_path = File.join(service_dir, "config", "boot.rb")
182
221
  return unless File.exist?(boot_rb_path)
@@ -1,4 +1,4 @@
1
1
  # lib/regolith/version.rb
2
2
  module Regolith
3
- VERSION = "0.1.25"
3
+ VERSION = "0.1.27"
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.25
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Regolith Team