Sha256: e1e222a6aa5cff676150e5bd9c824acf755a4c64c9a500128c768e25814fca51

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

require 'hux/version'
require 'fileutils'
require 'pathname'
require 'thor'

module Hux
  class Generator < Thor
    map ['-v', '--version'] => :version
    map ['scaffold'] => :install
    map ['delete'] => :remove

    desc 'install', 'Install Hux into your project'
    method_options path: :string
    def install
      if hux_files_already_exist?
        puts "Hux files already installed, doing nothing."
      else
        install_files
        puts "Hux files installed to #{install_path}/base"
      end
    end

    desc 'reset', 'Reset Hux'
    def reset
      if hux_files_already_exist?
        remove_hux_directory
        install_files
        puts "Hux files updated."
      else
        puts "No existing Hux installation. Doing nothing."
      end
    end

    desc 'remove', 'Remove Hux'
    def remove
      if hux_files_already_exist?
        remove_hux_directory
        puts "Hux was successfully removed."
      else
        puts "No existing Hux installation. Doing nothing."
      end
    end

    desc 'version', 'Show Hux version'
    def version
      say "Hux #{Hux::VERSION}"
    end

    private

    def hux_files_already_exist?
      File.directory?(install_path)
    end

    def install_path
      Pathname.new(options[:path].to_s).join('base')
    end

    def install_files
      FileUtils.mkdir_p(install_path)
      FileUtils.cp_r(all_stylesheets, install_path)
    end

    def remove_hux_directory
      FileUtils.rm_rf("base")
    end

    def all_stylesheets
      Dir["#{stylesheets_directory}/*"]
    end

    def stylesheets_directory
      File.join(top_level_directory, "core")
    end

    def top_level_directory
      File.dirname(File.dirname(File.dirname(__FILE__)))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hux-0.0.1 lib/hux/generator.rb