hiiro 0.1.154 → 0.1.156

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: a2fdf896084fbec37ad190f81188a0e470aaf30c491acb77df209e3b6d3da6cf
4
- data.tar.gz: 3310a848c676685907bec54adba6b2eb76be56a811cf73f1dd56fb4a3953ddd7
3
+ metadata.gz: cc18a91776e0f111e0263e6dcf4c48129a14097f9b58cb0a75f3d7917c8281a2
4
+ data.tar.gz: 02f058b4148463f1685476f7c963931a74f2a1970cd8c8fddcf1fe1605f66721
5
5
  SHA512:
6
- metadata.gz: 85fe854d98a6ffa72e9df07b3816bd8a0e20ca044667afabefd8cd5918264804b8d92f85c464301aaf3275be71ba410399ab27499473ffb3b4b163e872040bff
7
- data.tar.gz: 0ea45cfd61f388f051c50eca1fc6a7f1f46039cd56f6129dc03b12e5a93ad952298225d18ea0cb078aabea04f78fcf4e27ae6662d54abeb45bdaa9ffd0dba590
6
+ metadata.gz: d2bad5c61c106dc01c45e62e40a3c49fc247b96cbd2c7d2138d5bb8c7df2fe995ad85e48563cf9250333e4bfe62f4307efdc27ca3103086f4e2e9c0e16681958
7
+ data.tar.gz: 23bb98706770163a575aa25ee40368cd5d94856c0ed4214e2aaaa4433afa92ec691738332d973dc44e02d0fec4b6f2ceaf724eb96a29c47c126b6e26bfeef8ef
@@ -0,0 +1,291 @@
1
+ # Example services.yml
2
+ # Place at ~/.config/hiiro/services.yml
3
+ #
4
+ # base_dir is always relative to the repo root (where init/start commands run)
5
+ #
6
+ # Base env templates referenced by base_env live in:
7
+ # ~/.config/hiiro/env_templates/
8
+
9
+ # =============================================================================
10
+ # Simple service - single start command, no env files
11
+ # =============================================================================
12
+ redis:
13
+ base_dir: ""
14
+ host: localhost
15
+ port: 6379
16
+ start:
17
+ - redis-server
18
+
19
+ # Usage:
20
+ # h service start redis
21
+ # h service stop redis # sends C-c
22
+
23
+ # =============================================================================
24
+ # Rails API - multiple init steps, single env file with variations
25
+ # =============================================================================
26
+ api-rails:
27
+ base_dir: apps/api
28
+ host: localhost
29
+ port: 3000
30
+ init:
31
+ - bundle install
32
+ - bin/rails db:migrate
33
+ start:
34
+ - bundle exec rails s -p 3000
35
+ cleanup:
36
+ - rm -f tmp/pids/server.pid
37
+ env_files:
38
+ - env_file: .env.development
39
+ base_env: api-rails.env
40
+ env_vars:
41
+ DATABASE_URL:
42
+ variations:
43
+ local: postgres://localhost:5432/api_dev
44
+ docker: postgres://db:5432/api_dev
45
+ staging: postgres://readonly:pass@staging-db.internal:5432/api
46
+ REDIS_URL:
47
+ variations:
48
+ local: redis://localhost:6379
49
+ docker: redis://redis:6379
50
+ LOG_LEVEL:
51
+ variations:
52
+ local: debug
53
+ quiet: warn
54
+
55
+ # Usage:
56
+ # h service start api-rails
57
+ # -> uses "local" for all variations (DATABASE_URL=postgres://localhost..., REDIS_URL=redis://localhost..., LOG_LEVEL=debug)
58
+ #
59
+ # h service start api-rails --use DATABASE_URL=docker --use REDIS_URL=docker
60
+ # -> uses docker DB and redis, LOG_LEVEL defaults to "local" (debug)
61
+ #
62
+ # h service start api-rails --use DATABASE_URL=staging --use LOG_LEVEL=quiet
63
+ # -> connects to staging DB (readonly), quiet logging, REDIS_URL defaults to local
64
+ #
65
+ # h service start api-rails --use LOG_LEVEL=quiet
66
+ # -> everything local except warn-level logging
67
+
68
+ # =============================================================================
69
+ # GraphQL service - multiple env files
70
+ # =============================================================================
71
+ graphql:
72
+ base_dir: services/graphql
73
+ host: localhost
74
+ port: 4000
75
+ init:
76
+ - npm install
77
+ start:
78
+ - npm run dev
79
+ env_files:
80
+ - env_file: .env.local
81
+ base_env: graphql.env
82
+ env_vars:
83
+ API_URL:
84
+ variations:
85
+ local: http://localhost:3000
86
+ staging: https://api.staging.example.com
87
+ production: https://api.example.com
88
+ AUTH_PROVIDER:
89
+ variations:
90
+ local: http://localhost:8080/auth
91
+ staging: https://auth.staging.example.com
92
+ production: https://auth.example.com
93
+ - env_file: .env.test
94
+ base_env: graphql-test.env
95
+ env_vars:
96
+ API_URL:
97
+ variations:
98
+ local: http://localhost:3001
99
+ mock: http://localhost:9999
100
+
101
+ # Usage:
102
+ # h service start graphql
103
+ # -> writes BOTH env files:
104
+ # .env.local gets API_URL=http://localhost:3000, AUTH_PROVIDER=http://localhost:8080/auth
105
+ # .env.test gets API_URL=http://localhost:3001
106
+ #
107
+ # h service start graphql --use API_URL=staging --use AUTH_PROVIDER=staging
108
+ # -> .env.local gets API_URL=https://api.staging.example.com, AUTH_PROVIDER=https://auth.staging.example.com
109
+ # .env.test gets API_URL=http://localhost:3001 (no "staging" variation defined for .env.test, falls back to "local")
110
+ #
111
+ # h service start graphql --use API_URL=mock
112
+ # -> .env.local gets API_URL=http://localhost:3000 (no "mock" variation in .env.local, falls back to "local")
113
+ # .env.test gets API_URL=http://localhost:9999 (uses "mock" variation)
114
+ #
115
+ # h service start graphql --use API_URL=production --use AUTH_PROVIDER=production
116
+ # -> .env.local gets API_URL=https://api.example.com, AUTH_PROVIDER=https://auth.example.com
117
+ # .env.test gets API_URL=http://localhost:3001 (no "production" defined, falls back to "local")
118
+
119
+ # =============================================================================
120
+ # Frontend - depends on graphql URL
121
+ # =============================================================================
122
+ frontend:
123
+ base_dir: apps/frontend
124
+ host: localhost
125
+ port: 8080
126
+ start:
127
+ - npm run dev
128
+ env_files:
129
+ - env_file: .env.local
130
+ base_env: frontend.env
131
+ env_vars:
132
+ GRAPHQL_URL:
133
+ variations:
134
+ local: http://localhost:4000/graphql
135
+ staging: https://graphql.staging.example.com/graphql
136
+ production: https://graphql.example.com/graphql
137
+ FEATURE_FLAGS:
138
+ variations:
139
+ local: all
140
+ staging: released
141
+ production: released
142
+
143
+ # Usage:
144
+ # h service start frontend
145
+ # -> GRAPHQL_URL=http://localhost:4000/graphql, FEATURE_FLAGS=all
146
+ #
147
+ # h service start frontend --use GRAPHQL_URL=staging --use FEATURE_FLAGS=staging
148
+ # -> GRAPHQL_URL=https://graphql.staging.example.com/graphql, FEATURE_FLAGS=released
149
+
150
+ # =============================================================================
151
+ # Worker with custom stop command
152
+ # =============================================================================
153
+ sidekiq:
154
+ base_dir: apps/api
155
+ host: localhost
156
+ port: ""
157
+ start:
158
+ - bundle exec sidekiq -C config/sidekiq.yml
159
+ stop: "pkill -f sidekiq"
160
+ env_files:
161
+ - env_file: .env.development
162
+ base_env: api-rails.env
163
+ env_vars:
164
+ REDIS_URL:
165
+ variations:
166
+ local: redis://localhost:6379
167
+ docker: redis://redis:6379
168
+
169
+ # Usage:
170
+ # h service start sidekiq
171
+ # h service stop sidekiq # runs "pkill -f sidekiq" instead of C-c
172
+
173
+ # =============================================================================
174
+ # Multi-command start - seed data then launch
175
+ # =============================================================================
176
+ demo-server:
177
+ base_dir: apps/demo
178
+ host: localhost
179
+ port: 5000
180
+ init:
181
+ - npm install
182
+ start:
183
+ - npm run db:seed
184
+ - npm run build:assets
185
+ - npm start
186
+ env_files:
187
+ - env_file: .env
188
+ base_env: demo.env
189
+ env_vars:
190
+ DEMO_MODE:
191
+ variations:
192
+ local: full
193
+ lite: minimal
194
+
195
+ # Usage:
196
+ # h service start demo-server
197
+ # -> creates a script that runs: db:seed && build:assets && start
198
+ # -> DEMO_MODE=full
199
+ #
200
+ # h service start demo-server --use DEMO_MODE=lite
201
+ # -> same commands, DEMO_MODE=minimal
202
+
203
+ # =============================================================================
204
+ # SERVICE GROUPS
205
+ # =============================================================================
206
+
207
+ # Full local stack - everything pointing at localhost
208
+ full-stack:
209
+ services:
210
+ - name: redis
211
+ - name: api-rails
212
+ use:
213
+ DATABASE_URL: local
214
+ REDIS_URL: local
215
+ LOG_LEVEL: local
216
+ - name: graphql
217
+ use:
218
+ API_URL: local
219
+ AUTH_PROVIDER: local
220
+ - name: frontend
221
+ use:
222
+ GRAPHQL_URL: local
223
+ FEATURE_FLAGS: local
224
+
225
+ # Usage:
226
+ # h service start full-stack
227
+ # -> creates ONE tmux window with 4 split panes (redis, api-rails, graphql, frontend)
228
+ # -> all services use "local" variations
229
+
230
+ # Frontend + GraphQL against staging API (no local rails needed)
231
+ staging-fe:
232
+ services:
233
+ - name: graphql
234
+ use:
235
+ API_URL: staging
236
+ AUTH_PROVIDER: staging
237
+ - name: frontend
238
+ use:
239
+ GRAPHQL_URL: local
240
+ FEATURE_FLAGS: staging
241
+
242
+ # Usage:
243
+ # h service start staging-fe
244
+ # -> ONE tmux window, 2 split panes
245
+ # -> graphql points at staging API/auth
246
+ # -> frontend points at local graphql (which proxies to staging)
247
+
248
+ # Backend only - rails + sidekiq + redis, docker DB
249
+ backend-docker:
250
+ services:
251
+ - name: redis
252
+ - name: api-rails
253
+ use:
254
+ DATABASE_URL: docker
255
+ REDIS_URL: docker
256
+ LOG_LEVEL: local
257
+ - name: sidekiq
258
+ use:
259
+ REDIS_URL: docker
260
+
261
+ # Usage:
262
+ # h service start backend-docker
263
+ # -> 3 split panes: redis, api-rails, sidekiq
264
+ # -> all using docker postgres and redis URLs
265
+
266
+ # =============================================================================
267
+ # QUICK REFERENCE - all start commands
268
+ # =============================================================================
269
+ #
270
+ # Start with defaults (all "local" variations):
271
+ # h service start <name>
272
+ #
273
+ # Start with specific variations:
274
+ # h service start <name> --use VAR=variation
275
+ # h service start <name> --use VAR1=v1 --use VAR2=v2
276
+ #
277
+ # Start a group (pre-configured variation combos):
278
+ # h service start <group-name>
279
+ #
280
+ # Interactive selection (no name):
281
+ # h service start
282
+ #
283
+ # Other commands:
284
+ # h service stop [name] # C-c (or custom stop cmd), fuzzy select if no name
285
+ # h service attach [name] # switch to service's tmux pane
286
+ # h service status [name] # show service details
287
+ # h service reset [name] # clear stale running state
288
+ # h service clean # auto-prune dead panes from state
289
+ # h service ls # list all services + status
290
+ # h service env <name> # show env file config and variations
291
+ # h service groups # list all groups and members
@@ -50,8 +50,7 @@ class Hiiro
50
50
  svc = find_service(svc_name)
51
51
  return unless svc
52
52
 
53
- base_dir = svc[:base_dir]
54
- return unless base_dir
53
+ base_dir = resolve_base_dir(svc[:base_dir])
55
54
 
56
55
  env_file_configs = build_env_file_configs(svc)
57
56
  return if env_file_configs.empty?
@@ -86,7 +85,7 @@ class Hiiro
86
85
  first_member = members.first
87
86
  first_name = first_member['name'] || first_member[:name]
88
87
  first_svc = find_service(first_name)
89
- first_base_dir = first_svc&.[](:base_dir) || Dir.pwd
88
+ first_base_dir = resolve_base_dir(first_svc&.[](:base_dir))
90
89
 
91
90
  # Create a new window for the group
92
91
  window_target = create_tmux_window(session, group[:name], first_base_dir)
@@ -99,7 +98,7 @@ class Hiiro
99
98
  svc = find_service(member_name)
100
99
  next unless svc
101
100
 
102
- base_dir = svc[:base_dir] || Dir.pwd
101
+ base_dir = resolve_base_dir(svc[:base_dir])
103
102
 
104
103
  if idx == 0
105
104
  # First service uses the initial pane
@@ -184,13 +183,9 @@ class Hiiro
184
183
 
185
184
  # Run init commands
186
185
  if svc[:init]
186
+ base_dir = resolve_base_dir(svc[:base_dir])
187
187
  svc[:init].each do |cmd|
188
- base_dir = svc[:base_dir]
189
- if base_dir
190
- system("cd #{base_dir} && #{cmd}")
191
- else
192
- system(cmd)
193
- end
188
+ system("cd #{base_dir} && #{cmd}")
194
189
  end
195
190
  end
196
191
 
@@ -207,7 +202,7 @@ class Hiiro
207
202
  end
208
203
 
209
204
  start_cmds = Array(start_cmd)
210
- base_dir = svc[:base_dir]
205
+ base_dir = resolve_base_dir(svc[:base_dir])
211
206
  session = tmux_info[:session] || current_tmux_session
212
207
 
213
208
  # Write start commands to an executable tempfile
@@ -215,7 +210,7 @@ class Hiiro
215
210
 
216
211
  if session && !skip_window_creation
217
212
  # Create a new tmux window for this service
218
- window_target = create_tmux_window(session, svc_name, base_dir || Dir.pwd)
213
+ window_target = create_tmux_window(session, svc_name, base_dir)
219
214
  pane_id = capture_pane_id(window_target)
220
215
  elsif session && skip_window_creation
221
216
  # Pane already created by start_group
@@ -228,10 +223,8 @@ class Hiiro
228
223
 
229
224
  if pane_id
230
225
  system('tmux', 'send-keys', '-t', pane_id, script, 'Enter')
231
- elsif base_dir
232
- system("cd #{base_dir} && #{script} &")
233
226
  else
234
- system("#{script} &")
227
+ system("cd #{base_dir} && #{script} &")
235
228
  end
236
229
 
237
230
  # Record state
@@ -817,5 +810,14 @@ class Hiiro
817
810
  def symbolize_keys(hash)
818
811
  hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
819
812
  end
813
+
814
+ def resolve_base_dir(base_dir)
815
+ return Dir.pwd if base_dir.nil? || base_dir.to_s.empty?
816
+
817
+ git_root = `git rev-parse --show-toplevel 2>/dev/null`.chomp
818
+ root = git_root.empty? ? Dir.pwd : git_root
819
+
820
+ File.join(root, base_dir)
821
+ end
820
822
  end
821
823
  end
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.154"
2
+ VERSION = "0.1.156"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.154
4
+ version: 0.1.156
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota
@@ -113,6 +113,7 @@ files:
113
113
  - docs/h-session.md
114
114
  - docs/h-window.md
115
115
  - editboth
116
+ - examples/services.yml
116
117
  - exe/h
117
118
  - exe/hiiro
118
119
  - h-tmux-plugins.tmux