makit 0.0.40 → 0.0.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generated/makit/v1/makit.v1_pb.rb +34 -0
  3. data/lib/generated/makit/v1/web/link_pb.rb +20 -0
  4. data/lib/makit/apache.rb +32 -32
  5. data/lib/makit/cli/clean.rb +14 -14
  6. data/lib/makit/cli/clone.rb +59 -59
  7. data/lib/makit/cli/init.rb +38 -38
  8. data/lib/makit/cli/main.rb +33 -33
  9. data/lib/makit/cli/make.rb +54 -54
  10. data/lib/makit/cli/new.rb +37 -37
  11. data/lib/makit/cli/nuget_cache.rb +38 -38
  12. data/lib/makit/cli/pull.rb +31 -31
  13. data/lib/makit/cli/setup.rb +71 -71
  14. data/lib/makit/cli/work.rb +21 -21
  15. data/lib/makit/command_runner.rb +400 -391
  16. data/lib/makit/commands.rb +21 -21
  17. data/lib/makit/content/default_gitignore.rb +5 -5
  18. data/lib/makit/content/default_gitignore.txt +222 -222
  19. data/lib/makit/content/default_rakefile.rb +11 -11
  20. data/lib/makit/content/gem_rakefile.rb +14 -14
  21. data/lib/makit/data.rb +50 -50
  22. data/lib/makit/directories.rb +140 -140
  23. data/lib/makit/directory.rb +200 -200
  24. data/lib/makit/dotnet.rb +155 -156
  25. data/lib/makit/environment.rb +127 -127
  26. data/lib/makit/fileinfo.rb +16 -16
  27. data/lib/makit/files.rb +47 -47
  28. data/lib/makit/git.rb +87 -87
  29. data/lib/makit/gitlab_runner.rb +60 -60
  30. data/lib/makit/humanize.rb +129 -129
  31. data/lib/makit/indexer.rb +56 -56
  32. data/lib/makit/logging.rb +96 -96
  33. data/lib/makit/markdown.rb +75 -75
  34. data/lib/makit/mp/basic_object_mp.rb +16 -16
  35. data/lib/makit/mp/command_request.mp.rb +16 -16
  36. data/lib/makit/mp/project_mp.rb +210 -210
  37. data/lib/makit/mp/string_mp.rb +140 -122
  38. data/lib/makit/nuget.rb +57 -57
  39. data/lib/makit/protoc.rb +104 -104
  40. data/lib/makit/serializer.rb +115 -115
  41. data/lib/makit/show.rb +108 -108
  42. data/lib/makit/storage.rb +131 -131
  43. data/lib/makit/symbols.rb +149 -149
  44. data/lib/makit/tasks.rb +60 -60
  45. data/lib/makit/tree.rb +37 -37
  46. data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
  47. data/lib/makit/version.rb +52 -52
  48. data/lib/makit/wix.rb +95 -95
  49. data/lib/makit/zip.rb +17 -17
  50. data/lib/makit.rb +267 -267
  51. metadata +5 -3
@@ -1,122 +1,140 @@
1
- # frozen_string_literal: true
2
- require "json"
3
- # monkey patch String class with a run method
4
-
5
- class String
6
- def run(args = nil)
7
- if args.nil?
8
- command = self
9
- Makit::RUNNER.run(Makit::RUNNER::parse_command_request(command))
10
- else
11
- command = self
12
- request = Makit::RUNNER.parse_args(command)
13
- if args.is_a?(Hash)
14
- args.each do |key, value|
15
- request.send("#{key}=", value)
16
- end
17
- end
18
- Makit::RUNNER.run(request)
19
- end
20
- end
21
-
22
- def try(args = nil)
23
- if args.nil?
24
- command = self
25
- Makit::RUNNER.try(command)
26
- else
27
- command = self
28
- request = Makit::RUNNER.parse_args(command)
29
- if args.is_a?(Hash)
30
- args.each do |key, value|
31
- request.send("#{key}=", value)
32
- end
33
- end
34
- Makit::RUNNER.try(request)
35
- end
36
- end
37
-
38
- def cache_run()
39
- command = self
40
- Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command))
41
- end
42
-
43
- def cache_run(timestamp = nil)
44
- if timestamp.nil?
45
- timestamp = Makit::GIT_FILE_INFOS.first.mtime #GIT_FILE_INFOS. Makit::Directory.get_newest_git_file_timestamp(Makit::Directories::PROJECT_ROOT)
46
- #timestamp = Makit::Timestamp.now
47
- end
48
-
49
- command = self
50
- Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command), timestamp)
51
- end
52
-
53
- # Read a value from a JSON file
54
- # key is a string with the key to read, e.g. "AzureAd.Authority"
55
- def get_json_value(key)
56
- json = File.read(self)
57
- data = JSON.parse(json)
58
-
59
- # key delimiter is '.' so we can access nested keys
60
- key.split(".").each do |k|
61
- data = data[k]
62
- end
63
- data
64
- end
65
-
66
- alias_method :retrieve, :get_json_value
67
-
68
- # Set a value in a JSON file
69
- # key is a string with the key to set, e.g. "AzureAd.Authority"
70
- def set_json_value(key, value)
71
- file = File.read(self)
72
- data = JSON.parse(file)
73
- keys = key.split(".")
74
- current = data
75
-
76
- # Traverse and create any missing keys
77
- keys[0..-2].each do |k|
78
- current[k] ||= {} # Create a new hash if the key doesn't exist
79
- current = current[k]
80
- end
81
-
82
- # Set the value for the final key
83
- current[keys[-1]] = value
84
-
85
- # Write the JSON back to the file
86
- File.write(self, JSON.pretty_generate(data))
87
- end
88
-
89
- # Alias for set_json_value
90
- alias_method :assign, :set_json_value
91
-
92
- def strip_color_codes
93
- # Regular expression to remove ANSI color codes
94
- cleaned_content = self.gsub(/\e\[[\d;]+m/, "")
95
- cleaned_content
96
- end
97
-
98
- def to_lines(max_length = 80, indent_length = 5)
99
- if (self.length <= max_length)
100
- return self
101
- else
102
- indent = " " * indent_length
103
- words = self.split(" ")
104
- lines = []
105
- line = ""
106
- words.each do |word|
107
- if ((line + word).length > max_length)
108
- lines << line
109
- line = indent + word
110
- else
111
- if (line.length == 0)
112
- line = word
113
- else
114
- line += " " + word
115
- end
116
- end
117
- end
118
- lines << line
119
- return lines.join("\n")
120
- end
121
- end
122
- end
1
+ # frozen_string_literal: true
2
+ require "json"
3
+ # monkey patch String class with a run method
4
+
5
+ class String
6
+ def run(args = nil)
7
+ if args.nil?
8
+ command = self
9
+ Makit::RUNNER.run(Makit::RUNNER::parse_command_request(command))
10
+ else
11
+ command = self
12
+ request = Makit::RUNNER.parse_args(command)
13
+ if args.is_a?(Hash)
14
+ args.each do |key, value|
15
+ request.send("#{key}=", value)
16
+ end
17
+ end
18
+ Makit::RUNNER.run(request)
19
+ end
20
+ end
21
+
22
+
23
+
24
+ def cache_run()
25
+ command = self
26
+ Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command))
27
+ end
28
+
29
+ def cache_run(timestamp = nil)
30
+ if timestamp.nil?
31
+ timestamp = Makit::GIT_FILE_INFOS.first.mtime #GIT_FILE_INFOS. Makit::Directory.get_newest_git_file_timestamp(Makit::Directories::PROJECT_ROOT)
32
+ #timestamp = Makit::Timestamp.now
33
+ end
34
+
35
+ command = self
36
+ Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command), timestamp)
37
+ end
38
+
39
+ def try(args = nil)
40
+ if args.nil?
41
+ command = self
42
+ Makit::RUNNER.try(command)
43
+ else
44
+ command = self
45
+ request = Makit::RUNNER.parse_args(command)
46
+ if args.is_a?(Hash)
47
+ args.each do |key, value|
48
+ request.send("#{key}=", value)
49
+ end
50
+ end
51
+ Makit::RUNNER.try(request)
52
+ end
53
+ end
54
+
55
+ def cache_try()
56
+ command = self
57
+ Makit::RUNNER.cache_try(Makit::RUNNER::parse_command_request(command))
58
+ end
59
+
60
+ def cache_try(timestamp = nil)
61
+ if timestamp.nil?
62
+ timestamp = Makit::GIT_FILE_INFOS.first.mtime #GIT_FILE_INFOS. Makit::Directory.get_newest_git_file_timestamp(Makit::Directories::PROJECT_ROOT)
63
+ #timestamp = Makit::Timestamp.now
64
+ end
65
+
66
+ command = self
67
+ Makit::RUNNER.cache_try(Makit::RUNNER::parse_command_request(command), timestamp)
68
+ end
69
+
70
+
71
+ # Read a value from a JSON file
72
+ # key is a string with the key to read, e.g. "AzureAd.Authority"
73
+ def get_json_value(key)
74
+ json = File.read(self)
75
+ data = JSON.parse(json)
76
+
77
+ # key delimiter is '.' so we can access nested keys
78
+ key.split(".").each do |k|
79
+ data = data[k]
80
+ end
81
+ data
82
+ end
83
+
84
+ alias_method :retrieve, :get_json_value
85
+
86
+ # Set a value in a JSON file
87
+ # key is a string with the key to set, e.g. "AzureAd.Authority"
88
+ def set_json_value(key, value)
89
+ file = File.read(self)
90
+ data = JSON.parse(file)
91
+ keys = key.split(".")
92
+ current = data
93
+
94
+ # Traverse and create any missing keys
95
+ keys[0..-2].each do |k|
96
+ current[k] ||= {} # Create a new hash if the key doesn't exist
97
+ current = current[k]
98
+ end
99
+
100
+ # Set the value for the final key
101
+ current[keys[-1]] = value
102
+
103
+ # Write the JSON back to the file
104
+ File.write(self, JSON.pretty_generate(data))
105
+ end
106
+
107
+ # Alias for set_json_value
108
+ alias_method :assign, :set_json_value
109
+
110
+ def strip_color_codes
111
+ # Regular expression to remove ANSI color codes
112
+ cleaned_content = self.gsub(/\e\[[\d;]+m/, "")
113
+ cleaned_content
114
+ end
115
+
116
+ def to_lines(max_length = 80, indent_length = 5)
117
+ if (self.length <= max_length)
118
+ return self
119
+ else
120
+ indent = " " * indent_length
121
+ words = self.split(" ")
122
+ lines = []
123
+ line = ""
124
+ words.each do |word|
125
+ if ((line + word).length > max_length)
126
+ lines << line
127
+ line = indent + word
128
+ else
129
+ if (line.length == 0)
130
+ line = word
131
+ else
132
+ line += " " + word
133
+ end
134
+ end
135
+ end
136
+ lines << line
137
+ return lines.join("\n")
138
+ end
139
+ end
140
+ end
data/lib/makit/nuget.rb CHANGED
@@ -1,57 +1,57 @@
1
- require "tmpdir"
2
- # This module provides classes for the Makit gem.
3
- module Makit
4
- # This class provide methods for working with the Nuget package cache
5
- #
6
- # Example:
7
- #
8
- # Makit::Directory.cache("Google.Protobuf", "3.27.2")
9
- #
10
- # dotnet nuget locals all --list
11
- # dotnet nuget locals all --clear
12
- #
13
- class NuGet
14
- def self.get_cache_dir(package, version)
15
- File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package, version)
16
- end
17
-
18
- def self.cache(package, version)
19
- # if the package is already cached, there is nothing to do
20
- if (!Dir.exist?(get_cache_dir(package, version)))
21
- Dir.mktmpdir do |dir|
22
- # Use the temp directory here
23
- Dir.chdir(dir) do
24
- system("dotnet new classlib -n ClassLib")
25
- Dir.chdir("ClassLib") do
26
-
27
- # display a list of directories in the current directory
28
- puts Dir.entries(Dir.pwd)
29
- # display a list of files in the current directory
30
- puts Dir.entries(Dir.pwd)
31
- puts "dotnet add ClassLib.csproj package #{package} --version #{version}"
32
- system("dotnet add ClassLib.csproj package #{package} --version #{version}")
33
- end
34
- end
35
- # The directory and its contents will be removed automatically after the block
36
- end
37
- end
38
- end
39
-
40
- def self.clear_cache(package, version)
41
- if (Dir.exist?(get_cache_dir(package, version)))
42
- FileUtils.rm_rf(get_cache_dir(package, version))
43
- end
44
- end
45
-
46
- # get the latest version of the package
47
- def self.get_latest_version(package)
48
- dir = File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package)
49
- if (Dir.exist?(dir))
50
- versions = Dir.entries(dir).select { |entry| File.directory?(File.join(dir, entry)) && !(entry == "." || entry == "..") }
51
- highest_version = Makit::Version::get_highest_version(versions)
52
- return highest_version
53
- end
54
- nil
55
- end
56
- end
57
- end
1
+ require "tmpdir"
2
+ # This module provides classes for the Makit gem.
3
+ module Makit
4
+ # This class provide methods for working with the Nuget package cache
5
+ #
6
+ # Example:
7
+ #
8
+ # Makit::Directory.cache("Google.Protobuf", "3.27.2")
9
+ #
10
+ # dotnet nuget locals all --list
11
+ # dotnet nuget locals all --clear
12
+ #
13
+ class NuGet
14
+ def self.get_cache_dir(package, version)
15
+ File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package, version)
16
+ end
17
+
18
+ def self.cache(package, version)
19
+ # if the package is already cached, there is nothing to do
20
+ if (!Dir.exist?(get_cache_dir(package, version)))
21
+ Dir.mktmpdir do |dir|
22
+ # Use the temp directory here
23
+ Dir.chdir(dir) do
24
+ system("dotnet new classlib -n ClassLib")
25
+ Dir.chdir("ClassLib") do
26
+
27
+ # display a list of directories in the current directory
28
+ puts Dir.entries(Dir.pwd)
29
+ # display a list of files in the current directory
30
+ puts Dir.entries(Dir.pwd)
31
+ puts "dotnet add ClassLib.csproj package #{package} --version #{version}"
32
+ system("dotnet add ClassLib.csproj package #{package} --version #{version}")
33
+ end
34
+ end
35
+ # The directory and its contents will be removed automatically after the block
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.clear_cache(package, version)
41
+ if (Dir.exist?(get_cache_dir(package, version)))
42
+ FileUtils.rm_rf(get_cache_dir(package, version))
43
+ end
44
+ end
45
+
46
+ # get the latest version of the package
47
+ def self.get_latest_version(package)
48
+ dir = File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package)
49
+ if (Dir.exist?(dir))
50
+ versions = Dir.entries(dir).select { |entry| File.directory?(File.join(dir, entry)) && !(entry == "." || entry == "..") }
51
+ highest_version = Makit::Version::get_highest_version(versions)
52
+ return highest_version
53
+ end
54
+ nil
55
+ end
56
+ end
57
+ end
data/lib/makit/protoc.rb CHANGED
@@ -1,104 +1,104 @@
1
- # frozen_string_literal: true
2
- require "pathname"
3
-
4
- # This module provides classes for the Makit gem.
5
- module Makit
6
- # This class provide methods for working with the system Environment.
7
- #
8
- class Protoc
9
- def self.grpc_tools_path
10
- File.join(Makit::Directories::NUGET_PACKAGE_CACHE, "grpc.tools", Makit::Protoc::get_latest_grpc_tools_version)
11
- end
12
-
13
- def self.grpc_csharp_plugin_path
14
- Makit::Protoc::find_plugin_path("grpc_csharp_plugin")
15
- end
16
- def self.setup
17
- if (!Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE))
18
- puts " warning: Nuget package cache directory #{Makit::Directories::NUGET_PACKAGE_CACHE} not found".colorize(:red)
19
- puts " warning: Unable to proceed with protoc setup".colorize(:red)
20
- else
21
- Makit::NuGet::cache("Grpc.Tools", "2.66.0")
22
- raise "Nuget package path #{Makit::Directories::NUGET_PACKAGE_CACHE} not found" if !Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE)
23
-
24
- # test if protoc is installed by running >protoc --version
25
- which_protoc = Makit::Environment.which("protoc")
26
- if (Makit::Environment.which("protoc").nil?)
27
- puts " protoc not found, installing...".colorize(:red)
28
- "go version".run
29
- "go install google.golang.org/protobuf/cmd/protoc-gen-go@latest".run
30
- "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest".run
31
- "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest".run
32
- else
33
- puts " protoc found at #{which_protoc}".colorize(:green)
34
- end
35
- raise "protoc not found" if !Makit::Environment.which("protoc")
36
-
37
- #"git clone https://github.com/googleapis/googleapis.git third_party".run unless File.directory?("third_party/google")
38
- puts " grpc_tools_path " + "#{Makit::Protoc::grpc_tools_path}".colorize(:green)
39
- puts " grpc_csharp_plugin_path " + "#{Makit::Protoc::grpc_csharp_plugin_path}".colorize(:green)
40
- end
41
- end
42
-
43
- # get the latest version of the grpc.tools package
44
- def self.get_latest_grpc_tools_version
45
- Makit::NuGet::get_latest_version("Grpc.Tools")
46
- end
47
-
48
- #GRPC_CSHARP_PLUGIN_PATH = Makit::Protoc::find_plugin_path("grpc_csharp_plugin")
49
- def self.find_plugin_path(plugin_name)
50
- # search for a file matching the pattern *grpc_csharp_plugin* in the grpc.tools directory
51
- # should match on Windows and Linux
52
- if (Makit::Environment.is_windows?)
53
- plugin_name = plugin_name + ".exe"
54
- end
55
-
56
- plugin_path = Dir.glob("#{Makit::Directories::GRPC_TOOLS_PATH}/**/#{plugin_name}").first
57
-
58
- raise "Plugin path #{plugin_path} not found" if !File.exist?(plugin_path)
59
- plugin_path
60
- end
61
-
62
- def self.get_proto_files_from_path(proto_source_dir)
63
- proto_files = Array.new()
64
- Dir.chdir(proto_source_dir) do
65
- Dir.glob("**/*.proto").each do |proto|
66
- proto_files << proto
67
- end
68
- end
69
- proto_files
70
- end
71
-
72
- def self.generate_source_file(proto_filename, language, csharp_output_dir)
73
- FileUtils.mkdir_p(csharp_output_dir) unless Dir.exist?(csharp_output_dir)
74
- "protoc --#{language}_out=#{csharp_output_dir} #{proto_filename}".run
75
- end
76
-
77
- # language: charp, ruby, go, etc.
78
- def self.generate_source_files(proto_source_dir, language, output_dir)
79
- debug = false
80
- puts "Generating source files for #{language} in #{proto_source_dir} to #{output_dir}" if debug
81
- FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir)
82
-
83
- path_a = Pathname.new(proto_source_dir)
84
- path_b = Pathname.new(output_dir)
85
- output_relative_path = path_b.relative_path_from(path_a)
86
- puts "output_relative_path: #{output_relative_path}" if debug
87
-
88
- Dir.chdir(proto_source_dir) do
89
- Dir.glob("**/*.proto").each do |proto|
90
- puts "Generating #{proto}" if debug
91
- if (language == "csharp")
92
- namespace_dir = File.dirname(proto)
93
- output_dir = "#{output_relative_path}/#{namespace_dir}"
94
- puts "Generating #{proto} in #{output_dir}" if debug
95
- FileUtils.mkdir_p("#{output_dir}") unless Dir.exist?("#{output_dir}")
96
- "protoc --csharp_out=#{output_dir} #{proto}".run
97
- else
98
- "protoc --#{language}_out=#{output_relative_path} #{proto}".run
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end
1
+ # frozen_string_literal: true
2
+ require "pathname"
3
+
4
+ # This module provides classes for the Makit gem.
5
+ module Makit
6
+ # This class provide methods for working with the system Environment.
7
+ #
8
+ class Protoc
9
+ def self.grpc_tools_path
10
+ File.join(Makit::Directories::NUGET_PACKAGE_CACHE, "grpc.tools", Makit::Protoc::get_latest_grpc_tools_version)
11
+ end
12
+
13
+ def self.grpc_csharp_plugin_path
14
+ Makit::Protoc::find_plugin_path("grpc_csharp_plugin")
15
+ end
16
+ def self.setup
17
+ if (!Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE))
18
+ puts " warning: Nuget package cache directory #{Makit::Directories::NUGET_PACKAGE_CACHE} not found".colorize(:red)
19
+ puts " warning: Unable to proceed with protoc setup".colorize(:red)
20
+ else
21
+ Makit::NuGet::cache("Grpc.Tools", "2.66.0")
22
+ raise "Nuget package path #{Makit::Directories::NUGET_PACKAGE_CACHE} not found" if !Dir.exist?(Makit::Directories::NUGET_PACKAGE_CACHE)
23
+
24
+ # test if protoc is installed by running >protoc --version
25
+ which_protoc = Makit::Environment.which("protoc")
26
+ if (Makit::Environment.which("protoc").nil?)
27
+ puts " protoc not found, installing...".colorize(:red)
28
+ "go version".run
29
+ "go install google.golang.org/protobuf/cmd/protoc-gen-go@latest".run
30
+ "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest".run
31
+ "go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest".run
32
+ else
33
+ puts " protoc found at #{which_protoc}".colorize(:green)
34
+ end
35
+ raise "protoc not found" if !Makit::Environment.which("protoc")
36
+
37
+ #"git clone https://github.com/googleapis/googleapis.git third_party".run unless File.directory?("third_party/google")
38
+ puts " grpc_tools_path " + "#{Makit::Protoc::grpc_tools_path}".colorize(:green)
39
+ puts " grpc_csharp_plugin_path " + "#{Makit::Protoc::grpc_csharp_plugin_path}".colorize(:green)
40
+ end
41
+ end
42
+
43
+ # get the latest version of the grpc.tools package
44
+ def self.get_latest_grpc_tools_version
45
+ Makit::NuGet::get_latest_version("Grpc.Tools")
46
+ end
47
+
48
+ #GRPC_CSHARP_PLUGIN_PATH = Makit::Protoc::find_plugin_path("grpc_csharp_plugin")
49
+ def self.find_plugin_path(plugin_name)
50
+ # search for a file matching the pattern *grpc_csharp_plugin* in the grpc.tools directory
51
+ # should match on Windows and Linux
52
+ if (Makit::Environment.is_windows?)
53
+ plugin_name = plugin_name + ".exe"
54
+ end
55
+
56
+ plugin_path = Dir.glob("#{Makit::Directories::GRPC_TOOLS_PATH}/**/#{plugin_name}").first
57
+
58
+ raise "Plugin path #{plugin_path} not found" if !File.exist?(plugin_path)
59
+ plugin_path
60
+ end
61
+
62
+ def self.get_proto_files_from_path(proto_source_dir)
63
+ proto_files = Array.new()
64
+ Dir.chdir(proto_source_dir) do
65
+ Dir.glob("**/*.proto").each do |proto|
66
+ proto_files << proto
67
+ end
68
+ end
69
+ proto_files
70
+ end
71
+
72
+ def self.generate_source_file(proto_filename, language, csharp_output_dir)
73
+ FileUtils.mkdir_p(csharp_output_dir) unless Dir.exist?(csharp_output_dir)
74
+ "protoc --#{language}_out=#{csharp_output_dir} #{proto_filename}".run
75
+ end
76
+
77
+ # language: charp, ruby, go, etc.
78
+ def self.generate_source_files(proto_source_dir, language, output_dir)
79
+ debug = false
80
+ puts "Generating source files for #{language} in #{proto_source_dir} to #{output_dir}" if debug
81
+ FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir)
82
+
83
+ path_a = Pathname.new(proto_source_dir)
84
+ path_b = Pathname.new(output_dir)
85
+ output_relative_path = path_b.relative_path_from(path_a)
86
+ puts "output_relative_path: #{output_relative_path}" if debug
87
+
88
+ Dir.chdir(proto_source_dir) do
89
+ Dir.glob("**/*.proto").each do |proto|
90
+ puts "Generating #{proto}" if debug
91
+ if (language == "csharp")
92
+ namespace_dir = File.dirname(proto)
93
+ output_dir = "#{output_relative_path}/#{namespace_dir}"
94
+ puts "Generating #{proto} in #{output_dir}" if debug
95
+ FileUtils.mkdir_p("#{output_dir}") unless Dir.exist?("#{output_dir}")
96
+ "protoc --csharp_out=#{output_dir} #{proto}".run
97
+ else
98
+ "protoc --#{language}_out=#{output_relative_path} #{proto}".run
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end