bundlegem 1.0.1.pre.rc.1 → 1.1.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: 4cfe0b3615f641b31c021924c843d79bf38bcde9c437620ff2469166be8a0e79
4
- data.tar.gz: 3c530f05af2a8aa4aa89c99fa03590978d33d61b559437b5f9d78a74c52fe594
3
+ metadata.gz: 59cedb35eb5e27205162bbf4cab34f99d0269f2becdaa7e0544b614bad7510eb
4
+ data.tar.gz: 79334971e8ac017e651e5aeab129ede8e5be7b8ba4491fdcbed360d9286ce795
5
5
  SHA512:
6
- metadata.gz: 2d7bb6ae37d62d13d0b4dd4e15fc0d916b39b00e1f9feaf520ceb4fcdf63159d221f648fd547fd63cb28b027c56cfc0bedeb46c60b132ae9d78d9a8d6c6fe9e8
7
- data.tar.gz: 27b0d466cba63e6638547dc583645b411536068401658b9a27e106c60faf05fc922d3e3021f0d2158a987bc80f34f7fadad04d75e005ba643d7388c8e8a6d576
6
+ metadata.gz: c728247b2e279c30b46efebb45d26f52cca5c052286bedc04a55f190b3c88242db8fe4b5e4ae7e22210c67c0fb84d2e80569b43da151d24e0a63b469925d7bfc
7
+ data.tar.gz: cf6e1c50c39fa472fced36fc8175e716e43d7d61563f3e0efdce4a83ddecdc72733b0a956c9a111e1f1c568285d3e7d8171740af8d2864a7540b94b5a1b2df2a
data/README.md CHANGED
@@ -57,7 +57,7 @@ EMBEDDED:
57
57
  You'll find a project skeleton in ~/.bundlegem/templates/my_service that you can customize to your liking.
58
58
 
59
59
 
60
- ### Create Your Own Template
60
+ ## Create Your Own Template
61
61
 
62
62
  You can create a new template for a project class you expect to use more than once:
63
63
 
@@ -73,12 +73,12 @@ Cloning base project structure into ~/.bundlegem/templates/my_service
73
73
 
74
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
75
 
76
- ## TODO: Did you actually implement this?
76
+ ### Categorizing Your Template
77
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:
78
+ Also, you can specify the `category` of the gem by editing the bundlegem.yml 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
79
 
80
80
 
81
- ## Customizing Your Own Templates
81
+ ### Customizing Your Own Templates
82
82
 
83
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.
84
84
 
@@ -92,6 +92,6 @@ Quick Tips:
92
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.
93
93
 
94
94
 
95
- ### Gem Backstory
95
+ ## Gem Backstory
96
96
 
97
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/changelog CHANGED
@@ -1,12 +1,16 @@
1
- ** 0.0.x **
2
- - Add prompt "Would you care to summarize your gem for documentation purposes? (y/[n])
3
- - Add prompt for specifying java package org name
4
- - Why have more than one built in template? Only one is needed for testing, the rest should
5
- be pulled from the web and made easily customizable by the users.
6
- - Is thor used in this project or not???
7
-
8
- Completed on main:
9
- - Nothing yet
1
+ ** Planned 0.1.x **
2
+ - TBD
3
+
4
+ ** 0.1.0 **
5
+ - Feature: Drops .bundlegem file in favor of bundlegem.yml in templates
6
+ - Feature: Introduces `--to-template` switch to add a `.tt` extension to all files in the current directory
7
+ - Feature: Enables execution of bootstrap_commands listing in bundlegem.yml
8
+ - Feature: Cleans out built-in templates in favor of externally managed templates
9
+ - Bugfix: Prevents creation of template files that are gitignored
10
+
11
+ ** 1.0.0 **
12
+ - Feature: Greatly expands the template interpolation values
13
+ - Bugfix: misc cleanup
10
14
 
11
15
  ** 0.0.14 **
12
16
  - Bugfix: The project didn't work with ruby 3 due to use of the method `exists?`???
data/config/config CHANGED
@@ -1,4 +1,4 @@
1
1
  # Comments made to this file will not be preserved
2
2
  ---
3
3
  default_template: cli_gem
4
- best_templates: https://github.com/TheNotary/template-ruby-cli-gem https://github.com/TheNotary/template-arduino.git https://github.com/TheNotary/template-raspberry-pi-c.git https://github.com/TheNotary/docker_repo.git https://github.com/TheNotary/template-html-css-js.git https://github.com/TheNotary/template-java-gradle-cli-app https://github.com/TheNotary/template-python-library
4
+ best_templates: https://github.com/TheNotary/template-ruby-cli-gem https://github.com/TheNotary/template-arduino.git https://github.com/TheNotary/template-docker-repo.git https://github.com/TheNotary/template-html-css-js.git https://github.com/TheNotary/template-java-gradle-cli-app
@@ -14,9 +14,9 @@ module Bundlegem::Cli::DirToTemplate
14
14
  private
15
15
 
16
16
  def validate_working_directory!
17
- # check for the existence of a .bundlegem file which won't ordinarily exist
18
- if !File.exist?(".bundlegem")
19
- raise "error: .bundlegem file not found in current directory. Create it or run this command in the folder you thought you were in."
17
+ # check for the existence of a bundlegem.yml file which won't ordinarily exist
18
+ if !File.exist?("bundlegem.yml")
19
+ raise "error: bundlegem.yml file not found in current directory. Create it or run this command in the folder you thought you were in."
20
20
  end
21
21
  end
22
22
 
@@ -93,13 +93,29 @@ module Bundlegem
93
93
  # Bundler.ui.info "Initializing git repo in #{target}"
94
94
  Dir.chdir(target) { `git init`; `git add .` }
95
95
 
96
+ if @tconf[:bootstrap_command]
97
+ puts "Executing bootstrap_command"
98
+ puts @tconf[:bootstrap_command]
99
+ `#{@tconf[:bootstrap_command]}`
100
+ end
101
+
96
102
  puts "\nComplete."
97
103
  end
98
104
 
99
105
  private
100
106
 
107
+ # TODO: Extract these notes to the docs or delete them
108
+ # The language and purpose configurations of the bundlegem.yml file
109
+ # can be used to make sure when you create a folder named
110
+ # `bundlegem -t blah tool-go-ollama-find`, the internal name
111
+ # that the app has for itself can become simply `ollama-find`, dropping the prefix
112
+ # which is intended to exist only at the repostory name and shouldn't impact
113
+ # the package naming... much...
114
+ #
115
+ # I didn't document this feature originally so it may not have been fully fleshed out...
101
116
  def load_template_configs
102
117
  template_config_path = File.join(@template_src, "bundlegem.yml")
118
+
103
119
  if File.exist?(template_config_path)
104
120
  t_config = YAML.load_file(template_config_path, symbolize_names: true)
105
121
  else
@@ -124,6 +140,7 @@ module Bundlegem
124
140
  next if f == "#{@template_src}/." || f == "#{@template_src}/.."
125
141
  next unless File.directory? f
126
142
  base_path = f[@template_src.length+1..-1]
143
+ next if ignored_by_git?(@template_src, base_path)
127
144
  template_dirs.merge!(base_path => substitute_template_values(base_path))
128
145
  end
129
146
  template_dirs
@@ -137,13 +154,13 @@ module Bundlegem
137
154
  def generate_templates_for_built_in_gems(config)
138
155
  # Hmmm... generate dynamically instead? Yes, overwritten below
139
156
  templates = {
140
- 'Gemfile.tt' => "Gemfile",
157
+ 'Gemfile.tt' => "Gemfile",
141
158
  'changelog.tt' => "changelog",
142
159
  'gitignore.tt' => ".gitignore",
143
160
  'lib/#{name}.rb.tt' => "lib/#{config[:namespaced_path]}.rb",
144
161
  'lib/#{name}/version.rb.tt' => "lib/#{config[:namespaced_path]}/version.rb",
145
162
  '#{name}.gemspec.tt' => "#{config[:name]}.gemspec",
146
- 'Rakefile.tt' => "Rakefile",
163
+ 'Rakefile.tt' => "Rakefile",
147
164
  'README.md.tt' => "README.md",
148
165
  'bin/console.tt' => "bin/console"
149
166
  }
@@ -181,6 +198,7 @@ module Bundlegem
181
198
  templates = {}
182
199
  Dir.glob("#{@template_src}/**/*.tt", File::FNM_DOTMATCH).each do |f|
183
200
  base_path = f[@template_src.length+1..-1]
201
+ next if ignored_by_git?(@template_src, base_path)
184
202
  templates.merge!( base_path => substitute_template_values(base_path).sub(/\.tt$/, "") )
185
203
  end
186
204
 
@@ -189,6 +207,11 @@ module Bundlegem
189
207
  return templates
190
208
  end
191
209
 
210
+ def ignored_by_git?(repo_root, path)
211
+ stdout, _, status = Open3.capture3("git -C #{repo_root} check-ignore #{Shellwords.escape(path)}")
212
+ status.success? && !stdout.strip.empty?
213
+ end
214
+
192
215
  def create_template_directories(template_directories, target)
193
216
  template_directories.each do |k,v|
194
217
  d = "#{target}/#{v}"
@@ -28,25 +28,22 @@ module Bundlegem
28
28
 
29
29
  def collect_user_defined_templates
30
30
  user_definition_directory = @user_defined_templates_path
31
- template_dirs = Dir.entries(user_definition_directory).select do |entry|
31
+ templates = Dir.entries(user_definition_directory).select do |entry|
32
32
  File.directory?(File.join(user_definition_directory, entry)) and !(entry =='.' || entry == '..')
33
33
  end
34
34
 
35
35
  pairs = []
36
- template_dirs.each do |dir|
37
- # open the dir and read the .bundlegem file to see what class of file it is
38
- # If there's no .bundlegem file in there, mark it misc
39
-
40
- begin
41
- f = File.read("#{@user_defined_templates_path}/#{dir}/.bundlegem")
42
-
43
- category = parse_out(:category, f)
44
- rescue
45
- category = "MISC"
36
+ templates.each do |template_path|
37
+ # open the template_path and read the bundlegem.yml file to see what class of file it is
38
+ # If there's no bundlegem.yml file in there, mark it misc
39
+
40
+ template_config_path = "#{@user_defined_templates_path}/#{template_path}/bundlegem.yml"
41
+ if File.exist?(template_config_path)
42
+ obj = YAML.load_file(template_config_path, symbolize_names: true) || { category: "misc" }
43
+ category = obj[:category]
46
44
  end
47
45
 
48
- category = "MISC" if category.nil?
49
- pairs << {category => dir.sub(/^template-/, "") }
46
+ pairs << {category => template_path.sub(/^template-/, "") }
50
47
  end
51
48
  pairs
52
49
  end
@@ -17,6 +17,8 @@ module Bundlegem::Core::DirToTemplate
17
17
 
18
18
  new_path = "#{path}.tt"
19
19
  File.rename(path, new_path) unless dry_run
20
+ repopulate_gitignore(path, new_path) unless dry_run
21
+
20
22
  files_changed << "Renamed: #{path} -> #{new_path}"
21
23
  end
22
24
  files_changed
@@ -24,6 +26,13 @@ module Bundlegem::Core::DirToTemplate
24
26
 
25
27
  private
26
28
 
29
+ # Hack for putting the gitignore file back if it's been templatized...
30
+ def repopulate_gitignore(path, new_path)
31
+ if new_path == "./.gitignore.tt"
32
+ FileUtils.cp(new_path, path)
33
+ end
34
+ end
35
+
27
36
  def conduct_pkg_name_to_template_variable_replacements!(path)
28
37
  # TODO: Conduct text replacements:
29
38
  #
@@ -33,20 +42,18 @@ module Bundlegem::Core::DirToTemplate
33
42
  end
34
43
 
35
44
  def should_skip?(path)
36
- return false if path == "./.gitignore" && !File.exist?("#{path}.tt")
37
-
38
45
  !File.file?(path) || # skip directories
39
46
  path.end_with?('.tt') || # skip if the file is a .tt already
40
47
  File.exist?("#{path}.tt") || # skip if a .tt variant of this file exists
41
- path.start_with?('./.git') || # skip the .git directory
48
+ path.start_with?('./.git/') || # skip the .git directory
42
49
  ignored_by_git?(path) || # skip things that are gitignored
43
- path == "./.bundlegem" # skip the .bundlegem file
50
+ path == "./bundlegem.yml" # skip the bundlegem.yml file
44
51
  end
45
52
 
46
53
  def validate_working_directory!
47
- # check for the existence of a .bundlegem file which won't ordinarily exist
48
- if !File.exist?(".bundlegem")
49
- raise "error: .bundlegem file not found in current directory. Create it or run this command in the folder you thought you were in."
54
+ # check for the existence of a bundlegem.yml file which won't ordinarily exist
55
+ if !File.exist?("bundlegem.yml")
56
+ raise "error: bundlegem.yml file not found in current directory. Create it or run this command in the folder you thought you were in."
50
57
  end
51
58
  end
52
59
 
@@ -5,17 +5,14 @@ Use bundlegem to start a new project folder based on a predefined template.
5
5
 
6
6
  Usage Examples:
7
7
 
8
- # Make a new ruby gem
9
- $ bundlegem your_gem_name
8
+ # Download all my template files (configured in ~/.bundlegem/config)
9
+ $ bundlegem --install-best-templates
10
10
 
11
11
  # List available teplates
12
12
  $ bundlegem --list
13
13
 
14
14
  # Create a ruby gem project using the built in service template
15
- $ bundlegem your_gem_name -t service
16
-
17
- # Download all my template files (configured in ~/.bundlegem/config)
18
- $ bundlegem --install-best-templates
15
+ $ bundlegem --template service your_gem_name
19
16
 
20
17
  # Convert the current directory which represents a working project into a
21
18
  # template meaning all files will be renamed to *.tt unless a *.tt of that
@@ -1,3 +1,3 @@
1
1
  module Bundlegem
2
- VERSION = "1.0.1-rc.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -10,13 +10,31 @@ module Bundlegem::Core
10
10
 
11
11
  reset_test_env
12
12
  FileUtils.chdir(@dst_dir)
13
+ @initial_dir = FileUtils.pwd
13
14
  end
14
15
 
15
- it 'is there' do
16
- create_user_defined_template(category: "wizardly_tools")
17
- files_changed = DirToTemplate.🧙🪄! Find.find('/tmp/temp/.'), dry_run: true
16
+ after :each do
17
+ FileUtils.cd(@initial_dir)
18
+ end
19
+
20
+ it 'will rename the expected files and ignore the ones that should be ignored' do
21
+ template_dir = create_user_defined_template(category: "wizardly_tools")
22
+
23
+ gitignored_file = "something.toignore"
24
+
25
+ # Setup test template
26
+ FileUtils.cd(template_dir)
27
+ FileUtils.touch("#{template_dir}/README.md")
28
+ FileUtils.touch("#{template_dir}/#{gitignored_file}")
29
+ File.write("#{template_dir}/.gitignore", gitignored_file)
30
+ `git init`
31
+
32
+ files_changed = DirToTemplate.🧙🪄! Find.find("."), dry_run: true
18
33
 
19
- expect(files_changed.first).to eq "Renamed: /tmp/temp/./README.md -> /tmp/temp/./README.md.tt"
34
+ expect(files_changed[0]).to eq "Renamed: ./.gitignore -> ./.gitignore.tt"
35
+ expect(files_changed[1]).to eq "Renamed: ./README.md -> ./README.md.tt"
36
+ expect(File).to exist "#{template_dir}/.gitignore"
37
+ expect(files_changed.count).to eq 2
20
38
  end
21
39
  end
22
40
  end
@@ -14,6 +14,8 @@ describe Bundlegem do
14
14
  expect(Bundlegem::VERSION).not_to be nil
15
15
  end
16
16
 
17
+ # List
18
+
17
19
  it 'creates a config file if needed and lists properly' do
18
20
  create_user_defined_template
19
21
 
@@ -42,6 +44,8 @@ describe Bundlegem do
42
44
  expect(list_output).to include "happy-burger"
43
45
  end
44
46
 
47
+ # Generate
48
+
45
49
  # This bulids the default gem template
46
50
  it "can generate the default built-in gem fine" do
47
51
  options = {"bin"=>false, "ext"=>false, :coc=> false}
@@ -59,7 +63,6 @@ describe Bundlegem do
59
63
  expect(File).to exist("#{@dst_dir}/#{gem_name}/ext/tmp_gem/#{gem_name}.c")
60
64
  end
61
65
 
62
-
63
66
  it "finds the template-test template even if the template- prefix was omitted" do
64
67
  options = {"bin"=>false, "ext"=>false, :coc=> false, "template" => "test"}
65
68
  gem_name = "tmp_gem"
@@ -69,7 +72,6 @@ describe Bundlegem do
69
72
  expect(File).to exist("#{@dst_dir}/#{gem_name}/.vscode/launch.json")
70
73
  end
71
74
 
72
-
73
75
  it "has a useful dynamically_generate_template_directories method" do
74
76
  options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test_template" }
75
77
  gem_name = "good-dog"
@@ -110,6 +112,37 @@ describe Bundlegem do
110
112
  expect(src_dst_map['simple_dir/keep.tt']).to eq 'simple_dir/keep'
111
113
  end
112
114
 
115
+ it "won't generate template files that are listed under the gitignore" do
116
+ template_dir = create_user_defined_template("testing", "template-user-supplied")
117
+ options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "template-user-supplied" }
118
+ gem_name = "good-dog"
119
+
120
+ File.write("#{template_dir}/.gitignore", "node_modules/")
121
+ File.write("#{template_dir}/README.md.tt", "Hello")
122
+ FileUtils.mkdir("#{template_dir}/node_modules")
123
+ File.write("#{template_dir}/node_modules/dont_template.rb.tt", "I must not be interpretted")
124
+ `git init #{template_dir}`
125
+
126
+ capture_stdout { Bundlegem.gem(options, gem_name) }
127
+
128
+ expect(File).not_to exist "#{@dst_dir}/#{gem_name}/node_modules/dont_template.rb"
129
+ expect(File).not_to exist "#{@dst_dir}/#{gem_name}/node_modules"
130
+ end
131
+
132
+ it "executes the bootstrap_command if supplied" do
133
+ template_dir = create_user_defined_template("testing", "template-user-supplied")
134
+ options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "template-user-supplied" }
135
+ gem_name = "good-dog"
136
+
137
+ File.write("#{template_dir}/bundlegem.yml", "bootstrap_command: echo hihihi")
138
+ File.write("#{template_dir}/README.md.tt", "# Readme...")
139
+ `git init #{template_dir}`
140
+
141
+ output = capture_stdout { Bundlegem.gem(options, gem_name) }
142
+
143
+ expect(output).to include "hihihi"
144
+ end
145
+
113
146
  it "has a test proving every interpolation in one file" do
114
147
  options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test_template" }
115
148
  gem_name = "good-dog"
data/spec/spec_helper.rb CHANGED
@@ -30,7 +30,7 @@ def create_user_defined_template(category = nil, template_name = "empty_template
30
30
  FileUtils.mkdir_p new_template_dir
31
31
 
32
32
  # Writes the category
33
- File.open("#{new_template_dir}/.bundlegem", "w+") do |f|
33
+ File.open("#{new_template_dir}/bundlegem.yml", "w+") do |f|
34
34
  f.puts "category: #{category}" unless category.nil?
35
35
  end
36
36
 
@@ -8,8 +8,6 @@ module Bundlegem
8
8
 
9
9
  output = TemplateManager.get_template_src(options)
10
10
 
11
- # binding.pry
12
-
13
11
  expect(File.basename(output)).to eq "template-test"
14
12
  end
15
13
 
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: 1.0.1.pre.rc.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-11 00:00:00.000000000 Z
10
+ date: 2025-06-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor
@@ -222,9 +222,9 @@ licenses:
222
222
  - MIT
223
223
  metadata:
224
224
  bug_tracker_uri: https://github.com/TheNotary/bundlegem/issues
225
- changelog_uri: https://github.com/TheNotary/bundlegem/releases/tag/v1.0.1-rc.1
226
- documentation_uri: https://api.rubyonrails.org/v1.0.1-rc.1/
227
- source_code_uri: https://github.com/TheNotary/bundlegem/tree/v1.0.1-rc.1
225
+ changelog_uri: https://github.com/TheNotary/bundlegem/releases/tag/v1.1.0
226
+ documentation_uri: https://api.rubyonrails.org/v1.1.0/
227
+ source_code_uri: https://github.com/TheNotary/bundlegem/tree/v1.1.0
228
228
  rdoc_options: []
229
229
  require_paths:
230
230
  - lib