metanorma/metanorma-cli

View on GitHub
bin/font-test

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
# frozen_string_literal: true
require "fontist"
require "rubygems"
require "yaml"

flavors = ARGV

Fontist::Formula.update_formulas_repo

flavors.each do |flavor|
  begin
    gem_name = "metanorma-#{flavor}"
    require gem_name

    submodule = case flavor
                when "jcgm"
                  "Bipm"
                else
                  flavor.capitalize
                end
    processor_class = "Metanorma::#{submodule}::Processor"

    processor = Object
      .const_get(processor_class)
      .new

    unless processor.respond_to?(:fonts_manifest)
      puts "#{flavor} don't require any fonts"
      exit(0)
    end

    manifest = processor.fonts_manifest

    Fontist::Manifest::Install.from_hash(
      manifest,
      confirmation: "yes",
    )

    puts "#{flavor}-related fonts:"
    puts Fontist::Manifest::Locations.from_hash(manifest).to_yaml
  rescue LoadError => e
    STDERR.puts "Could not load gem '#{gem_name}': #{e.message}"
    exit(1)
  rescue NameError => e
    STDERR.puts "Could not find class '#{processor_class}': #{e.message}"
    exit(1)
  rescue => e
    if e.class.to_s.start_with?("Fontist::Errors::")
      STDERR.puts "Fontist failed with: #{e.message}"
    else
      STDERR.puts "Unknown error: #{e.message}"
    end
    exit(1)
  end
end