foobar_templates 2.0.1.rc2 → 2.0.1.rc4

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: ef1e2cd0e959fef6c0ac4f5e4475675f8ea8c9b4c60d818ff3606ca94d2638a7
4
- data.tar.gz: e5d6e2ef6a066ad687a0509eb80d199f7d381307bf4ea2470f8f45f9c6eca274
3
+ metadata.gz: c933bd134506713bc01168f73ba617aeb22f7d3dc10a472455da258189136528
4
+ data.tar.gz: 0a5bcd41cff0ef149b6950e5a6868e444eaff671e7eef5043cf89ea5f24f917c
5
5
  SHA512:
6
- metadata.gz: 59087e7c7d265a35bc574ef126d11ff253b3c4970ce156e1d3edc0bbfb67d73f39f0894498f6594f9eb2e63e1fc7307803fe9e243bfe000fae7bc985d14b3484
7
- data.tar.gz: cd0ee89ddd0b52b6ab18c222deb7af07a933cc253428861ffd6e276943b9f70225e95ca8a95e4a502a89989358596d372020d75628fe532bfab9c048fe70f336
6
+ metadata.gz: a036cca148228d0cd1b6d7f1f8d0d81249108dd1aa4b029d146838b64b26ea018857a9f4a175f3e8c9bbc229f77035a68c4bc7dadbacae0e0a8b2ffaf38c3143
7
+ data.tar.gz: fa889a9eb2be2514d2b1347458b624491a460e1f7bc7faf25e7577a62da623e85ca29ec31b4ecb6633a4042d5ba75b66e37c72a21b2b3c67a88ef1a9c77ba3b9
data/bin/foobar_templates CHANGED
@@ -29,6 +29,10 @@ parser = OptionParser.new do |opts|
29
29
  exit
30
30
  end
31
31
 
32
+ opts.on("-p", "--performance", "Show performance metrics for template generation") do
33
+ options[:performance] = true
34
+ end
35
+
32
36
  opts.on("--install-public-templates", "Install public templates") do
33
37
  FoobarTemplates.install_public_templates
34
38
  exit
@@ -23,53 +23,67 @@ module FoobarTemplates::CLI
23
23
  end
24
24
 
25
25
  def config
26
- @config ||= build_interpolation_config
26
+ @config ||= time_it("build_interpolation_config") { build_interpolation_config }
27
27
  end
28
28
 
29
29
  def run
30
- puts "Beginning run" if $TRACE
31
- raise_project_with_that_name_already_exists! if File.exist?(target)
30
+ time_it("TOTAL run") do
31
+ puts "Beginning run" if $TRACE
32
+ raise_project_with_that_name_already_exists! if File.exist?(target)
32
33
 
33
- puts "ensure_safe_project_name" if $TRACE
34
- ensure_safe_project_name(name, config[:constant_array])
34
+ puts "ensure_safe_project_name" if $TRACE
35
+ time_it("ensure_safe_project_name") do
36
+ ensure_safe_project_name(name, config[:constant_array])
37
+ end
35
38
 
36
- puts "run_name_validation" if $TRACE
37
- run_name_validation
39
+ puts "run_name_validation" if $TRACE
40
+ time_it("run_name_validation") { run_name_validation }
38
41
 
39
- template_src = match_template_src
42
+ template_src = time_it("match_template_src") { match_template_src }
40
43
 
41
- puts "dynamically_generate_template_directories" if $TRACE
42
- time_it("dynamically_generate_template_directories") do
43
- @template_directories = dynamically_generate_template_directories
44
- end
44
+ puts "dynamically_generate_template_directories" if $TRACE
45
+ @template_directories = time_it("dynamically_generate_template_directories") do
46
+ dynamically_generate_template_directories
47
+ end
45
48
 
46
- puts "dynamically_generate_templates_files" if $TRACE
47
- templates = dynamically_generate_templates_files
49
+ puts "dynamically_generate_templates_files" if $TRACE
50
+ templates = time_it("dynamically_generate_templates_files") do
51
+ dynamically_generate_templates_files
52
+ end
48
53
 
49
- puts "Creating new project folder '#{name}'\n\n"
50
- create_template_directories(@template_directories, target)
54
+ puts "Creating new project folder '#{name}'\n\n"
55
+ time_it("create_template_directories") do
56
+ create_template_directories(@template_directories, target)
57
+ end
51
58
 
52
- templates.each do |src, dst|
53
- template("#{template_src}/#{src}", target.join(dst), config)
54
- end
59
+ time_it("write_template_files") do
60
+ templates.each do |src, dst|
61
+ template("#{template_src}/#{src}", target.join(dst), config)
62
+ end
63
+ end
55
64
 
56
- Dir.chdir(target) do
57
- if @configurator.always_perform_git_init || !inside_git_work_tree?
58
- `git init`
65
+ time_it("git_init_and_add") do
66
+ Dir.chdir(target) do
67
+ if @configurator.always_perform_git_init || !inside_git_work_tree?
68
+ `git init`
69
+ end
70
+ `git add .`
71
+ end
59
72
  end
60
- `git add .`
61
- end
62
73
 
63
- if @tconf[:bootstrap_command]
64
- puts "Executing bootstrap_command"
65
- cmd = safe_gsub_template_variables(@tconf[:bootstrap_command])
66
- puts cmd
67
- Dir.chdir(target) do
68
- `#{cmd}`
74
+ if @tconf[:bootstrap_command]
75
+ puts "Executing bootstrap_command"
76
+ cmd = safe_gsub_template_variables(@tconf[:bootstrap_command])
77
+ puts cmd
78
+ time_it("bootstrap_command") do
79
+ Dir.chdir(target) do
80
+ `#{cmd}`
81
+ end
82
+ end
69
83
  end
70
- end
71
84
 
72
- puts "\nComplete."
85
+ puts "\nComplete."
86
+ end
73
87
  end
74
88
 
75
89
  def build_interpolation_config
@@ -84,7 +98,9 @@ module FoobarTemplates::CLI
84
98
  git_user_email = `git config user.email`.chomp
85
99
 
86
100
  # Resolve domain values from ~/.foobar/config, prompting if needed
87
- required_domains = scan_template_for_required_domains
101
+ required_domains = time_it("scan_template_for_required_domains") do
102
+ scan_template_for_required_domains
103
+ end
88
104
  prompt_for_missing_domains(required_domains)
89
105
 
90
106
  registry_domain = @configurator.domain('registry_domain')
@@ -202,14 +218,11 @@ module FoobarTemplates::CLI
202
218
 
203
219
  def scan_template_for_required_domains
204
220
  all_placeholders = DOMAIN_PLACEHOLDERS.values.flatten
205
- pattern = Regexp.union(all_placeholders)
206
221
  found_placeholders = Set.new
207
222
 
208
- Dir.glob("#{@template_src}/**/*", File::FNM_DOTMATCH).each do |f|
223
+ template_relative_paths.each do |rel|
224
+ f = File.join(@template_src, rel)
209
225
  next unless File.file?(f)
210
- base_path = f[@template_src.length+1..-1]
211
- next if base_path.nil?
212
- next if base_path.start_with?(".git" + File::SEPARATOR) || base_path == ".git"
213
226
  next if binary_file?(f)
214
227
 
215
228
  content = File.read(f)
@@ -296,7 +309,9 @@ module FoobarTemplates::CLI
296
309
  # .git directory and any gitignored paths. Ignored directories are pruned
297
310
  # during traversal so their (potentially huge) contents are never walked.
298
311
  def template_relative_paths
299
- @template_relative_paths ||= collect_non_ignored_paths(@template_src)
312
+ @template_relative_paths ||= time_it("collect_non_ignored_paths") do
313
+ collect_non_ignored_paths(@template_src)
314
+ end
300
315
  end
301
316
 
302
317
  # Breadth-first walk that prunes ignored directories. One batched
@@ -476,11 +491,18 @@ Exiting...
476
491
  end
477
492
 
478
493
  def time_it(label = nil)
494
+ return yield unless performance?
495
+
479
496
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
480
- yield
497
+ result = yield
481
498
  end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
482
499
  elapsed_ms = ((end_time - start_time) * 1000).round(2)
483
500
  puts "#{label || 'Elapsed'}: #{elapsed_ms} ms"
501
+ result
502
+ end
503
+
504
+ def performance?
505
+ @options[:performance]
484
506
  end
485
507
 
486
508
  # This checks to see that the gem_name is a valid ruby gem name and will 'work'
@@ -1,3 +1,3 @@
1
1
  module FoobarTemplates
2
- VERSION = "2.0.1.rc2"
2
+ VERSION = "2.0.1.rc4"
3
3
  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.rc2
4
+ version: 2.0.1.rc4
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.rc2
133
+ changelog_uri: https://github.com/TheNotary/foobar_templates/releases/tag/v2.0.1.rc4
134
134
  documentation_uri: https://github.com/TheNotary/foobar_templates
135
- source_code_uri: https://github.com/TheNotary/foobar_templates/tree/v2.0.1.rc2
135
+ source_code_uri: https://github.com/TheNotary/foobar_templates/tree/v2.0.1.rc4
136
136
  rdoc_options: []
137
137
  require_paths:
138
138
  - lib