Sha256: 4f69682e4e923221b961b3544a6084f60bce08bd14a9a32c00e5e67ee6a2e9df

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'erb'
require 'pathname'
desc 'Install Ferry, ferry install STAGES=test,development,production'
task :install do
  envs = ENV['STAGES'] || 'test,development,production'

  tasks_dir = Pathname.new('lib/ferry/tasks')
  config_dir = Pathname.new('config')
  deploy_dir = config_dir.join('deploy_ferry')

  deploy_rb = File.expand_path("../../templates/deploy_ferry.rb.erb", __FILE__)
  stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
  ferryfile = File.expand_path("../../templates/Ferryfile", __FILE__)

  mkdir_p deploy_dir

  entries = [{template: deploy_rb, file: config_dir.join('deploy.rb')}]
  entries += envs.split(',').map { |stage| {template: stage_rb, file: deploy_dir.join("#{stage}.rb")} }

  entries.each do |entry|
    if File.exists?(entry[:file])
      warn "[skip] #{entry[:file]} already exists"
    else
      File.open(entry[:file], 'w+') do |f|
        f.write(ERB.new(File.read(entry[:template])).result(binding))
        puts I18n.t(:written_file, scope: :ferry, file: entry[:file])
      end
    end
  end

  mkdir_p tasks_dir

  if File.exists?('Ferryfile')
    warn "[skip] Ferryfile already exists"
  else
    FileUtils.cp(ferryfile, 'Ferryfile')
    puts I18n.t(:written_file, scope: :ferry, file: 'Ferryfile')
  end

  puts I18n.t :set_sail, scope: :deploy
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ferry-2.0.0 lib/ferry/tasks/install.rake