Sha256: 298b416e8bcf16c1b87ed00138cfcdb3eab52c8262eafbd81f4f381908473105

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'fileutils'

module Ree
  module CLI
    class GenerateObjectSchema
      class << self
        def run(package_name:, object_path:, project_path:, silence: false)
          ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'

          path = Ree.locate_packages_schema(project_path)
          dir = Pathname.new(path).dirname.to_s

          Ree.init(dir)

          package_name = package_name.to_sym
          object_name = object_path.split('/')[-1].split('.').first.to_sym

          puts("Generating #{object_name}.schema.json in #{package_name} package") if !silence

          facade = Ree.container.packages_facade
          Ree.load_package(package_name)

          package = facade.get_package(package_name)

          if facade.has_object?(package_name, object_name)
            object = facade.load_package_object(package_name, object_name)
            Ree.write_object_schema(package.name, object.name)

            obj_path = Ree::PathHelper.abs_object_schema_path(object)
          else
            file_path = File.join(dir, object_path)

            if File.exists?(file_path)
              facade.load_file(file_path, package_name)
              facade.dump_package_schema(package_name)

              if facade.has_object?(package_name, object_name)
                Ree.write_object_schema(package_name, object_name)
              end
            else
              raise Ree::Error.new("package file not found: #{file_path}")
            end
          end

          puts("done") if !silence
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ree-1.0.8 lib/ree/cli/generate_object_schema.rb