Sha256: 014443cc55790ec546a0896a8c90128be8e8d101f7724a0d4be13c97d8778b41

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'zip/zip'

module Dugway
  module Cli
    class Build < Thor::Group
      include Thor::Actions
      
      def self.source_root
        File.join(Dir.pwd, 'source')
      end
      
      def self.destination_root
        File.join(Dir.pwd, 'build')
      end
      
      def validate
        unless theme.valid?
          theme.errors.each { |error| say(error, :red) }
          raise "Theme is invalid"
        end
      end
      
      def create_destination
        empty_directory self.class.destination_root
      end
      
      def build
        Zip::ZipFile.open(build_file, Zip::ZipFile::CREATE) { |zipfile|
          theme.files.each { |file|
            zipfile.get_output_stream(file) { |f|
              f << theme.build_file(file)
            }
          }
        }
      end
      
      def success
        say_status(:create, "build/#{ build_name }")
      end
      
      private
      
      def theme
        @theme ||= Theme.new(self.class.source_root)
      end
      
      def build_name
        @build_name ||= "#{ theme.name.parameterize }-#{ theme.version }.zip"
      end
      
      def build_file
        @build_file ||= File.join(self.class.destination_root, build_name)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dugway-0.5.0 lib/dugway/cli/build.rb