Class: Stylegen::CLI::Commands::Build

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/stylegen/cli/commands.rb

Instance Method Summary collapse

Instance Method Details

#call(input: 'theme.yaml') ⇒ Object

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/stylegen/cli/commands.rb', line 47

def call(input: 'theme.yaml', **)
  raise Error, "'#{input}' not found. Create one with 'stylegen init'." unless File.exist?(input)

  data = File.open(input) { |file| YAML.safe_load(file) }

  validator = Validator.new
  unless validator.valid?(data)
    message = []
    message << "#{input} contains one or more errors:"

    validator.validate(data).each do |e|
      message << "  #{e}"
    end

    raise Error, message.join("\n")
  end

  generator = Generator.new(data)
  generator.generate

  puts "Generated '#{generator.stats[:output_path]}' with #{generator.stats[:color_count]} colors."
end