lib/jets/commands/import/sequence.rb in jets-1.0.1 vs lib/jets/commands/import/sequence.rb in jets-1.0.2

- old
+ new

@@ -2,67 +2,83 @@ require 'colorize' require 'active_support/core_ext/string' require 'thor' require 'bundler' -class Jets::Commands::Import::Sequence < Thor::Group - include Thor::Actions - argument :source +class Jets::Commands::Import + class Sequence < Thor::Group + include Thor::Actions + argument :source -private - def clone_project - check_git_installed + private + def clone_project + if File.exist?(rack_folder) + abort "The folder #{rack_folder} already exists. Please remove it first if you want to import a project." + end - command = "git clone #{repo_url} #{rack_folder}" - puts "=> #{command}" - if File.exist?(rack_folder) - abort "The folder #{rack_folder} already exists." - else + check_git_installed + if @options[:submodule] + git_submodule + else + git_clone + end + end + + def git_submodule + puts "Adding project as a submodule" + run "git submodule add --force #{repo_url} #{rack_folder}" + Cheatsheet.create(repo_url) + end + + def git_clone + command = "git clone #{repo_url} #{rack_folder}" + # Thor's run already puts out the command, so no need to puts run command + run "rm -rf #{Jets.root}rack/.git" end - end - def copy_project - puts "Creating rack folder" - template_path = File.expand_path(@source) - set_source_paths(template_path) - directory ".", rack_folder - end + def copy_project + puts "Creating rack folder" + template_path = File.expand_path(@source) + set_source_paths(template_path) + directory ".", rack_folder + end - def set_source_paths(*paths) - # Using string with instance_eval because block doesnt have access to - # path at runtime. - self.class.instance_eval %{ - def self.source_paths - #{paths.flatten.inspect} + def set_source_paths(*paths) + # Using string with instance_eval because block doesnt have access to + # path at runtime. + self.class.instance_eval %{ + def self.source_paths + #{paths.flatten.inspect} + end + } + end + + # normalize repo_url + def repo_url + if @source.include?('github.com') + @source # leave as is, user has provided full github url + else + "https://github.com/#{@source}" end - } - end + end - # normalize repo_url - def repo_url - if @source.include?('github.com') - @source # leave as is, user has provided full github url - else - "https://github.com/#{@source}" + def repo? + @source.include?('github.com') end - end - def repo? - @source.include?('github.com') - end + def check_git_installed + return unless repo_url.include?('http') || repo_url.include?('git@') + unless git_installed? + abort "Unable to detect git installation on your system. Git needs to be installed in order to clone the project." + end + end - def check_git_installed - return unless repo_url.include?('http') || repo_url.include?('git@') - unless git_installed? - abort "Unable to detect git installation on your system. Git needs to be installed in order to clone the project." + def git_installed? + system("type git > /dev/null 2>&1") end - end - def git_installed? - system("type git > /dev/null 2>&1") - end - - def rack_folder - "#{Jets.root}rack" + def rack_folder + "#{Jets.root}rack" + end end end \ No newline at end of file