Sha256: f7552f12d17b6830952290e5d0cf763c7a1346e17f45cd5ef8664d58ac9b6bbd

Contents?: true

Size: 1.99 KB

Versions: 8

Compression:

Stored size: 1.99 KB

Contents

require 'bundler'
require 'colorize'
require 'fileutils'
require 'thor'

class Jets::Commands::Import
  class Sequence < Thor::Group
    include Thor::Actions
    argument :source

  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

      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

    def copy_project
      puts "Creating rack folder"
      template_path = File.expand_path(@source)
      set_source_paths(template_path)
      directory ".", rack_folder, exclude_pattern: %r{.git}
    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}
        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

    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 git_installed?
      system("type git > /dev/null 2>&1")
    end

    def rack_folder
      "#{Jets.root}rack"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
jets-1.3.5 lib/jets/commands/import/sequence.rb
jets-1.3.4 lib/jets/commands/import/sequence.rb
jets-1.3.3 lib/jets/commands/import/sequence.rb
jets-1.3.2 lib/jets/commands/import/sequence.rb
jets-1.3.1 lib/jets/commands/import/sequence.rb
jets-1.3.0 lib/jets/commands/import/sequence.rb
jets-1.2.1 lib/jets/commands/import/sequence.rb
jets-1.2.0 lib/jets/commands/import/sequence.rb