Sha256: dfed9f8b0fdd5859cd6da0d049fb0492761354e4ea3bcbc3feba46aaa1f67385

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require 'fileutils'
require 'yaml'
require 'xcbootstrap/template'

module XCBootstrap
  class Bootstrap
    attr_accessor :template_dir
    attr_accessor :project_dir
    
    def initialize template_root, template_name, project_dir
      @template_dir = File.join template_root, template_name
      raise "Invalid template: could not find template directory #{@template_dir}" unless File.directory?(@template_dir)
      
      manifest_file = File.join @template_dir, "manifest.yml"
      raise "Invalid template: could not find template manifest #{manifest_file}" unless File.exists?(manifest_file)
      
      @manifest = YAML.load_file manifest_file
      raise "Invalid template: manifest file did not contain a hash of file mappings #{manifest_file}" unless manifest_data_is_valid(@manifest)
      
      @project_dir = File.expand_path(project_dir, Dir.pwd)
    end
    
    def process
      FileUtils.mkdir_p project_dir
      
      @manifest["files"].each do |file|
        Template.new(file, @template_dir, @project_dir).process
      end
    end
    
    def finish
      print_output_project_files
      print_next_steps
    end
    
    private
    
    def manifest_data_is_valid manifest_data
      manifest_data.kind_of?(Hash) && !manifest_data["files"].nil? && manifest_data["files"].kind_of?(Array) && !manifest_data["files"].empty?
    end
    
    def print_output_project_files
      puts @project_dir
      Dir.glob("#{@project_dir}/**/*").each do |item|
        item.gsub(@project_dir, "").split("/").size.times do
          print "."
        end
        puts File.basename(item)
      end
      puts "\n"
    end
    
    def print_next_steps
      cat_file(File.join(File.dirname(__FILE__), "next_steps.txt"))
    end
    
    def cat_file file
      File.readlines(file).each do |line|
          puts line
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xcbootstrap-0.1.0 lib/xcbootstrap/bootstrap.rb