bundlegem 0.1.1 → 1.0.0

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: ca33941473a43a89745d74fba7d815ceae364f0f7514d8d63db538c3178cde54
4
- data.tar.gz: 5032d292e973052403c142088e5e358718e22e819b94af74e39f238a2daf9b28
3
+ metadata.gz: 87bffef9a7e1a004acb8ec2bb0a2c34e9f9bb7fd02082df470909955fae5ba7a
4
+ data.tar.gz: 0fdfb58410fed01c7cd8cdc665d4b98f1dfba8d387926ed210e123794a0880d1
5
5
  SHA512:
6
- metadata.gz: ba17e06fe7f97d46af8cbe3e8212d2094eb3bfbc925f546ae3598425c0a3185b1f99295b7e25dd6899c2ce1e412389a326e001798bf423a08a639707c8928e7a
7
- data.tar.gz: 89a207b4241e8ad8fd89e8b6bcc81489daece88e3dc14dc0325a960792f231a0d40ca6c6aeaf042912e0c6b3eeb9b1c98cacd416ae6b0d0c757b4fdfcc0f7b73
6
+ metadata.gz: 43b8c991915dbfa57dccb3e9b6de71c926369543833cd98065aec5e52f023c6763c4148fc69cba17573a243f9b7032cabab108fe18e8451b4dcc2cfff6fb9170
7
+ data.tar.gz: 9872c8314e8d54736de3fb006c71ebbb96fb3c0654c24fbab48ac7fc9f5c064897454b6b0f870f8ba893dbcc2174ff359be352291cdd0012bf5116145385b690
data/README.md CHANGED
@@ -1,33 +1,45 @@
1
1
  # BundleGem: A Gem Project Generator with User Defined Templates
2
-
3
- Note: Alot of the code here was extracted from Bundler's `bundle gem` command, so credits to the Bundler folks. Originally I planned to make the new features accessible to the Bundler team and so tried to keep the code as similar to their project as possible, but ultimately discovered that they don't want to grow this feature because good tools should do a single thing very well (manage dependencies), not many things (manage dependencies and also do random other helpful stuff). Also it's a profoundly common dependency meaning every change is high stakes.
2
+ [![Gem Version](https://badge.fury.io/rb/bundlegem.svg)](https://badge.fury.io/rb/bundlegem)
4
3
 
5
4
  The goal of the project is to allow users to define templates in the most native form to all technologist: Directory Structures, short commands, and helpful commands which make the gem's usage completely visible!
6
5
 
7
- The benefits of using this repo to create gems rather than bundler is that you can choose to create 'classes' of gems. By classes, I mean that there are different typs of 'gems', there are basic library gems, that are just code and can only be used from other code, there are command line application gems, those are gems that are run on the command line and include a binary file, and there are also web interface gems, those are gems which spin up a simple web interface and request that the user connect to it's server on what ever port it has spun up on. Depending on your field of specialty, you may be able to imagine other classes of gems that will aid you in your work.
6
+ The benefits of using this repo to create gems rather than bundler is that you can choose to create 'classes' of gems. By classes, I mean that there are different types of 'gems', there are basic library gems, that are just code and can only be used from other code, there are command line application gems, those are gems that are run on the command line and include a binary file, and there are also web interface gems, those are gems which spin up a simple web interface and request that the user connect to it's server on what ever port it has spun up on. Depending on your field of specialty, you may be able to imagine other classes of gems that will aid you in your work.
7
+
8
+ All of these 'classes of gems' as I refer to them, start out with a different code base, consistent with all other gems of the same class. This 'class based' approach to gem creation is different from the adaptive approach that other gem generators are based on.
8
9
 
9
- All of these 'classes of gems' as I refer to them, start out with a different code base, consistent with all other gems of the same class. This 'class based' aproach to gem creation is different from the addative approach that other gem genorators are based on.
10
+ The most beneficial aspect of this gem is that it allows you to specify exactly how you want your 'default starting gem' to look, rather than rely on what someone else thought would be generally helpful.
10
11
 
11
- The most benificial aspect of this gem is that it allows users to specify exactly how they want their 'default starting gem' to look like, rather than rely on what someone else thought their default starting gem should look like.
12
12
 
13
- ### Installation and usage
13
+ ### Installation
14
14
 
15
15
  First install it:
16
16
  ```
17
17
  gem install bundlegem
18
18
  ```
19
19
 
20
- Then create a new template for a gem class you expect to use more than once:
20
+ ### Configuration
21
+
22
+ Configuration comes from your gitconfig. At the user level, this is set at `~/.gitconfig`. These are the recommended minimal configurations to get the default templates to work ok:
23
+
21
24
  ```
22
- $ bundlegem --newtemplate
23
- Specify a name for your gem template: my_service
24
- Specify description:
25
- Specify template tag name [MISC]:
26
- Cloning base project structure into ~/.bundlegem/templates/my_service
27
- ...
28
- Complete!
25
+ [user]
26
+ email = me@example.com
27
+ name = Me
28
+ repo-domain = github.com
29
29
  ```
30
- You can now get to work making changes to the my_service gem. All you need to know is that any file that ends in .tt in that folder will be copied into new projects when you create a new project based on that template, however the .tt extension will obviously be stripped out of the resulting file name. Also, you can specify the `category` of the gem by editing the .bundlegem file in each template's root. Categories are just used for organizing the output when you run `bundlegem --list`. Here, I'll show you an example:
30
+
31
+
32
+ ### Usage
33
+
34
+ These commands will create a new gem named `project_name` in `/tmp/project_name`:
35
+
36
+ ```
37
+ $ cd /tmp
38
+ $ bundlegem project_name -t arduino
39
+ ```
40
+
41
+
42
+ ### List Available Templates
31
43
 
32
44
  ```
33
45
  $ bundlegem --list
@@ -40,26 +52,46 @@ MISC:
40
52
 
41
53
  EMBEDDED:
42
54
  arduino
43
-
44
55
  ```
45
56
 
46
- You'll now find a project skeleton in ~/.bundlegem/templates/my_service that you can customize to your liking.
57
+ You'll find a project skeleton in ~/.bundlegem/templates/my_service that you can customize to your liking.
58
+
47
59
 
60
+ ### Create Your Own Template
61
+
62
+ You can create a new template for a project class you expect to use more than once:
48
63
 
49
- Finally, create a new gem using your new gem template:
50
64
  ```
51
- $ cd /tmp
52
- $ bundlegem project_name -t my_service
65
+ $ bundlegem --newtemplate
66
+ Specify a name for your gem template: my_service
67
+ Specify description:
68
+ Specify template tag name [MISC]:
69
+ Cloning base project structure into ~/.bundlegem/templates/my_service
70
+ ...
71
+ Complete!
53
72
  ```
54
73
 
74
+ You can now get to work making changes to the my_service gem. All you need to know is that any file that ends in .tt in that folder will be copied into new projects when you create a new project based on that template, however the .tt extension will obviously be stripped out of the resulting file name.
75
+
76
+ ## TODO: Did you actually implement this?
77
+
78
+ Also, you can specify the `category` of the gem by editing the .bundlegem file in each template's root. Categories are just used for organizing the output when you run `bundlegem --list`. Here, I'll show you an example:
79
+
80
+
55
81
  ## Customizing Your Own Templates
56
82
 
57
83
  Place your own templates in `~/.bunglegem/templates`. You can populate it with examples by running `bundlegem --install-best-templates` which will effectively clone down a few sample git repos into the templates folder for you such as [Go-Cli](https://github.com/TheNotary/go-cli) for instance.
58
84
 
59
- You'll get a good idea as to the possibilities by inspecting the files in [templates](https://github.com/TheNotary/bundlegem/tree/master/lib/bundlegem/templates/newgem). Some quick tips follow:
85
+ You'll get a good idea as to the possibilities by inspecting the files in [templates](https://github.com/TheNotary/bundlegem/tree/master/lib/bundlegem/templates/cli_gem). Check out the [reference](/spec/data/variable_manifest_test.rb) test file to see what kind of interpolations are possible.
86
+
87
+ Quick Tips:
60
88
 
61
89
  - Files ending with a `.tt` extension will by written to new projects
62
90
  - File **names** containing `#{name}` will have that symbol replaced by the project name defined on the CLI
63
91
  - Within files, use `<%=config[:namespaced_path]%>` to have that reinterpreted as just the file name with underscores
64
92
  - Have a look [under the hood](https://github.com/TheNotary/bundlegem/blob/master/lib/bundlegem/cli/gem.rb#L30-L43) to see other options and the context where the ERB.new takes place.
65
93
 
94
+
95
+ ### Gem Backstory
96
+
97
+ A lot of the code here was extracted from Bundler's `bundle gem` command, so credits to the Bundler folks. Originally I planned to make the new features accessible to the Bundler team and went out of my way to keep the code as similar to their project as possible, but ultimately realized two thing. First they don't want to grow the project creation feature because good tools should do a single thing very well (manage dependencies), not many things (manage dependencies and also do random other helpful stuff). And second Bundler is a profoundly common dependency meaning every change is enormously high stakes.
data/config/config CHANGED
@@ -1,4 +1,4 @@
1
1
  # Comments made to this file will not be preserved
2
2
  ---
3
- default_template: newgem
3
+ default_template: cli_gem
4
4
  best_templates: https://github.com/TheNotary/arduino.git https://github.com/TheNotary/raspberry_pi_c.git https://github.com/TheNotary/docker_repo.git https://github.com/TheNotary/simple_frontend.git https://github.com/tymeart/node_cli https://github.com/TheNotary/java-cli-app https://github.com/TheNotary/java-gradle-cli-app https://github.com/TheNotary/python_library
@@ -1,4 +1,5 @@
1
1
  require 'pathname'
2
+ require 'yaml'
2
3
 
3
4
  module Bundlegem
4
5
  class CLI::Gem
@@ -10,29 +11,57 @@ module Bundlegem
10
11
 
11
12
  @name = @gem_name
12
13
  @target = Pathname.pwd.join(gem_name)
14
+ @template_src = TemplateManager.get_template_src(options)
15
+
16
+ @tconf = load_template_configs
13
17
 
14
18
  validate_ext_name if options[:ext]
15
19
  end
16
20
 
17
21
  def build_interpolation_config
22
+ pascal_name = name.tr('-', '_').split('_').map(&:capitalize).join
23
+ unprefixed_name = name.sub(/^#{@tconf[:prefix]}/, '')
18
24
  underscored_name = name.tr('-', '_')
19
- namespaced_path = name.tr('-', '/')
20
25
  constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] unless p.empty?}.join
21
26
  constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
22
27
  constant_array = constant_name.split('::')
23
28
  git_user_name = `git config user.name`.chomp
24
29
  git_user_email = `git config user.email`.chomp
25
30
 
31
+ # domain = provider.com
32
+ git_repo_domain = `git config user.repo-domain`.chomp
33
+
34
+ if git_repo_domain.empty?
35
+ git_repo_domain = "github.com"
36
+ end
37
+
38
+ if git_user_name.empty?
39
+ raise "git config user.name didn't return a value. Please double check your username configurations in ~/.gitconfig"
40
+ else
41
+ # path = provider.com/user/name
42
+ git_repo_path = "#{git_repo_domain}/#{git_user_name}/#{name}".downcase # downcasing for languages like go that are creative
43
+ end
44
+
45
+ # url = https://provider.com/user/name
46
+ git_repo_url = "https://#{git_repo_domain}/#{git_user_name}/#{name}"
47
+
26
48
  config = {
27
49
  :name => name,
50
+ :unprefixed_name => unprefixed_name,
51
+ :unprefixed_pascal=> unprefixed_name.tr('-', '_').split('_').map(&:capitalize).join,
28
52
  :underscored_name => underscored_name,
29
- :namespaced_path => namespaced_path,
53
+ :pascal_name => pascal_name,
54
+ :camel_name => pascal_name.sub(/^./, &:downcase),
55
+ :screamcase_name => name.tr('-', '_').upcase,
56
+ :namespaced_path => name.tr('-', '/'),
30
57
  :makefile_path => "#{underscored_name}/#{underscored_name}",
31
58
  :constant_name => constant_name,
32
59
  :constant_array => constant_array,
33
60
  :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
34
61
  :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
35
- :git_repo_url => git_user_name.empty? ? "TODO: set your git username so link to repo is automatic" : "https://github.com/#{git_user_name}/#{underscored_name}",
62
+ :git_repo_domain => git_repo_domain,
63
+ :git_repo_url => git_repo_url,
64
+ :git_repo_path => git_repo_path,
36
65
  :template => options[:template],
37
66
  :test => options[:test],
38
67
  :ext => options[:ext],
@@ -52,7 +81,7 @@ module Bundlegem
52
81
 
53
82
  template_src = match_template_src
54
83
  template_directories = dynamically_generate_template_directories
55
- templates = dynamically_generate_templates
84
+ templates = dynamically_generate_templates_files
56
85
 
57
86
  puts "Creating new project folder '#{name}'\n\n"
58
87
  create_template_directories(template_directories, target)
@@ -64,27 +93,37 @@ module Bundlegem
64
93
  # Bundler.ui.info "Initializing git repo in #{target}"
65
94
  Dir.chdir(target) { `git init`; `git add .` }
66
95
 
67
- # Disabled thanks to removal of thor, might not be helpful...
68
- #if options[:edit]
69
- # # Open gemspec in editor
70
- #
71
- # # thor.run("#{options["edit"]} \"#{target.join("#{name}.gemspec")}\"")
72
- #end
73
-
74
96
  puts "\nComplete."
75
97
  end
76
98
 
77
99
  private
78
100
 
101
+ def load_template_configs
102
+ template_config_path = File.join(@template_src, "bundlegem.yml")
103
+ if File.exist?(template_config_path)
104
+ t_config = YAML.load_file(template_config_path, symbolize_names: true)
105
+ else
106
+ t_config = {
107
+ purpose: "tool",
108
+ language: "go"
109
+ }
110
+ end
111
+
112
+ if t_config[:prefix].nil?
113
+ t_config[:prefix] = t_config[:purpose] ? "#{t_config[:purpose]}-" : ""
114
+ t_config[:prefix] += t_config[:language] ? "#{t_config[:language]}-" : ""
115
+ end
116
+
117
+ t_config
118
+ end
119
+
79
120
  # Returns a hash of source directory names and their destination mappings
80
121
  def dynamically_generate_template_directories
81
- template_src = TemplateManager.get_template_src(options)
82
-
83
122
  template_dirs = {}
84
- Dir.glob("#{template_src}/**/*").each do |f|
123
+ Dir.glob("#{@template_src}/**/*").each do |f|
85
124
  next unless File.directory? f
86
- base_path = f[template_src.length+1..-1]
87
- template_dirs.merge!(base_path => base_path.gsub('#{name}', "#{name}") )
125
+ base_path = f[@template_src.length+1..-1]
126
+ template_dirs.merge!(base_path => substitute_template_values(base_path))
88
127
  end
89
128
  template_dirs
90
129
  end
@@ -108,7 +147,6 @@ module Bundlegem
108
147
  'bin/console.tt' => "bin/console"
109
148
  }
110
149
 
111
-
112
150
  prompt_coc!(templates)
113
151
  prompt_mit!(templates, config)
114
152
  prompt_test_framework!(templates, config)
@@ -125,19 +163,24 @@ module Bundlegem
125
163
  templates
126
164
  end
127
165
 
166
+ # Applies every possible substitution within config to the fs_obj_name
167
+ def substitute_template_values(fs_obj_name)
168
+ config.keys.inject(fs_obj_name) do |accu, key|
169
+ if config[key].class == String
170
+ accu.gsub(/\#\{#{key.to_s}\}/, config[key])
171
+ else
172
+ accu
173
+ end
174
+ end
175
+ end
176
+
128
177
  # Figures out the translation between all the .tt file to their
129
178
  # destination names
130
- def dynamically_generate_templates
131
- template_src = TemplateManager.get_template_src(options)
132
-
179
+ def dynamically_generate_templates_files
133
180
  templates = {}
134
- Dir.glob("#{template_src}/**/{*,.*}.tt").each do |f|
135
- base_path = f[template_src.length+1..-1]
136
- templates.merge!(base_path => base_path
137
- .gsub(/\.tt$/, "")
138
- .gsub('#{name}', "#{name}")
139
- .gsub('#{underscored_name}', config[:underscored_name])
140
- )
181
+ Dir.glob("#{@template_src}/**/{*,.*}.tt").each do |f|
182
+ base_path = f[@template_src.length+1..-1]
183
+ templates.merge!( base_path => substitute_template_values(base_path).sub(/\.tt$/, "") )
141
184
  end
142
185
 
143
186
  raise_no_files_in_template_error! if templates.empty?
data/lib/bundlegem/cli.rb CHANGED
@@ -113,7 +113,7 @@ module Bundlegem
113
113
  method_option :mit, :type => :boolean, :desc => "Generate an MIT license file"
114
114
  method_option :test, :type => :string, :lazy_default => 'rspec', :aliases => '-t', :banner => "rspec",
115
115
  :desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config gem.test rspec`."
116
- method_option :template, :type => :string, :lazy_default => "newgem", :aliases => '-u', :banner => "default", :desc => "Generate a gem based on the user's predefined template."
116
+ method_option :template, :type => :string, :lazy_default => "cli_gem", :aliases => '-u', :banner => "default", :desc => "Generate a gem based on the user's predefined template."
117
117
  def gem(name)
118
118
  # options = {"bin"=>false, "ext"=>false}
119
119
  # name = "gem_name"
@@ -15,7 +15,7 @@ module Bundlegem
15
15
 
16
16
 
17
17
  def get_default_template_name
18
- "newgem"
18
+ "cli_gem"
19
19
  end
20
20
 
21
21
  def get_template_src(options)
@@ -1,40 +1,42 @@
1
1
  # coding: utf-8
2
2
  require_relative 'lib/<%=config[:namespaced_path]%>/version'
3
3
 
4
- Gem::Specification.new do |spec|
5
- spec.name = <%=config[:name].inspect%>
6
- spec.version = <%=config[:constant_name]%>::VERSION
7
- spec.authors = [<%=config[:author].inspect%>]
8
- spec.email = [<%=config[:email].inspect%>]
4
+ version = <%=config[:constant_name]%>::VERSION
9
5
 
10
- spec.summary = %q{A gem}
6
+ Gem::Specification.new do |s|
7
+ s.name = <%=config[:name].inspect%>
8
+ s.version = version
9
+ s.authors = [<%=config[:author].inspect%>]
10
+ s.email = [<%=config[:email].inspect%>]
11
11
 
12
- spec.homepage = "https://github.com/<%=config[:author]%>/<%=config[:name]%>"
13
- spec.required_ruby_version = ">= 3.0.0"
12
+ s.summary = %q{A gem}
14
13
 
15
- spec.metadata["allowed_push_host"] = "https://localhost.com" # prevents unexpected data loss
14
+ s.homepage = "https://github.com/<%=config[:author]%>/<%=config[:name]%>"
15
+ s.required_ruby_version = ">= 3.0.0"
16
16
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://localhost.com"
19
- spec.metadata["changelog_uri"] = "https://localhost.com"
17
+ s.metadata["allowed_push_host"] = "https://localhost.com" # prevents accidental gem pushes for private projects
18
+
19
+ s.metadata["homepage_uri"] = s.homepage
20
+ s.metadata["source_code_uri"] = s.homepage
21
+ s.metadata["changelog_uri"] = s.homepage
20
22
 
21
23
  # Specify which files should be added to the gem when it is released.
22
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
25
  gemspec = File.basename(__FILE__)
24
- spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
26
+ s.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
25
27
  ls.readlines("\x0", chomp: true).reject do |f|
26
28
  (f == gemspec) ||
27
29
  f.start_with?(*%w[bin/ test/ spec/ features/ .git .gitlab-ci.yml appveyor Gemfile])
28
30
  end
29
31
  end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
32
+ s.bindir = "exe"
33
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ s.require_paths = ["lib"]
33
35
 
34
- # spec.add_dependency "bundler", "~> <%= config[:bundler_version] %>"
36
+ # s.add_dependency "bundler", "~> <%= config[:bundler_version] %>"
35
37
 
36
- spec.add_development_dependency "bundler", "~> <%= config[:bundler_version] %>"
37
- spec.add_development_dependency "rake", "~> 13.0"
38
- spec.add_development_dependency "rspec"
39
- spec.add_development_dependency "pry"
38
+ s.add_development_dependency "bundler", "~> <%= config[:bundler_version] %>"
39
+ s.add_development_dependency "rake", "~> 13.0"
40
+ s.add_development_dependency "rspec"
41
+ s.add_development_dependency "pry"
40
42
  end
@@ -1,11 +1,19 @@
1
1
  This file shows all the variables in one place!
2
+ See "lib/bundlegem/templates/test_template/#{name}.rb.tt"
2
3
 
3
4
  config[:name]: <%= config[:name] %>
5
+ config[:unprefixed_name]: <%= config[:unprefixed_name] %>
6
+ config[:unprefixed_pascal]:<%= config[:unprefixed_pascal] %>
4
7
  config[:underscored_name]: <%= config[:underscored_name] %>
8
+ config[:pascal_name]: <%= config[:pascal_name] %>
9
+ config[:camel_name]: <%= config[:camel_name] %>
10
+ config[:screamcase_name]: <%= config[:screamcase_name] %>
5
11
  config[:namespaced_path]: <%= config[:namespaced_path] %>
6
12
  config[:makefile_path]: <%= config[:makefile_path] %>
7
13
  config[:constant_name]: <%= config[:constant_name] %>
8
14
  config[:constant_array]: <%= config[:constant_array] %>
9
15
  config[:author]: <%= config[:author] %>
10
16
  config[:email]: <%= config[:email] %>
17
+ config[:git_repo_domain]: <%= config[:git_repo_domain] %>
11
18
  config[:git_repo_url]: <%= config[:git_repo_url] %>
19
+ config[:git_repo_path]: <%= config[:git_repo_path] %>
@@ -0,0 +1,2 @@
1
+ purpose: tool
2
+ language: go
@@ -1,3 +1,3 @@
1
1
  module Bundlegem
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/bundlegem.rb CHANGED
@@ -19,9 +19,10 @@ module Bundlegem
19
19
  def list
20
20
  configurator = Configurator.new
21
21
  # search through builtin
22
- available_templates = [ { "predefined" => "newgem" },
23
- { "predefined" => "c_extension_gem" },
24
- { "predefined" => "cli_gem" }]
22
+ available_templates = [
23
+ { "predefined" => "cli_gem" },
24
+ { "predefined" => "c_extension_gem" },
25
+ ]
25
26
 
26
27
  # search through user downloaded
27
28
  available_templates += configurator.user_downloaded_templates
@@ -64,7 +65,7 @@ module Bundlegem
64
65
  template_name = args[1]
65
66
  template_name = prompt_for_template_name if template_name.nil?
66
67
 
67
- # Copy newgem from within the repo to ~/.bundlegem/templates/#{template_name}
68
+ # Copy template_name from within the repo to ~/.bundlegem/templates/#{template_name}
68
69
  TemplateManager.create_new_template(template_name)
69
70
  end
70
71
 
@@ -20,7 +20,7 @@ describe Bundlegem do
20
20
 
21
21
  list_output = Bundlegem.list
22
22
 
23
- expect(list_output).to eq " PREDEFINED:\n * newgem (default)\n c_extension_gem\n cli_gem\n\n MISC:\n empty_template\n\n"
23
+ expect(list_output).to eq " PREDEFINED:\n * cli_gem (default)\n c_extension_gem\n\n MISC:\n empty_template\n\n"
24
24
  expect(File.exist?("#{ENV['HOME']}/.bundlegem")).to be true
25
25
  end
26
26
 
@@ -49,7 +49,7 @@ describe Bundlegem do
49
49
  expect(File.exist?("#{@dst_dir}/#{gem_name}/ext/tmp_gem/#{gem_name}.c")).to be_truthy
50
50
  end
51
51
 
52
- it "has a useful dynamically_generate_templates metho" do
52
+ it "has a useful dynamically_generate_template_directories method" do
53
53
  options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test_template" }
54
54
  gem_name = "good-dog"
55
55
  my_gem = Bundlegem::CLI::Gem.new(options, gem_name)
@@ -57,16 +57,31 @@ describe Bundlegem do
57
57
  src_dst_map = my_gem.send('dynamically_generate_template_directories')
58
58
 
59
59
  expect(src_dst_map['#{name}']).to eq "good-dog"
60
- expect(src_dst_map['#{underscored_name}']).to eq '#{underscored_name}'
60
+ expect(src_dst_map['#{underscored_name}']).to eq "good_dog"
61
61
  expect(src_dst_map['simple_dir']).to eq 'simple_dir'
62
62
  end
63
63
 
64
- it "has a useful dynamically_generate_templates method" do
64
+ it "returns the expected interpolated string when substitute_template_values is called" do
65
65
  options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test_template" }
66
66
  gem_name = "good-dog"
67
67
  my_gem = Bundlegem::CLI::Gem.new(options, gem_name)
68
68
 
69
- src_dst_map = my_gem.send('dynamically_generate_templates')
69
+ short_path = '#{name}'
70
+ long_path = 'hello/#{name}/blah/#{name}'
71
+
72
+ short_interpolated_string = my_gem.send('substitute_template_values', short_path)
73
+ expect(short_interpolated_string).to eq gem_name
74
+
75
+ long_interpolated_string = my_gem.send('substitute_template_values', long_path)
76
+ expect(long_interpolated_string).to eq "hello/good-dog/blah/good-dog"
77
+ end
78
+
79
+ it "has a useful dynamically_generate_templates_files method" do
80
+ options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test_template" }
81
+ gem_name = "good-dog"
82
+ my_gem = Bundlegem::CLI::Gem.new(options, gem_name)
83
+
84
+ src_dst_map = my_gem.send('dynamically_generate_templates_files')
70
85
 
71
86
  expect(src_dst_map['#{name}/keep.tt']).to eq "good-dog/keep"
72
87
  expect(src_dst_map['#{name}.rb.tt']).to eq 'good-dog.rb'
@@ -82,6 +97,16 @@ describe Bundlegem do
82
97
  expect(File.read("#{@dst_dir}/#{gem_name}/#{gem_name}.rb")).to eq File.read("#{ENV['SPEC_DATA_DIR']}/variable_manifest_test.rb")
83
98
  end
84
99
 
100
+ it "has config[:unprefixed_name] removing purpose-tool- from name" do
101
+ options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test_template" }
102
+ gem_name = "tool-go-good-dog"
103
+ my_gem = Bundlegem::CLI::Gem.new(options, gem_name)
104
+
105
+ config = my_gem.build_interpolation_config
106
+
107
+ expect(config[:unprefixed_name]).to eq "good-dog"
108
+ end
109
+
85
110
  describe "install best templates" do
86
111
 
87
112
  before :each do
@@ -1,11 +1,19 @@
1
1
  This file shows all the variables in one place!
2
+ See "lib/bundlegem/templates/test_template/#{name}.rb.tt"
2
3
 
3
4
  config[:name]: good-dog
5
+ config[:unprefixed_name]: good-dog
6
+ config[:unprefixed_pascal]:GoodDog
4
7
  config[:underscored_name]: good_dog
8
+ config[:pascal_name]: GoodDog
9
+ config[:camel_name]: goodDog
10
+ config[:screamcase_name]: GOOD_DOG
5
11
  config[:namespaced_path]: good/dog
6
12
  config[:makefile_path]: good_dog/good_dog
7
13
  config[:constant_name]: Good::Dog
8
14
  config[:constant_array]: ["Good", "Dog"]
9
- config[:author]: test
15
+ config[:author]: Test
10
16
  config[:email]: you@example.com
11
- config[:git_repo_url]: https://github.com/test/good_dog
17
+ config[:git_repo_domain]: github.com
18
+ config[:git_repo_url]: https://github.com/Test/good-dog
19
+ config[:git_repo_path]: github.com/test/good-dog
data/spec/spec_helper.rb CHANGED
@@ -43,7 +43,7 @@ def reset_test_env
43
43
  FileUtils.mkdir_p @dst_dir
44
44
  FileUtils.mkdir_p @template_root
45
45
  FileUtils.cd @dst_dir
46
- auth_settings = 'git config --global user.email "you@example.com" && git config --global user.name "test"'
46
+ auth_settings = 'git config --global user.email "you@example.com" && git config --global user.name "Test"'
47
47
 
48
48
  `git config --global init.defaultBranch main && #{auth_settings}`
49
49
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundlegem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-27 00:00:00.000000000 Z
10
+ date: 2025-03-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor
@@ -198,6 +198,7 @@ files:
198
198
  - lib/bundlegem/templates/test_template/#{name}.rb.tt
199
199
  - lib/bundlegem/templates/test_template/#{name}/keep.tt
200
200
  - lib/bundlegem/templates/test_template/#{underscored_name}/keep.tt
201
+ - lib/bundlegem/templates/test_template/bundlegem.yml
201
202
  - lib/bundlegem/templates/test_template/simple_dir/keep.tt
202
203
  - lib/bundlegem/version.rb
203
204
  - spec/bundlegem_spec.rb
@@ -208,9 +209,9 @@ licenses:
208
209
  - MIT
209
210
  metadata:
210
211
  bug_tracker_uri: https://github.com/TheNotary/bundlegem/issues
211
- changelog_uri: https://github.com/TheNotary/bundlegem/releases/tag/v0.1.1
212
- documentation_uri: https://api.rubyonrails.org/v0.1.1/
213
- source_code_uri: https://github.com/TheNotary/bundlegem/tree/v0.1.1
212
+ changelog_uri: https://github.com/TheNotary/bundlegem/releases/tag/v1.0.0
213
+ documentation_uri: https://api.rubyonrails.org/v1.0.0/
214
+ source_code_uri: https://github.com/TheNotary/bundlegem/tree/v1.0.0
214
215
  rdoc_options: []
215
216
  require_paths:
216
217
  - lib