foobar_templates 2.0.1.rc4 → 2.0.1
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/README.md +17 -0
- data/Rakefile +58 -1
- data/lib/foobar_templates/cli/cli.rb +1 -0
- data/lib/foobar_templates/cli/template_generator.rb +25 -24
- data/lib/foobar_templates/version.rb +3 -1
- data/lib/foobar_templates.rb +1 -3
- data/spec/foobar_templates_spec.rb +36 -13
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a321f9180b9cad22c9e5f3675fba1405b6177d245c0d82057f595b4135660fdf
|
|
4
|
+
data.tar.gz: 5c8f819dce4a1af6a442f85577f31f3a01d342245a3a7172de25d96185ae87ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56401afe877b9bd254c96649ef61026c246ba806c6eb1de936f5cb2808e242c4e515ff56a8c70d75dd6c10882162f59b5177af5273198727b83826093f187920
|
|
7
|
+
data.tar.gz: 0be856b92d4ec8e243e42c9d2f9adf1404bd53e11b77a54d57102bafce844189ea53168d7d4dbd8812876d4bc7380a4ca33dfe7abb623555462a3c5d8cd7536e
|
data/README.md
CHANGED
|
@@ -153,3 +153,20 @@ If you would find additional variables handy, set me up with a PR and assuming i
|
|
|
153
153
|
- Use `FOO_` prefixed placeholders for non-name variables: `FOO_AUTHOR`, `FOO_EMAIL`, `FOO_GIT_REPO_URL`, etc.
|
|
154
154
|
- Running `foobar_templates --cheat-sheet` will list off available template variables
|
|
155
155
|
- File **names** containing `foo-bar` or `foo_bar` will have those replaced by the project name
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## Release Process
|
|
159
|
+
|
|
160
|
+
Cut a pre-release with:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
rake release
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Days or months later, promote it to a release:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
git checkout OLD_RELEASE
|
|
170
|
+
rake promote
|
|
171
|
+
```
|
|
172
|
+
|
data/Rakefile
CHANGED
|
@@ -19,12 +19,26 @@ module ReleaseHelper
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def current_version
|
|
22
|
+
return ENV['GEM_VERSION'] if ENV['GEM_VERSION']
|
|
23
|
+
|
|
22
24
|
src = File.read(VERSION_FILE)
|
|
23
|
-
m = src.match(/VERSION\s*=\s*"([^"]+)"/)
|
|
25
|
+
m = src.match(/VERSION\s*=\s*["']([^"']+)["']/)
|
|
24
26
|
abort "Could not parse VERSION from #{VERSION_FILE}" unless m
|
|
25
27
|
m[1]
|
|
26
28
|
end
|
|
27
29
|
|
|
30
|
+
def strip_rc(version)
|
|
31
|
+
m = version.match(RC_RE)
|
|
32
|
+
return nil unless m
|
|
33
|
+
maj, min, pat, _rc = m.captures
|
|
34
|
+
"#{maj}.#{min}.#{pat}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def rc_tag_on_head
|
|
38
|
+
tags = `git tag --points-at HEAD`.strip.split("\n")
|
|
39
|
+
tags.find { |t| t.match?(/\Av\d+\.\d+\.\d+\.rc\d+\z/) }
|
|
40
|
+
end
|
|
41
|
+
|
|
28
42
|
def next_version(v)
|
|
29
43
|
if (m = v.match(RC_RE))
|
|
30
44
|
maj, min, pat, rc = m.captures.map(&:to_i)
|
|
@@ -168,6 +182,49 @@ task :release do
|
|
|
168
182
|
puts "=" * 60
|
|
169
183
|
end
|
|
170
184
|
|
|
185
|
+
desc "Promote a pre-release commit to a final release (no new commit needed)"
|
|
186
|
+
task :promote, [:version] do |_t, args|
|
|
187
|
+
include_helper = ReleaseHelper
|
|
188
|
+
|
|
189
|
+
include_helper.preflight!
|
|
190
|
+
|
|
191
|
+
# Determine the RC tag on HEAD
|
|
192
|
+
rc_tag = include_helper.rc_tag_on_head
|
|
193
|
+
abort "No pre-release tag (vX.Y.Z.rcN) found on HEAD. Checkout a tagged RC commit first." unless rc_tag
|
|
194
|
+
rc_version = rc_tag.sub(/\Av/, '')
|
|
195
|
+
|
|
196
|
+
# Determine target release version
|
|
197
|
+
release_version = args[:version] || include_helper.strip_rc(rc_version)
|
|
198
|
+
abort "Could not derive release version from #{rc_version}" unless release_version
|
|
199
|
+
abort "Target version #{release_version} is not a release format (expected MAJOR.MINOR.PATCH)" unless release_version.match?(ReleaseHelper::REL_RE)
|
|
200
|
+
|
|
201
|
+
sha = `git rev-parse --short HEAD`.strip
|
|
202
|
+
puts "Promoting commit #{sha} (tagged #{rc_tag}) \u2192 v#{release_version}"
|
|
203
|
+
unless include_helper.confirm!("Continue?", default: false)
|
|
204
|
+
puts "Aborted."
|
|
205
|
+
exit 0
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# Build gem with the release version (override via ENV, no file edit)
|
|
209
|
+
ENV['GEM_VERSION'] = release_version
|
|
210
|
+
Rake::Task[:build].invoke
|
|
211
|
+
|
|
212
|
+
gem_file = "pkg/#{GEM_NAME}-#{release_version}.gem"
|
|
213
|
+
abort "Built gem not found at #{gem_file}" unless File.exist?(gem_file)
|
|
214
|
+
|
|
215
|
+
# Tag and push
|
|
216
|
+
tag = "v#{release_version}"
|
|
217
|
+
include_helper.sh! %(git tag -a #{tag} -m "Release #{tag}")
|
|
218
|
+
include_helper.push! "git push origin #{tag}"
|
|
219
|
+
include_helper.push! "gem push #{gem_file}"
|
|
220
|
+
|
|
221
|
+
puts ""
|
|
222
|
+
puts "=" * 60
|
|
223
|
+
puts "Promoted: #{rc_tag} \u2192 #{tag}"
|
|
224
|
+
puts "Tag: https://github.com/TheNotary/#{GEM_NAME}/releases/tag/#{tag}"
|
|
225
|
+
puts "=" * 60
|
|
226
|
+
end
|
|
227
|
+
|
|
171
228
|
desc "Run unit specs"
|
|
172
229
|
RSpec::Core::RakeTask.new(:unit) do |t|
|
|
173
230
|
t.rspec_opts = %w(-fd -c)
|
|
@@ -77,7 +77,7 @@ module FoobarTemplates::CLI
|
|
|
77
77
|
puts cmd
|
|
78
78
|
time_it("bootstrap_command") do
|
|
79
79
|
Dir.chdir(target) do
|
|
80
|
-
`#{cmd}`
|
|
80
|
+
puts `#{cmd}`
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
end
|
|
@@ -178,8 +178,9 @@ module FoobarTemplates::CLI
|
|
|
178
178
|
|
|
179
179
|
reserved = Array(rules[:reserved_names]).map(&:to_s)
|
|
180
180
|
if reserved.include?(name)
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
raise FoobarTemplates::CLIError, <<~HEREDOC
|
|
182
|
+
Invalid project name '#{name}': reserved by template '#{@options[:template]}'. Please choose another name.
|
|
183
|
+
HEREDOC
|
|
183
184
|
end
|
|
184
185
|
|
|
185
186
|
pattern = rules[:regex_validator]
|
|
@@ -187,13 +188,15 @@ module FoobarTemplates::CLI
|
|
|
187
188
|
begin
|
|
188
189
|
regex = Regexp.new(pattern.to_s)
|
|
189
190
|
rescue RegexpError => e
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
raise FoobarTemplates::CLIError, <<~HEREDOC
|
|
192
|
+
Template '#{@options[:template]}' has an invalid name_validation.regex_validator: #{e.message}
|
|
193
|
+
HEREDOC
|
|
192
194
|
end
|
|
193
195
|
|
|
194
196
|
unless regex.match?(name)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
raise FoobarTemplates::CLIError, <<~HEREDOC
|
|
198
|
+
Invalid project name '#{name}': does not match #{regex.inspect} required by template '#{@options[:template]}'.
|
|
199
|
+
HEREDOC
|
|
197
200
|
end
|
|
198
201
|
end
|
|
199
202
|
end
|
|
@@ -463,31 +466,28 @@ module FoobarTemplates::CLI
|
|
|
463
466
|
end
|
|
464
467
|
|
|
465
468
|
def raise_no_files_in_template_error!
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
but no files were found within it.
|
|
469
|
+
raise FoobarTemplates::CLIError, <<~HEREDOC
|
|
470
|
+
The template was found for '#{@options[:template]}' in ~/.foobar/templates,
|
|
471
|
+
but no files were found within it.
|
|
469
472
|
|
|
470
|
-
Exiting...
|
|
473
|
+
Exiting...
|
|
471
474
|
HEREDOC
|
|
472
|
-
puts err_no_files_in_template
|
|
473
|
-
raise
|
|
474
475
|
end
|
|
475
476
|
|
|
476
477
|
def raise_project_with_that_name_already_exists!
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
Can't make project. Either delete that folder or choose a new project name
|
|
478
|
+
raise FoobarTemplates::CLIError, <<~HEREDOC
|
|
479
|
+
A project with the name #{target} already exists.
|
|
480
|
+
Can't make project. Either delete that folder or choose a new project name
|
|
480
481
|
|
|
481
|
-
Exiting...
|
|
482
|
+
Exiting...
|
|
482
483
|
HEREDOC
|
|
483
|
-
puts err_project_with_that_name_exists
|
|
484
|
-
raise
|
|
485
484
|
end
|
|
486
485
|
|
|
487
486
|
def raise_template_not_found!
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
487
|
+
raise FoobarTemplates::CLIError, <<~HEREDOC
|
|
488
|
+
Template not found for '#{@options[:template]}' in `~/.foobar/templates/`.
|
|
489
|
+
Please check to make sure your desired template exists.
|
|
490
|
+
HEREDOC
|
|
491
491
|
end
|
|
492
492
|
|
|
493
493
|
def time_it(label = nil)
|
|
@@ -509,8 +509,9 @@ Exiting...
|
|
|
509
509
|
# and won't overlap with a foobar_templates constant apparently...
|
|
510
510
|
def ensure_safe_project_name(name, constant_array)
|
|
511
511
|
if name =~ /^\d/
|
|
512
|
-
|
|
513
|
-
|
|
512
|
+
raise FoobarTemplates::CLIError, <<~HEREDOC
|
|
513
|
+
Invalid gem name #{name}. Please give a name which does not start with numbers.
|
|
514
|
+
HEREDOC
|
|
514
515
|
end
|
|
515
516
|
end
|
|
516
517
|
|
data/lib/foobar_templates.rb
CHANGED
|
@@ -80,9 +80,7 @@ module FoobarTemplates
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def generate_template(options, gem_name)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
template_generator = CLI::TemplateGenerator.new(options, gem_name).run
|
|
83
|
+
CLI::TemplateGenerator.new(options, gem_name).run
|
|
86
84
|
rescue FoobarTemplates::CLIError => e
|
|
87
85
|
msg = e.message
|
|
88
86
|
$stderr.puts msg if msg && !msg.empty? && msg != e.class.name
|
|
@@ -9,6 +9,7 @@ describe FoobarTemplates do
|
|
|
9
9
|
|
|
10
10
|
reset_test_env
|
|
11
11
|
FileUtils.chdir(@dst_dir)
|
|
12
|
+
@dst_dir = FileUtils.pwd # We need to resolve the /tmp dir incase it's a mac with /private/tmp
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
it 'has a version number' do
|
|
@@ -205,7 +206,7 @@ describe FoobarTemplates do
|
|
|
205
206
|
5000.times { |i| File.write("#{template_dir}/node_modules/file_#{i}.rb", "ignored #{i}") }
|
|
206
207
|
`git init #{template_dir}`
|
|
207
208
|
|
|
208
|
-
capture_stdout do
|
|
209
|
+
capture_stdout do
|
|
209
210
|
FoobarTemplates.generate_template(options, gem_name)
|
|
210
211
|
end
|
|
211
212
|
|
|
@@ -242,6 +243,36 @@ describe FoobarTemplates do
|
|
|
242
243
|
expect(output).to include "echo #{gem_name}"
|
|
243
244
|
end
|
|
244
245
|
|
|
246
|
+
it "prints stdout of a multi-line bootstrap_command" do
|
|
247
|
+
# this is quite pointless, we're literally allowing the user to execute a command on their shell...
|
|
248
|
+
template_dir = create_user_defined_template("testing", "template-user-supplied")
|
|
249
|
+
options = { bin: false, ext: false, coc: false, template: "template-user-supplied" }
|
|
250
|
+
gem_name = "good-dog"
|
|
251
|
+
|
|
252
|
+
yaml_content = <<~YAML
|
|
253
|
+
bootstrap_command: |
|
|
254
|
+
echo 'foo-bar'
|
|
255
|
+
pwd
|
|
256
|
+
cd ..
|
|
257
|
+
pwd
|
|
258
|
+
YAML
|
|
259
|
+
|
|
260
|
+
File.write("#{template_dir}/foobar.yml", yaml_content)
|
|
261
|
+
File.write("#{template_dir}/README.md", "# Readme...")
|
|
262
|
+
`git init #{template_dir}`
|
|
263
|
+
|
|
264
|
+
output = capture_stdout { FoobarTemplates.generate_template(options, gem_name) }
|
|
265
|
+
|
|
266
|
+
expect(output).to end_with <<~OUTPUT
|
|
267
|
+
pwd
|
|
268
|
+
good-dog
|
|
269
|
+
#{@dst_dir}/good-dog
|
|
270
|
+
#{@dst_dir}
|
|
271
|
+
|
|
272
|
+
Complete.
|
|
273
|
+
OUTPUT
|
|
274
|
+
end
|
|
275
|
+
|
|
245
276
|
describe "name_validation" do
|
|
246
277
|
it "rejects names listed in reserved_names and skips bootstrap_command" do
|
|
247
278
|
template_dir = create_user_defined_template("testing", "template-user-supplied")
|
|
@@ -255,9 +286,7 @@ describe FoobarTemplates do
|
|
|
255
286
|
File.write("#{template_dir}/README.md", "# Readme")
|
|
256
287
|
`git init #{template_dir}`
|
|
257
288
|
|
|
258
|
-
|
|
259
|
-
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
260
|
-
}.to raise_error(RuntimeError)
|
|
289
|
+
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
261
290
|
|
|
262
291
|
expect($captured_stderr).to include "reserved by template"
|
|
263
292
|
expect(File).not_to exist("#{@dst_dir}/#{gem_name}")
|
|
@@ -292,9 +321,7 @@ describe FoobarTemplates do
|
|
|
292
321
|
File.write("#{template_dir}/README.md", "# Readme")
|
|
293
322
|
`git init #{template_dir}`
|
|
294
323
|
|
|
295
|
-
|
|
296
|
-
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
297
|
-
}.to raise_error(RuntimeError)
|
|
324
|
+
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
298
325
|
|
|
299
326
|
expect($captured_stderr).to include "does not match"
|
|
300
327
|
expect(File).not_to exist("#{@dst_dir}/#{gem_name}")
|
|
@@ -329,9 +356,7 @@ describe FoobarTemplates do
|
|
|
329
356
|
File.write("#{template_dir}/README.md", "# Readme")
|
|
330
357
|
`git init #{template_dir}`
|
|
331
358
|
|
|
332
|
-
|
|
333
|
-
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
334
|
-
}.to raise_error(RuntimeError)
|
|
359
|
+
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
335
360
|
|
|
336
361
|
expect($captured_stderr).to include "reserved"
|
|
337
362
|
end
|
|
@@ -348,9 +373,7 @@ describe FoobarTemplates do
|
|
|
348
373
|
File.write("#{template_dir}/README.md", "# Readme")
|
|
349
374
|
`git init #{template_dir}`
|
|
350
375
|
|
|
351
|
-
|
|
352
|
-
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
353
|
-
}.to raise_error(RuntimeError)
|
|
376
|
+
capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
|
|
354
377
|
|
|
355
378
|
expect($captured_stderr).to include "invalid name_validation.regex_validator"
|
|
356
379
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foobar_templates
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.1
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- TheNotary
|
|
@@ -130,9 +130,9 @@ licenses:
|
|
|
130
130
|
- MIT
|
|
131
131
|
metadata:
|
|
132
132
|
bug_tracker_uri: https://github.com/TheNotary/foobar_templates/issues
|
|
133
|
-
changelog_uri: https://github.com/TheNotary/foobar_templates/releases/tag/v2.0.1
|
|
133
|
+
changelog_uri: https://github.com/TheNotary/foobar_templates/releases/tag/v2.0.1
|
|
134
134
|
documentation_uri: https://github.com/TheNotary/foobar_templates
|
|
135
|
-
source_code_uri: https://github.com/TheNotary/foobar_templates/tree/v2.0.1
|
|
135
|
+
source_code_uri: https://github.com/TheNotary/foobar_templates/tree/v2.0.1
|
|
136
136
|
rdoc_options: []
|
|
137
137
|
require_paths:
|
|
138
138
|
- lib
|