Skip to content

Commit

Permalink
Change to extract empty directory mapping to the templater
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Aug 22, 2020
1 parent 7bb47fe commit 72447ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/tty/commands/add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def execute(input: $stdin, output: $stdout)
@templater.add_mapping("#{test_dir}/unit/command_#{test_dir}.rb.tt",
"#{test_dir}/unit/#{cmd_name_path}_#{test_dir}.rb")
@templater.add_mapping("command.rb.tt", cmd_file)
@templater.add_mapping("gitkeep.tt", "#{cmd_template_path}/.gitkeep")
@templater.add_empty_directory_mapping(cmd_template_path)
@templater.generate(template_context, file_options)

if !cmd_exists?(cli_content)
Expand Down Expand Up @@ -114,7 +114,7 @@ def execute(input: $stdin, output: $stdout)
@templater.add_mapping("namespace.rb.tt", cmd_file)
end
@templater.add_mapping("command.rb.tt", subcmd_file)
@templater.add_mapping("gitkeep.tt", "#{subcmd_template_path}/.gitkeep")
@templater.add_empty_directory_mapping(subcmd_template_path)
@templater.generate(template_context, file_options)

if !subcmd_registered?(cli_content)
Expand Down
10 changes: 5 additions & 5 deletions lib/tty/commands/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def test_dir
end

def add_empty_directories
@templater.add_mapping("gitkeep.tt", "lib/#{namespaced_path}/commands/.gitkeep")
@templater.add_mapping("gitkeep.tt", "lib/#{namespaced_path}/templates/.gitkeep")
@templater.add_mapping("gitkeep.tt", "#{test_dir}/integration/.gitkeep")
@templater.add_mapping("gitkeep.tt", "#{test_dir}/support/.gitkeep")
@templater.add_mapping("gitkeep.tt", "#{test_dir}/unit/.gitkeep")
@templater.add_empty_directory_mapping("lib/#{namespaced_path}/commands")
@templater.add_empty_directory_mapping("lib/#{namespaced_path}/templates")
@templater.add_empty_directory_mapping("#{test_dir}/integration")
@templater.add_empty_directory_mapping("#{test_dir}/support")
@templater.add_empty_directory_mapping("#{test_dir}/unit")
end

# Add license definition to gemspec
Expand Down
10 changes: 10 additions & 0 deletions lib/tty/templater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def add_mapping(source, target)
@templates << [source, target]
end

# Add empty directory with gitkeep file mapping
#
# @param [String] target
# the target location
#
# @api public
def add_empty_directory_mapping(target)
@templates << ["gitkeep.tt", ::File.join(target, ".gitkeep")]
end

# Process templates by injecting vars and moving to location
#
# @api private
Expand Down

0 comments on commit 72447ec

Please sign in to comment.