lib/makit/protoc.rb in makit-0.0.1 vs lib/makit/protoc.rb in makit-0.0.2

- old
+ new

@@ -1,61 +1,61 @@ -# frozen_string_literal: true - -# This module provides classes for the Makit gem. -module Makit - # This class provide methods for working with the system Environment. - # - class Protoc - def self.grpc_tools_path - File.join(Makit::Directories::NUGET_PACKAGE_CACHE, "grpc.tools", Makit::Protoc::get_latest_grpc_tools_version) - end - - def self.grpc_csharp_plugin_path - Makit::Protoc::find_plugin_path("grpc_csharp_plugin") - end - def self.setup - if (!Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE)) - puts " warning: Nuget package cache directory #{Makit::Directories::NUGET_PACKAGE_CACHE} not found".colorize(:red) - puts " warning: Unable to proceed with protoc setup".colorize(:red) - else - Makit::NuGet::cache("Grpc.Tools", "2.66.0") - raise "Nuget package path #{Makit::Directories::NUGET_PACKAGE_CACHE} not found" if !Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE) - - # test if protoc is installed by running >protoc --version - which_protoc = Makit::Environment.which("protoc") - if (Makit::Environment.which("protoc").nil?) - puts " protoc not found, installing...".colorize(:red) - "go version".run - "go install google.golang.org/protobuf/cmd/protoc-gen-go@latest".run - "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest".run - "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest".run - else - puts " protoc found at #{which_protoc}".colorize(:green) - end - raise "protoc not found" if !Makit::Environment.which("protoc") - - #"git clone https://github.com/googleapis/googleapis.git third_party".run unless File.directory?("third_party/google") - puts " grpc_tools_path " + "#{Makit::Protoc::grpc_tools_path}".colorize(:green) - puts " grpc_csharp_plugin_path " + "#{Makit::Protoc::grpc_csharp_plugin_path}".colorize(:green) - end - end - - # get the latest version of the grpc.tools package - def self.get_latest_grpc_tools_version - Makit::NuGet::get_latest_version("Grpc.Tools") - end - - #GRPC_CSHARP_PLUGIN_PATH = Makit::Protoc::find_plugin_path("grpc_csharp_plugin") - def self.find_plugin_path(plugin_name) - # search for a file matching the pattern *grpc_csharp_plugin* in the grpc.tools directory - # should match on Windows and Linux - if (Makit::Environment.is_windows?) - plugin_name = plugin_name + ".exe" - end - - plugin_path = Dir.glob("#{Makit::Directories::GRPC_TOOLS_PATH}/**/#{plugin_name}").first - - raise "Plugin path #{plugin_path} not found" if !File.exist?(plugin_path) - plugin_path - end - end -end +# frozen_string_literal: true + +# This module provides classes for the Makit gem. +module Makit + # This class provide methods for working with the system Environment. + # + class Protoc + def self.grpc_tools_path + File.join(Makit::Directories::NUGET_PACKAGE_CACHE, "grpc.tools", Makit::Protoc::get_latest_grpc_tools_version) + end + + def self.grpc_csharp_plugin_path + Makit::Protoc::find_plugin_path("grpc_csharp_plugin") + end + def self.setup + if (!Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE)) + puts " warning: Nuget package cache directory #{Makit::Directories::NUGET_PACKAGE_CACHE} not found".colorize(:red) + puts " warning: Unable to proceed with protoc setup".colorize(:red) + else + Makit::NuGet::cache("Grpc.Tools", "2.66.0") + raise "Nuget package path #{Makit::Directories::NUGET_PACKAGE_CACHE} not found" if !Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE) + + # test if protoc is installed by running >protoc --version + which_protoc = Makit::Environment.which("protoc") + if (Makit::Environment.which("protoc").nil?) + puts " protoc not found, installing...".colorize(:red) + "go version".run + "go install google.golang.org/protobuf/cmd/protoc-gen-go@latest".run + "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest".run + "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest".run + else + puts " protoc found at #{which_protoc}".colorize(:green) + end + raise "protoc not found" if !Makit::Environment.which("protoc") + + #"git clone https://github.com/googleapis/googleapis.git third_party".run unless File.directory?("third_party/google") + puts " grpc_tools_path " + "#{Makit::Protoc::grpc_tools_path}".colorize(:green) + puts " grpc_csharp_plugin_path " + "#{Makit::Protoc::grpc_csharp_plugin_path}".colorize(:green) + end + end + + # get the latest version of the grpc.tools package + def self.get_latest_grpc_tools_version + Makit::NuGet::get_latest_version("Grpc.Tools") + end + + #GRPC_CSHARP_PLUGIN_PATH = Makit::Protoc::find_plugin_path("grpc_csharp_plugin") + def self.find_plugin_path(plugin_name) + # search for a file matching the pattern *grpc_csharp_plugin* in the grpc.tools directory + # should match on Windows and Linux + if (Makit::Environment.is_windows?) + plugin_name = plugin_name + ".exe" + end + + plugin_path = Dir.glob("#{Makit::Directories::GRPC_TOOLS_PATH}/**/#{plugin_name}").first + + raise "Plugin path #{plugin_path} not found" if !File.exist?(plugin_path) + plugin_path + end + end +end