require 'crossbar/version' require 'fileutils' require 'pathname' require 'thor' module Crossbar class Generator < Thor map ['-v', '--version'] => :version desc 'install', 'Install Crossbar into your project' method_options path: :string def install # crossbar_files_already_installed? if crossbar_files_already_installed? puts "Crossbar files already installed, doing nothing." else install_files puts "Crossbar files installed to #{install_path}" end end desc 'version', 'Show Crossbar version' def version say "Crossbar #{Crossbar::VERSION}" end private def crossbar_files_already_installed? crossbar_folders.all? do |f| return File.directory?(File.join(install_path, f)) end end def crossbar_folders return ["base", "layout", "modules", "states"] end def install_path @install_path ||= if options[:path] Pathname.new(File.join(options[:path], '')) else Pathname.new '.' end end def install_files FileUtils.mkdir_p(install_path) FileUtils.cp_r(all_stylesheets, install_path) end def all_stylesheets Dir["#{stylesheets_directory}/*"] end def stylesheets_directory File.join(top_level_directory, "app", "assets", "stylesheets") end def top_level_directory File.dirname(File.dirname(File.dirname(__FILE__))) end end end