1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

discover template in local directory if applicable (#2157)

- look for template in local absolute directory
- use looser check for SSH git URL
This commit is contained in:
Dan Allen 2018-03-02 16:19:43 -07:00 committed by Thomas Reynolds
parent d0f4a7e488
commit 0719f314a5

View file

@ -47,7 +47,7 @@ module Middleman::Cli
begin
data = ::JSON.parse(uri.read)
data['links']['github']
is_local_dir = false
data['links']['github'].split('#')
rescue ::OpenURI::HTTPError
say "Template `#{options[:template]}` not found in Middleman Directory."
@ -56,21 +56,12 @@ module Middleman::Cli
end
else
repo_name, repo_branch = options[:template].split('#')
[repository_path(repo_name), repo_branch]
repo_path, is_local_dir = repository_path(repo_name)
[repo_path, repo_branch]
end
dir = Dir.mktmpdir
begin
branch_cmd = repo_branch ? "-b #{repo_branch} " : ''
run("#{GIT_CMD} clone --depth 1 #{branch_cmd}#{repo_path} #{dir}")
unless $?.success?
branch_msg = repo_branch ? " (#{repo_branch} branch)" : ''
say "Git clone command failed. Make sure git repository exists: #{repo_path}#{branch_msg}", :red
exit 1
end
dir = is_local_dir ? repo_path : clone_repository(repo_path, repo_branch)
inside(target) do
thorfile = File.join(dir, 'Thorfile')
@ -88,7 +79,7 @@ module Middleman::Cli
run("bundle install#{bundle_args}") unless ENV['TEST'] || options[:'skip-bundle']
end
ensure
FileUtils.remove_entry(dir) if File.directory?(dir)
FileUtils.remove_entry(dir) if !is_local_dir && File.directory?(dir)
end
end
@ -117,8 +108,30 @@ module Middleman::Cli
repo.split('/').length == 1
end
def repository_path(repo)
repo.include?('://') || repo.include?('git@') ? repo : "https://github.com/#{repo}.git"
def repository_path(repo_name)
if repo_name.include?('://') || /^[^@]+@[^:]+:.+/ =~ repo_name
repo_name
elsif (repo_path = Pathname(repo_name)).directory? && repo_path.absolute?
[repo_name, true]
else
"https://github.com/#{repo_name}.git"
end
end
def clone_repository(repo_path, repo_branch)
dir = Dir.mktmpdir
branch_cmd = repo_branch ? "-b #{repo_branch} " : ''
git_path = "#{branch_cmd}#{repo_path}"
run("#{GIT_CMD} clone --depth 1 #{branch_cmd}#{repo_path} #{dir}")
unless $?.success?
say "Git clone command failed. Make sure git repository exists: #{git_path}", :red
exit 1
end
dir
end
# Add to CLI