foobara-empty-ruby-project-generator 0.0.20 → 0.0.21

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: e82a8d6af3338fe69f43a3a4573720791a5d93064c50d2fa3d1e1f95a42f12aa
4
- data.tar.gz: 4d788a75115bf60b4bbb89089d3cfab7393fd95a3acb7b035f1e10fef6c93bf3
3
+ metadata.gz: f2b61d99024ebd625a84d1c39fa2dbc52a9535f67d38c55b5b34268e31d3c37a
4
+ data.tar.gz: 3059a9f887c3bfa08d9a059d8019be6e8267559be9992a12657b0ebf5edd1a62
5
5
  SHA512:
6
- metadata.gz: 875efa4b26a347baf98f9c4b347f15b472cc24bc1226691fe60cad7cf284db329b7df5d4c0ae8d73d486d6f0ceeeec4642f5e13550eb05128b4cf4425bd2310e
7
- data.tar.gz: f2ff5fbb32e62bf21d33ace1292257524f0023e35a6b1960561187529c7245ec21881cc570b06782c461622dfd7171cf2a276af4ece464e575dbfae8af9f8c2f
6
+ metadata.gz: 3f6d0cd0812dea545d4dc7e2498bb4830e2688dfc63109d0877fb9a3dde07b26fc29d56214977f14ad41c9f41884a6855a35b266e44637867a8463aba439680d
7
+ data.tar.gz: d1e492b3b824500c4675f8f69d2d74816617341bd0742bb627a89b30ad177d3d1e3c2f4beed2d1022b0991368b724f6f5e4cafca100ea26be5a51bdf1bc48881
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.21] - 2025-05-03
2
+
3
+ - Make optional things fail-safe when shelling out and simplify the code a bit, too
4
+
1
5
  ## [0.0.20] - 2025-05-03
2
6
 
3
7
  - Add use_git, push_to_github, and turn_on_rbenv_bundler options and default them to false
@@ -35,6 +35,8 @@ module Foobara
35
35
  output
36
36
  end
37
37
 
38
+ attr_accessor :use_git_failed, :push_to_github_failed
39
+
38
40
  def create_output_directory_if_needed
39
41
  FileUtils.mkdir_p output_directory
40
42
  end
@@ -106,22 +108,15 @@ module Foobara
106
108
 
107
109
  def bundle_install
108
110
  puts "bundling..."
109
- do_it = proc do
110
- Open3.popen3("bundle install") do |_stdin, _stdout, stderr, wait_thr|
111
- exit_status = wait_thr.value
112
- unless exit_status.success?
113
- # :nocov:
114
- raise "could not bundle install. #{stderr.read}"
115
- # :nocov:
116
- end
117
- end
118
- end
111
+ cmd = "bundle install"
119
112
 
120
113
  if Bundler.respond_to?(:with_unbundled_env)
121
- Bundler.with_unbundled_env(&do_it)
114
+ Bundler.with_unbundled_env do
115
+ run_cmd_and_return_output(cmd)
116
+ end
122
117
  else
123
118
  # :nocov:
124
- do_it.call
119
+ run_cmd_and_return_output(cmd)
125
120
  # :nocov:
126
121
  end
127
122
  end
@@ -129,15 +124,15 @@ module Foobara
129
124
  def rubocop_autocorrect
130
125
  puts "linting..."
131
126
 
132
- do_it = -> { run_cmd_and_return_output("bundle exec rubocop --no-server -A") }
127
+ cmd = "bundle exec rubocop --no-server -A"
133
128
 
134
129
  if Bundler.respond_to?(:with_unbundled_env)
135
130
  Bundler.with_unbundled_env do
136
- do_it.call
131
+ run_cmd_and_return_output(cmd)
137
132
  end
138
133
  else
139
134
  # :nocov:
140
- do_it.call
135
+ run_cmd_and_return_output(cmd)
141
136
  # :nocov:
142
137
  end
143
138
  end
@@ -145,90 +140,106 @@ module Foobara
145
140
  def make_bin_files_executable
146
141
  Dir["bin/*"].each do |file|
147
142
  if File.file?(file)
148
- system("chmod u+x #{file}")
143
+ cmd = "chmod u+x #{file}"
144
+ begin
145
+ run_cmd_and_return_output(cmd)
146
+ rescue CouldNotExecuteError => e
147
+ # :nocov:
148
+ warn e.message
149
+ # :nocov:
150
+ end
149
151
  end
150
152
  end
151
153
  end
152
154
 
153
155
  def git_init
154
- cmd = "git init"
156
+ return if use_git_failed
155
157
 
156
- Open3.popen3(cmd) do |_stdin, _stdout, stderr, wait_thr|
157
- exit_status = wait_thr.value
158
- unless exit_status.success?
159
- # :nocov:
160
- raise "could not #{cmd}\n#{stderr.read}"
161
- # :nocov:
162
- end
163
- end
158
+ cmd = "git init"
159
+ run_cmd_and_return_output(cmd)
160
+ rescue CouldNotExecuteError => e
161
+ # :nocov:
162
+ self.use_git_failed = true
163
+ warn e.message
164
+ # :nocov:
164
165
  end
165
166
 
166
167
  def git_add_all
167
- cmd = "git add ."
168
+ return if use_git_failed
168
169
 
169
- Open3.popen3(cmd) do |_stdin, _stdout, stderr, wait_thr|
170
- exit_status = wait_thr.value
171
- unless exit_status.success?
172
- # :nocov:
173
- raise "could not #{cmd}\n#{stderr.read}"
174
- # :nocov:
175
- end
176
- end
170
+ cmd = "git add ."
171
+ run_cmd_and_return_output(cmd)
172
+ rescue CouldNotExecuteError => e
173
+ # :nocov:
174
+ self.use_git_failed = true
175
+ warn e.message
176
+ # :nocov:
177
177
  end
178
178
 
179
179
  def git_commit
180
- # TODO: set author/name with git config in CI so we don't have to skip this
180
+ return if use_git_failed
181
+
182
+ cmd = "git commit -m 'Create ruby project files'"
183
+ run_cmd_and_return_output(cmd)
184
+ rescue CouldNotExecuteError => e
181
185
  # :nocov:
182
- Open3.popen3("git commit -m 'Create ruby project files'") do |_stdin, stdout, stderr, wait_thr|
183
- exit_status = wait_thr.value
184
- unless exit_status.success?
185
- raise "could not git commit -m 'Initial commit'. OUTPUT\n#{stdout.read}\nERROR:#{stderr.read}"
186
- end
187
- end
186
+ self.use_git_failed = true
187
+ warn e.message
188
188
  # :nocov:
189
189
  end
190
190
 
191
191
  def github_create_repo
192
+ return if push_to_github_failed
193
+
192
194
  puts "pushing to github..."
193
195
 
194
196
  cmd = "gh repo create --private #{project_config.org_slash_project_kebab}"
195
- run_cmd_and_write_output(cmd, raise_if_fails: false)
197
+ exit_status = run_cmd_and_write_output(cmd, raise_if_fails: false)
198
+
199
+ unless exit_status&.success?
200
+ self.push_to_github_failed = true
201
+ end
196
202
  end
197
203
 
198
204
  def git_add_remote_origin
199
- unless system("git remote add origin git@github.com:#{project_config.org_slash_project_kebab}.git")
205
+ return if push_to_github_failed
206
+
207
+ cmd = "git remote add origin git@github.com:#{project_config.org_slash_project_kebab}.git"
208
+ exit_status = run_cmd_and_write_output(cmd, raise_if_fails: false)
209
+
210
+ unless exit_status&.success?
200
211
  # :nocov:
201
- raise "could not git remote add origin git@github.com:#{project_config.org_slash_project_kebab}.git"
212
+ self.push_to_github_failed = true
202
213
  # :nocov:
203
214
  end
204
215
  end
205
216
 
206
217
  def git_branch_main
207
- unless system("git branch -M main")
218
+ return if use_git_failed
219
+
220
+ cmd = "git branch -M main"
221
+ exit_status = run_cmd_and_write_output(cmd, raise_if_fails: false)
222
+
223
+ unless exit_status&.success?
208
224
  # :nocov:
209
- raise "could not git branch -M main"
225
+ self.use_git_failed = true
210
226
  # :nocov:
211
227
  end
212
228
  end
213
229
 
214
230
  def push_to_github
215
- Open3.popen3("git push -u origin main") do |_stdin, _stdout, stderr, wait_thr|
216
- exit_status = wait_thr.value
217
- unless exit_status.success?
218
- warn "WARNING: could not git push -u origin main \n #{stderr.read}"
219
- end
220
- end
231
+ return if push_to_github_failed
232
+
233
+ cmd = "git push -u origin main"
234
+ run_cmd_and_return_output(cmd)
235
+ rescue CouldNotExecuteError => e
236
+ self.push_to_github_failed = true
237
+ warn e.message
221
238
  end
222
239
 
223
240
  def rbenv_bundler_on
224
- # :nocov:
225
- Open3.popen3("rbenv bundler on") do |_stdin, _stdout, stderr, wait_thr|
226
- exit_status = wait_thr.value
227
- unless exit_status.success?
228
- warn "WARNING: could not rbenv bundler on \n #{stderr.read}"
229
- end
230
- end
231
- # :nocov:
241
+ cmd = "rbenv bundler on"
242
+ run_cmd_and_write_output(cmd, raise_if_fails: false)
232
243
  end
233
244
 
234
245
  def output
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-empty-ruby-project-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi