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