lib/tape/installer.rb in taperole-1.2.8 vs lib/tape/installer.rb in taperole-1.3.0
- old
+ new
@@ -1,78 +1,110 @@
module TapeBoxer
class Installer < ExecutionModule
TapeBoxer.register_module :installer, self
action :install,
- proc {install},
- 'Creates all nessisary hosts and config files'
+ proc { install },
+ 'Creates all necessary hosts and config files'
action :uninstall,
- proc {uninstall},
- 'Cleans up files generated by the installer'
+ proc { uninstall },
+ 'Cleans up files generated by the installer'
def initialize(*args)
super
end
protected
def install
File.open('.gitignore', 'r+') { |f| f.puts '.tape' unless f.read =~/^\.tape$/ }
- mkdir 'roles'
+ mkdir tapefiles_dir
if fe_app? && !rails_app?
puts '🔎 JS/HTML app detected'.pink
copy_static_app_examples
else rails_app?
puts '🔎 Rails app detected'.pink
copy_basic_examples
end
- copy_example 'templates/base/hosts.example', 'hosts'
- mkdir 'dev_keys'
+ create_roles_dir
+ create_inventory_file
+ create_ssh_keys_dir
print 'Are you going to use vagrant? (y/n): '
if gets.chomp == 'y'
copy_example 'Vagrantfile', 'Vagrantfile'
end
end
+ def create_roles_dir
+ mkdir "#{tapefiles_dir}/roles"
+ `touch #{tapefiles_dir}/roles/.keep`
+ end
+
+ def create_ssh_keys_dir
+ mkdir "#{tapefiles_dir}/dev_keys"
+ end
+
+ def create_inventory_file
+ copy_example 'templates/base/hosts.example', "#{tapefiles_dir}/hosts"
+ end
+
def fe_app?
!Dir["#{local_dir}/gulpfile.*"].empty?
end
def rails_app?
!Dir["#{local_dir}/config.ru"].empty?
end
def copy_static_app_examples
- copy_example 'templates/static_html/omnibox.example.yml', 'omnibox.yml'
- copy_example 'templates/static_html/deploy.example.yml', 'deploy.yml'
- copy_example 'templates/static_html/tape_vars.example.yml', 'tape_vars.yml'
+ copy_example(
+ 'templates/static_html/omnibox.example.yml',
+ "#{tapefiles_dir}/omnibox.yml"
+ )
+ copy_example(
+ 'templates/static_html/deploy.example.yml',
+ "#{tapefiles_dir}/deploy.yml"
+ )
+ copy_example(
+ 'templates/static_html/tape_vars.example.yml',
+ "#{tapefiles_dir}/tape_vars.yml"
+ )
end
def copy_basic_examples
- copy_example 'templates/base/omnibox.example.yml', 'omnibox.yml'
- copy_example 'templates/base/deploy.example.yml', 'deploy.yml'
- copy_example 'templates/base/tape_vars.example.yml', 'tape_vars.yml'
+ copy_example(
+ 'templates/base/omnibox.example.yml',
+ "#{tapefiles_dir}/omnibox.yml"
+ )
+ copy_example(
+ 'templates/base/deploy.example.yml',
+ "#{tapefiles_dir}/deploy.yml"
+ )
+ copy_example(
+ 'templates/base/tape_vars.example.yml',
+ "#{tapefiles_dir}/tape_vars.yml"
+ )
end
def uninstall
- rm 'omnibox.yml'
- rm 'deploy.yml'
- rm 'tape_vars.yml'
- rm 'roles'
- rm 'hosts'
- rm 'dev_keys'
- rm 'Vagrantfile'
+ rm "#{tapefiles_dir}/omnibox.yml"
+ rm "#{tapefiles_dir}/deploy.yml"
+ rm "#{tapefiles_dir}/tape_vars.yml"
+ rm "#{tapefiles_dir}/roles"
+ rm "#{tapefiles_dir}/hosts"
+ rm "#{tapefiles_dir}/dev_keys"
+ rm "Vagrantfile"
end
def rm(file)
print 'Deleting '.red
FileUtils.rm_r "#{local_dir}/#{file}"
puts file
end
def mkdir(name)
- print "#{name}: "
+ print "#{Pathname.new(name).basename}: "
begin
FileUtils.mkdir name
success
rescue Errno::EEXIST
exists
@@ -80,20 +112,16 @@
error
raise e
end
end
- def touch(file)
- File.new "#{local_dir}/#{file}", 'w'
- end
-
def copy_example(file, cp_file)
- print "#{cp_file}: "
+ print "#{Pathname.new(cp_file).basename}: "
begin
- if File.exists?("#{local_dir}/#{cp_file}")
+ if File.exist?("#{cp_file}")
exists
else
- FileUtils.cp("#{tape_dir}/#{file}", "#{local_dir}/#{cp_file}")
+ FileUtils.cp("#{tape_dir}/#{file}", "#{cp_file}")
success
end
rescue Exception => e
error
raise e