Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves the template downloader, and manipulator into it's own class #5

Merged
merged 1 commit into from Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -8,7 +8,7 @@ GIT
PATH
remote: .
specs:
claide-plugins (0.9.0)
claide-plugins (0.9.1)
cork
nap
open4 (~> 1.3)
Expand All @@ -25,7 +25,7 @@ GEM
simplecov (>= 0.7.1, < 1.0.0)
coderay (1.1.1)
colored (1.2)
cork (0.1.0)
cork (0.2.0)
colored (~> 1.2)
crack (0.4.2)
safe_yaml (~> 1.0.0)
Expand Down Expand Up @@ -87,4 +87,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.12.5
1.13.1
4 changes: 3 additions & 1 deletion Rakefile
Expand Up @@ -29,7 +29,9 @@ begin
duration = Time.now - start_time
puts "Tests completed in #{duration}s"
Rake::Task['rubocop'].invoke
Rake::Task['validate_json'].invoke

# This is not used in this library
# Rake::Task['validate_json'].invoke
end

def specs(dir)
Expand Down
50 changes: 5 additions & 45 deletions lib/claide/command/plugins/create.rb
@@ -1,5 +1,6 @@
require 'claide/command/plugins_helper'
require 'claide/executable'
require 'claide/command/gem_helper'
require 'claide/command/template_runner'

module CLAide
class Command
Expand Down Expand Up @@ -46,57 +47,16 @@ def validate!
end

def run
clone_template
configure_template
runner = TemplateRunner.new @name, @template_url
runner.clone_template
runner.configure_template
show_reminder
end

#----------------------------------------#

private

# !@group Private helpers

extend CLAide::Executable
executable :git

# Clones the template from the remote in the working directory using
# the name of the plugin.
#
# @return [void]
#
def clone_template
UI.section("-> Creating `#{@name}` plugin") do
UI.notice "using template '#{template_repo_url}'"
command = ['clone', template_repo_url, @name]
git! command
end
end

# Runs the template configuration utilities.
#
# @return [void]
#
def configure_template
UI.section('-> Configuring template') do
Dir.chdir(@name) do
if File.file? 'configure'
system "./configure #{@name}"
else
UI.warn 'Template does not have a configure file.'
end
end
end
end

# Checks if a template URL is given else returns the Plugins.config URL
#
# @return String
#
def template_repo_url
@template_url || CLAide::Plugins.config.plugin_template_url
end

# Shows a reminder to the plugin author to make a Pull Request
# in order to update plugins.json once the plugin is released
#
Expand Down
51 changes: 51 additions & 0 deletions lib/claide/command/template_runner.rb
@@ -0,0 +1,51 @@
require 'claide/command/plugins_helper'
require 'claide/executable'

module CLAide
class TemplateRunner
extend CLAide::Executable
executable :git

def initialize(name, template_url)
@name = name
@template_url = template_url
end

# Clones the template from the remote in the working directory using
# the name of the plugin.
#
# @return [void]
#
def clone_template
UI.section("-> Creating `#{@name}` plugin") do
UI.notice "using template '#{template_repo_url}'"
command = ['clone', template_repo_url, @name]
git! command
end
end

# Runs the template configuration utilities.
#
# @return [void]
#
def configure_template
UI.section('-> Configuring template') do
Dir.chdir(@name) do
if File.file? 'configure'
system "./configure #{@name}"
else
UI.warn 'Template does not have a configure file.'
end
end
end
end

# Checks if a template URL is given else returns the Plugins.config URL
#
# @return String
#
def template_repo_url
@template_url || CLAide::Plugins.config.plugin_template_url
end
end
end
9 changes: 5 additions & 4 deletions spec/command/plugins/create_spec.rb
Expand Up @@ -84,8 +84,8 @@ module CLAide
template_repo = 'https://github.com/danger/' \
'danger-plugin-template'
git_command = ['clone', template_repo, 'danger-banana']
@command.expects(:git!).with(git_command)
@command.expects(:configure_template)
CLAide::TemplateRunner.any_instance.expects(:git!).with(git_command)
CLAide::TemplateRunner.any_instance.expects(:configure_template)
@command.run
UI_OUT.string.should.include('Creating `danger-banana` plugin')
end
Expand All @@ -95,8 +95,9 @@ module CLAide
'danger-banana-plugin-template'
@command = create_command('danger-banana', alt_repo)

@command.expects(:git!).with(['clone', alt_repo, 'danger-banana'])
@command.expects(:configure_template)
git_command = ['clone', alt_repo, 'danger-banana']
CLAide::TemplateRunner.any_instance.expects(:git!).with(git_command)
CLAide::TemplateRunner.any_instance.expects(:configure_template)
@command.run
UI_OUT.string.should.include('Creating `danger-banana` plugin')
end
Expand Down