bundlegem 1.0.0 → 1.0.1.pre.rc.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87bffef9a7e1a004acb8ec2bb0a2c34e9f9bb7fd02082df470909955fae5ba7a
4
- data.tar.gz: 0fdfb58410fed01c7cd8cdc665d4b98f1dfba8d387926ed210e123794a0880d1
3
+ metadata.gz: 4cfe0b3615f641b31c021924c843d79bf38bcde9c437620ff2469166be8a0e79
4
+ data.tar.gz: 3c530f05af2a8aa4aa89c99fa03590978d33d61b559437b5f9d78a74c52fe594
5
5
  SHA512:
6
- metadata.gz: 43b8c991915dbfa57dccb3e9b6de71c926369543833cd98065aec5e52f023c6763c4148fc69cba17573a243f9b7032cabab108fe18e8451b4dcc2cfff6fb9170
7
- data.tar.gz: 9872c8314e8d54736de3fb006c71ebbb96fb3c0654c24fbab48ac7fc9f5c064897454b6b0f870f8ba893dbcc2174ff359be352291cdd0012bf5116145385b690
6
+ metadata.gz: 2d7bb6ae37d62d13d0b4dd4e15fc0d916b39b00e1f9feaf520ceb4fcdf63159d221f648fd547fd63cb28b027c56cfc0bedeb46c60b132ae9d78d9a8d6c6fe9e8
7
+ data.tar.gz: 27b0d466cba63e6638547dc583645b411536068401658b9a27e106c60faf05fc922d3e3021f0d2158a987bc80f34f7fadad04d75e005ba643d7388c8e8a6d576
data/bin/bundlegem CHANGED
@@ -28,14 +28,13 @@ if ARGV[0] == "--version" or ARGV[0] == "-v"
28
28
  exit 0
29
29
  end
30
30
 
31
- if ARGV[0] == "--newtemplate"
32
- puts "Sorry, I haven't been implemented, I don't have a lot of free time atm :("
31
+ if ARGV[0] == "--install-best-templates"
32
+ Bundlegem.install_best_templates
33
33
  exit 0
34
- Bundlegem.newtemplate(ARGV)
35
34
  end
36
35
 
37
- if ARGV[0] == "--install-best-templates"
38
- Bundlegem.install_best_templates
36
+ if ARGV[0] == "--to-template"
37
+ Bundlegem.dir_to_template
39
38
  exit 0
40
39
  end
41
40
 
data/changelog CHANGED
@@ -1,12 +1,11 @@
1
1
  ** 0.0.x **
2
2
  - Add prompt "Would you care to summarize your gem for documentation purposes? (y/[n])
3
3
  - Add prompt for specifying java package org name
4
- - CMD: --newtemplate to start new template
5
- - I'll need to write a basic starter template that is educational
6
4
  - Why have more than one built in template? Only one is needed for testing, the rest should
7
5
  be pulled from the web and made easily customizable by the users.
6
+ - Is thor used in this project or not???
8
7
 
9
- Completed on Master:
8
+ Completed on main:
10
9
  - Nothing yet
11
10
 
12
11
  ** 0.0.14 **
@@ -21,24 +20,16 @@ Completed on Master:
21
20
  - Feature: java project template added to best templates
22
21
  - Feature: python project template added to best templates
23
22
 
24
-
25
-
26
23
  ** 0.0.11 **
27
24
  - Bugfix: config[:bundler_version] was listing the version of bundlegem not bundler
28
25
 
29
-
30
-
31
26
  ** 0.0.10 **
32
27
  - Feature: tweaks built-in templates
33
28
 
34
-
35
-
36
29
  ** 0.0.9 **
37
30
  - Bugfix: there were misconfigurations with the Rakefiles for cli_gems and c_ect gems that were corrected
38
31
  - Feature: `--version` option added
39
32
 
40
-
41
-
42
33
  ** 0.0.8 **
43
34
 
44
35
  - Bugfix: fixes bug where git clone was attempted even when the a clone
@@ -49,8 +40,6 @@ Completed on Master:
49
40
  --install-best-templates
50
41
  - Bugfix: fixes bug where require pry was left in
51
42
 
52
-
53
-
54
43
  ** 0.0.7 **
55
44
 
56
45
  - Feature: Ability to load templates from github via --install-best-templates
@@ -64,8 +53,6 @@ Completed on Master:
64
53
  - Bugfix: cli_gem and c_ext_gem now show up in the list
65
54
  - Bugfix: cli_gem and c_ext_gem had typos fixed
66
55
 
67
-
68
-
69
56
  ** 0.0.6 **
70
57
  - Feature: List now indicates default template
71
58
  - CORE: Created TemplateManager for working with templates
@@ -73,8 +60,6 @@ Completed on Master:
73
60
  change directory into a test area for creating new gems.
74
61
  - BUG: newgem template didn't have a dot in .gitignore.tt
75
62
 
76
-
77
-
78
63
  ** 0.0.5 **
79
64
  - Bug in 0.0.3 that broke building template gems fixed
80
65
  * Template Directories part of code was being skipped for built in templates, but not all of it
@@ -82,26 +67,21 @@ Completed on Master:
82
67
  - Added integration test just to make sure the built-in templates can be generated without problems
83
68
  - Cleaned up internal API and how the binary works
84
69
 
85
-
86
70
  ** 0.0.4 **
87
71
  - Tell the user what files are being created
88
72
  - Created config['git_repo_url'] variable to be used in templates
89
73
 
90
-
91
74
  ** 0.0.3 **
92
75
  - CMD: --list to list templates (with descriptions)
93
76
  - Raise error when project name already exists, do not overwrite!
94
77
  - Raises error if none of the files in the template directory end in .tt
95
78
  - Create even empty folders
96
79
 
97
-
98
80
  ** 0.0.2 **
99
81
  - Added default gem template 'service'
100
82
  - Better syntax of bundlegem gem_name -t template_name
101
83
  - CMD: --help to display a help message
102
84
 
103
-
104
85
  ** 0.0.1 **
105
86
  - Very basic prototype that allows you to specify templates in
106
87
  ~/.bundlegem/templates
107
-
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/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
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
@@ -0,0 +1,5 @@
1
+ # The namespace CLI is taken by the legacy code :(
2
+ module Bundlegem::Cli
3
+ end
4
+
5
+ require 'bundlegem/cli/dir_to_template'
@@ -0,0 +1,24 @@
1
+ require 'find'
2
+
3
+
4
+ module Bundlegem::Cli::DirToTemplate
5
+ class << self
6
+
7
+ def go
8
+ validate_working_directory!
9
+ file_enumerator = Find.find('.')
10
+
11
+ Bundlegem::Core::DirToTemplate.🧙🪄! file_enumerator
12
+ end
13
+
14
+ private
15
+
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."
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -120,7 +120,8 @@ module Bundlegem
120
120
  # Returns a hash of source directory names and their destination mappings
121
121
  def dynamically_generate_template_directories
122
122
  template_dirs = {}
123
- Dir.glob("#{@template_src}/**/*").each do |f|
123
+ Dir.glob("#{@template_src}/**/*", File::FNM_DOTMATCH).each do |f|
124
+ next if f == "#{@template_src}/." || f == "#{@template_src}/.."
124
125
  next unless File.directory? f
125
126
  base_path = f[@template_src.length+1..-1]
126
127
  template_dirs.merge!(base_path => substitute_template_values(base_path))
@@ -178,7 +179,7 @@ module Bundlegem
178
179
  # destination names
179
180
  def dynamically_generate_templates_files
180
181
  templates = {}
181
- Dir.glob("#{@template_src}/**/{*,.*}.tt").each do |f|
182
+ Dir.glob("#{@template_src}/**/*.tt", File::FNM_DOTMATCH).each do |f|
182
183
  base_path = f[@template_src.length+1..-1]
183
184
  templates.merge!( base_path => substitute_template_values(base_path).sub(/\.tt$/, "") )
184
185
  end
@@ -207,12 +208,10 @@ module Bundlegem
207
208
  end
208
209
  end
209
210
 
210
-
211
211
  def resolve_name(name)
212
212
  Pathname.pwd.join(name).basename.to_s
213
213
  end
214
214
 
215
-
216
215
  def validate_ext_name
217
216
  return unless gem_name.index('-')
218
217
 
@@ -223,7 +222,6 @@ module Bundlegem
223
222
  exit 1
224
223
  end
225
224
 
226
-
227
225
  def bundler_dependency_version
228
226
  v = Gem::Version.new(Bundler::VERSION)
229
227
  req = v.segments[0..1]
@@ -232,9 +230,6 @@ module Bundlegem
232
230
  end
233
231
 
234
232
 
235
-
236
-
237
-
238
233
  #
239
234
  # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
240
235
  #
@@ -290,7 +285,7 @@ but no files within it ended in .tt. Did you forget to rename the extensions of
290
285
  Exiting...
291
286
  HEREDOC
292
287
  puts err_no_files_in_template
293
- exit
288
+ raise
294
289
  end
295
290
 
296
291
  def raise_project_with_that_name_already_exists!
@@ -301,14 +296,14 @@ Can't make project. Either delete that folder or choose a new project name
301
296
  Exiting...
302
297
  HEREDOC
303
298
  puts err_project_with_that_name_exists
304
- exit
299
+ raise
305
300
  end
306
301
 
307
302
  def raise_template_not_found!
308
303
  err_missing_template = "Could not find template folder '#{options["template"]}' in `~/.bundle/templates/`. Please check to make sure your desired template exists."
309
304
  puts err_missing_template
310
305
  Bundler.ui.error err_missing_template
311
- exit 1
306
+ raise
312
307
  end
313
308
 
314
309
 
@@ -400,10 +395,10 @@ Exiting...
400
395
  def ensure_safe_gem_name(name, constant_array)
401
396
  if name =~ /^\d/
402
397
  Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
403
- exit 1
398
+ raise
404
399
  elsif Object.const_defined?(constant_array.first)
405
400
  Bundler.ui.error "Invalid gem name #{name} constant #{constant_array.join("::")} is already in use. Please choose another gem name."
406
- exit 1
401
+ raise
407
402
  end
408
403
  end
409
404
 
@@ -4,7 +4,7 @@ require 'yaml'
4
4
  module Bundlegem
5
5
 
6
6
  class Configurator
7
- attr_accessor :user_defined_templates, :user_downloaded_templates, :config_file_data
7
+ attr_accessor :config_file_data
8
8
 
9
9
  def initialize
10
10
  @config_directory_root = "#{ENV['HOME']}/.bundlegem"
@@ -13,9 +13,6 @@ module Bundlegem
13
13
 
14
14
  create_config_file_if_needed!
15
15
 
16
- @user_defined_templates = get_user_defined_templates
17
- @user_downloaded_templates = get_user_downloaded_templates
18
-
19
16
  # load configurations from config file
20
17
  @config_file_data = YAML.load_file @config_file
21
18
  end
@@ -29,16 +26,7 @@ module Bundlegem
29
26
  File.write(@config_file, "# Comments made to this file will not be preserved\n#{YAML.dump(@config_file_data)}")
30
27
  end
31
28
 
32
- def built_in_templates
33
-
34
- end
35
-
36
- # not implemented yet
37
- def get_user_downloaded_templates
38
- []
39
- end
40
-
41
- def get_user_defined_templates
29
+ def collect_user_defined_templates
42
30
  user_definition_directory = @user_defined_templates_path
43
31
  template_dirs = Dir.entries(user_definition_directory).select do |entry|
44
32
  File.directory?(File.join(user_definition_directory, entry)) and !(entry =='.' || entry == '..')
@@ -51,20 +39,23 @@ module Bundlegem
51
39
 
52
40
  begin
53
41
  f = File.read("#{@user_defined_templates_path}/#{dir}/.bundlegem")
54
- /category:\s*([\w\s]*$)/ =~ f
55
42
 
56
- category = $1.chomp
43
+ category = parse_out(:category, f)
57
44
  rescue
58
45
  category = "MISC"
59
46
  end
60
47
 
61
48
  category = "MISC" if category.nil?
62
-
63
- pairs << {category => dir }
49
+ pairs << {category => dir.sub(/^template-/, "") }
64
50
  end
65
51
  pairs
66
52
  end
67
53
 
54
+ def parse_out(key, config_txt)
55
+ /#{key.to_s}:\s*([\w\s]*$)/ =~ config_txt
56
+ $1.chomp
57
+ end
58
+
68
59
  def create_config_file_if_needed!
69
60
  FileUtils.mkdir_p @user_defined_templates_path
70
61
  FileUtils.cp("#{SOURCE_ROOT}/config/config", @config_file) unless File.exist? @config_file
@@ -0,0 +1,9 @@
1
+ # This is the core logic for the app. CLI stuff should eventually get pulled
2
+ # out so the app is neat and the way I do CLI stuff lately.
3
+ module Bundlegem::Core
4
+ end
5
+
6
+ # I saw someone on the internet do requires this way so am giving it a spin :)
7
+ # It's a little odd, right? I'm not sure I like it yet but lets me go to
8
+ # town on namespaces and `class << self` definitions if I want...
9
+ require 'bundlegem/core/dir_to_template'
@@ -0,0 +1,59 @@
1
+ require 'find'
2
+ require 'open3'
3
+ require 'shellwords'
4
+
5
+
6
+ module Bundlegem::Core::DirToTemplate
7
+ class << self
8
+
9
+ # Takes in a file_enumerator such as Find.find('.') and
10
+ # renames all the files
11
+ def 🧙🪄! file_enumerator, template_name: "asdf-pkg", dry_run: false
12
+ files_changed = []
13
+ file_enumerator.each do |path|
14
+ next if should_skip?(path)
15
+
16
+ conduct_pkg_name_to_template_variable_replacements!(path)
17
+
18
+ new_path = "#{path}.tt"
19
+ File.rename(path, new_path) unless dry_run
20
+ files_changed << "Renamed: #{path} -> #{new_path}"
21
+ end
22
+ files_changed
23
+ end
24
+
25
+ private
26
+
27
+ def conduct_pkg_name_to_template_variable_replacements!(path)
28
+ # TODO: Conduct text replacements:
29
+ #
30
+ # 'asdf-pkg' -> '<%=config[:name]%>'
31
+ # 'asdf_pkg' -> '<%=config[:underscored_name]%>'
32
+ # 'ASDF_PKG' -> '<%=config[:screamcase_name]%>'
33
+ end
34
+
35
+ def should_skip?(path)
36
+ return false if path == "./.gitignore" && !File.exist?("#{path}.tt")
37
+
38
+ !File.file?(path) || # skip directories
39
+ path.end_with?('.tt') || # skip if the file is a .tt already
40
+ File.exist?("#{path}.tt") || # skip if a .tt variant of this file exists
41
+ path.start_with?('./.git') || # skip the .git directory
42
+ ignored_by_git?(path) || # skip things that are gitignored
43
+ path == "./.bundlegem" # skip the .bundlegem file
44
+ end
45
+
46
+ 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."
50
+ end
51
+ end
52
+
53
+ def ignored_by_git?(path)
54
+ stdout, _, status = Open3.capture3("git check-ignore #{Shellwords.escape(path)}")
55
+ status.success? && !stdout.strip.empty?
56
+ end
57
+
58
+ end
59
+ end
@@ -17,13 +17,13 @@ Usage Examples:
17
17
  # Download all my template files (configured in ~/.bundlegem/config)
18
18
  $ bundlegem --install-best-templates
19
19
 
20
- # not implemented, should create a new gem template in ~/.bundlegem/templates
21
- # that you'll love customizing to your personal preference
22
- $ bundlegem --newtemplate
20
+ # Convert the current directory which represents a working project into a
21
+ # template meaning all files will be renamed to *.tt unless a *.tt of that
22
+ # name already exists
23
+ $ bundlegem --to-template
23
24
 
24
- $ bundlegem --help # shows this message
25
+ # shows this message
26
+ $ bundlegem --help
25
27
  HEREDOC
26
28
 
27
-
28
-
29
29
  end
@@ -6,45 +6,51 @@ module Bundlegem
6
6
  # in the user's dir, the gem's builtin templates
7
7
  # (and on the web some day)
8
8
  class TemplateManager
9
-
10
9
  class << self
11
10
 
12
- def create_new_template(template_name)
13
-
14
- end
11
+ def internal_template_location() = File.expand_path("#{File.dirname(__FILE__)}/templates")
12
+ def custom_template_location() = File.expand_path("~/.bundlegem/templates")
13
+ def default_template_name() = "cli_gem"
15
14
 
15
+ def get_template_src(options)
16
+ template_name = options["template"] || default_template_name
17
+ template_location = template_exists_within_repo?(template_name) ?
18
+ internal_template_location :
19
+ custom_template_location
16
20
 
17
- def get_default_template_name
18
- "cli_gem"
21
+ resolve_template_path(template_location, template_name)
19
22
  end
20
23
 
21
- def get_template_src(options)
22
- template_name = options["template"].nil? ? get_default_template_name : options["template"]
23
-
24
- if template_exists_within_repo?(template_name)
25
- template_location = get_internal_template_location
26
- else
27
- template_location = File.expand_path("~/.bundlegem/templates")
28
- end
29
- template_src = "#{template_location}/#{template_name}"
24
+ def template_exists_within_repo?(template_name)
25
+ file_in_source?(template_name) || file_in_source?("template-#{template_name}")
30
26
  end
31
27
 
28
+ def resolve_template_path(location, name)
29
+ basic = "#{location}/#{name}"
30
+ prefixed = "#{location}/template-#{name}"
31
+
32
+ return basic if File.exist?(basic)
33
+ return prefixed if File.exist?(prefixed)
32
34
 
33
- def get_internal_template_location
34
- File.expand_path("#{File.dirname(__FILE__)}/templates")
35
+ basic # fallback, even if it doesn't exist, will be caught downstream
35
36
  end
36
37
 
37
- def template_exists_within_repo?(template_name)
38
- TemplateManager.file_in_source?(template_name)
38
+ def try_template_src_locations(template_location, template_name)
39
+ basic_form = "#{template_location}/#{template_name}"
40
+ prefixed_form = "#{template_location}/template-#{template_name}"
41
+
42
+ if File.exist?(basic_form)
43
+ return basic_form
44
+ elsif File.exist?(prefixed_form)
45
+ return prefixed_form
46
+ else
47
+ "#{template_location}/#{template_name}"
48
+ end
39
49
  end
40
50
 
41
- #
42
- # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
43
- #
44
51
  def find_in_source_paths(target)
45
- src_in_source_path = "#{File.dirname(__FILE__)}/templates/#{target}"
46
- return src_in_source_path if File.exist?(src_in_source_path)
47
- target # failed, hopefully full path to a user specified gem template file
52
+ path = "#{__dir__}/templates/#{target}"
53
+ File.exist?(path) ? path : target
48
54
  end
49
55
 
50
56
  # Get's path to 'target' from within the gem's "templates" folder
@@ -0,0 +1,19 @@
1
+ This file shows all the variables in one place!
2
+ See "lib/bundlegem/templates/test_template/#{name}.rb.tt"
3
+
4
+ config[:name]: <%= config[:name] %>
5
+ config[:unprefixed_name]: <%= config[:unprefixed_name] %>
6
+ config[:unprefixed_pascal]:<%= config[:unprefixed_pascal] %>
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] %>
11
+ config[:namespaced_path]: <%= config[:namespaced_path] %>
12
+ config[:makefile_path]: <%= config[:makefile_path] %>
13
+ config[:constant_name]: <%= config[:constant_name] %>
14
+ config[:constant_array]: <%= config[:constant_array] %>
15
+ config[:author]: <%= config[:author] %>
16
+ config[:email]: <%= config[:email] %>
17
+ config[:git_repo_domain]: <%= config[:git_repo_domain] %>
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 = "1.0.0"
2
+ VERSION = "1.0.1-rc.1"
3
3
  end
data/lib/bundlegem.rb CHANGED
@@ -3,12 +3,14 @@ require "bundlegem/strings"
3
3
  require 'bundlegem/configurator'
4
4
  require 'bundlegem/template_manager'
5
5
 
6
+ require 'bundlegem/core/core'
7
+ require 'bundlegem/cli/cli'
8
+
6
9
  require 'bundlegem/cli'
7
10
 
8
11
  SOURCE_ROOT = File.expand_path("#{File.dirname(__FILE__)}/..")
9
12
 
10
13
  module Bundlegem
11
-
12
14
  class << self
13
15
 
14
16
  def version
@@ -18,17 +20,7 @@ module Bundlegem
18
20
  # lists available templates
19
21
  def list
20
22
  configurator = Configurator.new
21
- # search through builtin
22
- available_templates = [
23
- { "predefined" => "cli_gem" },
24
- { "predefined" => "c_extension_gem" },
25
- ]
26
-
27
- # search through user downloaded
28
- available_templates += configurator.user_downloaded_templates
29
-
30
- # search through user defined
31
- available_templates += configurator.user_defined_templates
23
+ available_templates = configurator.collect_user_defined_templates
32
24
 
33
25
  available_templates = group_hashes_by_key(available_templates)
34
26
  output_string = convert_grouped_hashes_to_output(available_templates)
@@ -48,12 +40,15 @@ module Bundlegem
48
40
  cmd += " 2> /dev/null" if $test_env
49
41
  `#{cmd}`
50
42
  else
51
- # TODO:
52
- # Prompt to update the repo if they have a clean working state.
43
+ puts "Warning: Skipping, template already exists #{ENV['HOME']}/.bundlegem/templates/#{template_folder_name}"
53
44
  end
54
45
  end
55
46
  end
56
47
 
48
+ def dir_to_template
49
+ puts Cli::DirToTemplate.go
50
+ end
51
+
57
52
  def gem(options, gem_name)
58
53
  require 'bundlegem/cli'
59
54
  require 'bundlegem/cli/gem'
@@ -61,19 +56,6 @@ module Bundlegem
61
56
  Bundlegem::CLI::Gem.new(options, gem_name).run
62
57
  end
63
58
 
64
- def new_template(args)
65
- template_name = args[1]
66
- template_name = prompt_for_template_name if template_name.nil?
67
-
68
- # Copy template_name from within the repo to ~/.bundlegem/templates/#{template_name}
69
- TemplateManager.create_new_template(template_name)
70
- end
71
-
72
- def prompt_for_template_name
73
- puts "Please specify a name for your template: "
74
- template_name = STDIN.gets.chomp.strip.gsub(" ", "_")
75
- end
76
-
77
59
  # input: [ { "predefined" => "default" },
78
60
  # { "MISC" => "my_thing" },
79
61
  # { "prdefined" => "service" }
@@ -135,5 +117,4 @@ module Bundlegem
135
117
  end
136
118
 
137
119
  end
138
-
139
120
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'find'
3
+
4
+ module Bundlegem::Core
5
+ describe DirToTemplate do
6
+ before :each do
7
+ @mocked_home = "/tmp/bundlegem_mock_home"
8
+ @template_root = "#{@mocked_home}/.bundlegem/templates"
9
+ @dst_dir = "/tmp/bundle_gem_dst_dir"
10
+
11
+ reset_test_env
12
+ FileUtils.chdir(@dst_dir)
13
+ end
14
+
15
+ it 'is there' do
16
+ create_user_defined_template(category: "wizardly_tools")
17
+ files_changed = DirToTemplate.🧙🪄! Find.find('/tmp/temp/.'), dry_run: true
18
+
19
+ expect(files_changed.first).to eq "Renamed: /tmp/temp/./README.md -> /tmp/temp/./README.md.tt"
20
+ end
21
+ end
22
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bundlegem do
4
-
5
4
  before :each do
6
5
  @mocked_home = "/tmp/bundlegem_mock_home"
7
6
  @template_root = "#{@mocked_home}/.bundlegem/templates"
@@ -20,8 +19,8 @@ describe Bundlegem do
20
19
 
21
20
  list_output = Bundlegem.list
22
21
 
23
- expect(list_output).to eq " PREDEFINED:\n * cli_gem (default)\n c_extension_gem\n\n MISC:\n empty_template\n\n"
24
- expect(File.exist?("#{ENV['HOME']}/.bundlegem")).to be true
22
+ expect(list_output).to eq " MISC:\n empty_template\n\n"
23
+ expect(File).to exist("#{ENV['HOME']}/.bundlegem")
25
24
  end
26
25
 
27
26
  it "lists with good categories" do
@@ -29,7 +28,18 @@ describe Bundlegem do
29
28
  create_user_defined_template(category)
30
29
 
31
30
  list_output = Bundlegem.list
32
- expect(list_output.include?(category)).to be true
31
+ expect(list_output).to include category
32
+ end
33
+
34
+ it "lists omit the prefix 'template-' if present in repo" do
35
+ category = "ANYTHING"
36
+ full_template_name = "template-happy-burger"
37
+ create_user_defined_template(category, "template-happy-burger")
38
+
39
+ list_output = Bundlegem.list
40
+ # expect(list_output.include?(full_template_name)).to be false
41
+ expect(list_output).not_to include full_template_name
42
+ expect(list_output).to include "happy-burger"
33
43
  end
34
44
 
35
45
  # This bulids the default gem template
@@ -38,7 +48,7 @@ describe Bundlegem do
38
48
  gem_name = "tmp_gem"
39
49
 
40
50
  capture_stdout { Bundlegem.gem(options, gem_name) }
41
- expect(File.exist?("#{@dst_dir}/#{gem_name}/README.md")).to be_truthy
51
+ expect(File).to exist("#{@dst_dir}/#{gem_name}/README.md")
42
52
  end
43
53
 
44
54
  it "can generate the c_ext gem fine" do
@@ -46,9 +56,20 @@ describe Bundlegem do
46
56
  gem_name = "tmp_gem"
47
57
 
48
58
  capture_stdout { Bundlegem.gem(options, gem_name) }
49
- expect(File.exist?("#{@dst_dir}/#{gem_name}/ext/tmp_gem/#{gem_name}.c")).to be_truthy
59
+ expect(File).to exist("#{@dst_dir}/#{gem_name}/ext/tmp_gem/#{gem_name}.c")
50
60
  end
51
61
 
62
+
63
+ it "finds the template-test template even if the template- prefix was omitted" do
64
+ options = {"bin"=>false, "ext"=>false, :coc=> false, "template" => "test"}
65
+ gem_name = "tmp_gem"
66
+
67
+ capture_stdout { Bundlegem.gem(options, gem_name) }
68
+ expect(File).to exist("#{@dst_dir}/#{gem_name}/test_confirmed")
69
+ expect(File).to exist("#{@dst_dir}/#{gem_name}/.vscode/launch.json")
70
+ end
71
+
72
+
52
73
  it "has a useful dynamically_generate_template_directories method" do
53
74
  options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test_template" }
54
75
  gem_name = "good-dog"
@@ -108,20 +129,17 @@ describe Bundlegem do
108
129
  end
109
130
 
110
131
  describe "install best templates" do
111
-
112
132
  before :each do
113
133
  setup_mock_web_template
114
134
  end
115
-
116
135
  after :each do
117
136
  remove_mock_web_template
118
137
  end
119
138
 
120
139
  it "can download best templates from the web" do
121
140
  capture_stdout { Bundlegem.install_best_templates }
122
- expect(File.exist?("#{ENV['HOME']}/.bundlegem/templates/arduino/README.md")).to be_truthy
141
+ expect(File).to exist("#{ENV['HOME']}/.bundlegem/templates/template-arduino/README.md")
123
142
  end
124
-
125
143
  end
126
144
 
127
145
  end
data/spec/spec_helper.rb CHANGED
@@ -23,16 +23,18 @@ def remove_mock_web_template
23
23
  FileUtils.rm_rf("#{ENV['HOME']}/arduino.git")
24
24
  end
25
25
 
26
- def create_user_defined_template(category = nil)
27
- new_templates_dir = "#{@template_root}/empty_template"
26
+ def create_user_defined_template(category = nil, template_name = "empty_template")
27
+ new_template_dir = "#{@template_root}/#{template_name}"
28
28
 
29
29
  # Creates the gem template (empty folder)
30
- FileUtils.mkdir_p new_templates_dir
30
+ FileUtils.mkdir_p new_template_dir
31
31
 
32
32
  # Writes the category
33
- File.open("#{new_templates_dir}/.bundlegem", "w+") do |f|
33
+ File.open("#{new_template_dir}/.bundlegem", "w+") do |f|
34
34
  f.puts "category: #{category}" unless category.nil?
35
35
  end
36
+
37
+ new_template_dir
36
38
  end
37
39
 
38
40
 
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ module Bundlegem
4
+ describe TemplateManager do
5
+
6
+ it '#get_template_src returns the template-test even if prefix is omitted' do
7
+ options = { "bin"=>false, "ext"=>false, :coc=> false, "template" => "test" }
8
+
9
+ output = TemplateManager.get_template_src(options)
10
+
11
+ # binding.pry
12
+
13
+ expect(File.basename(output)).to eq "template-test"
14
+ end
15
+
16
+ end
17
+ 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: 1.0.0
4
+ version: 1.0.1.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-31 00:00:00.000000000 Z
10
+ date: 2025-05-11 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor
@@ -129,8 +129,12 @@ files:
129
129
  - config/config
130
130
  - lib/bundlegem.rb
131
131
  - lib/bundlegem/cli.rb
132
+ - lib/bundlegem/cli/cli.rb
133
+ - lib/bundlegem/cli/dir_to_template.rb
132
134
  - lib/bundlegem/cli/gem.rb
133
135
  - lib/bundlegem/configurator.rb
136
+ - lib/bundlegem/core/core.rb
137
+ - lib/bundlegem/core/dir_to_template.rb
134
138
  - lib/bundlegem/friendly_errors.rb
135
139
  - lib/bundlegem/strings.rb
136
140
  - lib/bundlegem/template_manager.rb
@@ -195,23 +199,32 @@ files:
195
199
  - lib/bundlegem/templates/newgem/rspec.tt
196
200
  - lib/bundlegem/templates/newgem/spec/#{name}_spec.rb.tt
197
201
  - lib/bundlegem/templates/newgem/spec/spec_helper.rb.tt
202
+ - lib/bundlegem/templates/template-test/#{name}.rb.tt
203
+ - lib/bundlegem/templates/template-test/#{name}/keep.tt
204
+ - lib/bundlegem/templates/template-test/#{underscored_name}/keep.tt
205
+ - lib/bundlegem/templates/template-test/.vscode/launch.json.tt
206
+ - lib/bundlegem/templates/template-test/bundlegem.yml
207
+ - lib/bundlegem/templates/template-test/simple_dir/keep.tt
208
+ - lib/bundlegem/templates/template-test/test_confirmed.tt
198
209
  - lib/bundlegem/templates/test_template/#{name}.rb.tt
199
210
  - lib/bundlegem/templates/test_template/#{name}/keep.tt
200
211
  - lib/bundlegem/templates/test_template/#{underscored_name}/keep.tt
201
212
  - lib/bundlegem/templates/test_template/bundlegem.yml
202
213
  - lib/bundlegem/templates/test_template/simple_dir/keep.tt
203
214
  - lib/bundlegem/version.rb
215
+ - spec/bundlegem/core/dir_to_template_spec.rb
204
216
  - spec/bundlegem_spec.rb
205
217
  - spec/data/variable_manifest_test.rb
206
218
  - spec/spec_helper.rb
219
+ - spec/template_manager_spec.rb
207
220
  homepage: https://github.com/thenotary/bundlegem
208
221
  licenses:
209
222
  - MIT
210
223
  metadata:
211
224
  bug_tracker_uri: https://github.com/TheNotary/bundlegem/issues
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
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
215
228
  rdoc_options: []
216
229
  require_paths:
217
230
  - lib
@@ -230,6 +243,8 @@ rubygems_version: 3.6.2
230
243
  specification_version: 4
231
244
  summary: This gem makes more gems!
232
245
  test_files:
246
+ - spec/bundlegem/core/dir_to_template_spec.rb
233
247
  - spec/bundlegem_spec.rb
234
248
  - spec/data/variable_manifest_test.rb
235
249
  - spec/spec_helper.rb
250
+ - spec/template_manager_spec.rb