makit 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.makit.project.json +4 -0
  3. data/.makit.project.yml +2 -0
  4. data/.rubocop.yml +22 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +8 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/LICENSE +21 -0
  9. data/README.md +119 -0
  10. data/Rakefile +190 -0
  11. data/docs/Commands.md +50 -0
  12. data/docs_/Commands.md +166 -0
  13. data/docs_/Minitest.Timeouts.md +332 -0
  14. data/examples/protoc/Rakefile +31 -0
  15. data/examples/rake_default/Rakefile +5 -0
  16. data/examples/rubygem-foo/.gitkeep +0 -0
  17. data/examples/rubygem-foo/Rakefile +3 -0
  18. data/examples/run_mp/Rakefile +8 -0
  19. data/exe/makit +5 -0
  20. data/lib/makit/apache.rb +32 -0
  21. data/lib/makit/cli/clean.rb +14 -0
  22. data/lib/makit/cli/clone.rb +59 -0
  23. data/lib/makit/cli/init.rb +38 -0
  24. data/lib/makit/cli/main.rb +33 -0
  25. data/lib/makit/cli/make.rb +54 -0
  26. data/lib/makit/cli/new.rb +37 -0
  27. data/lib/makit/cli/nuget_cache.rb +38 -0
  28. data/lib/makit/cli/pull.rb +31 -0
  29. data/lib/makit/cli/setup.rb +71 -0
  30. data/lib/makit/cli/work.rb +21 -0
  31. data/lib/makit/command_runner.rb +237 -0
  32. data/lib/makit/commands.rb +21 -0
  33. data/lib/makit/content/default_gitignore.rb +5 -0
  34. data/lib/makit/content/default_gitignore.txt +222 -0
  35. data/lib/makit/content/default_rakefile.rb +11 -0
  36. data/lib/makit/content/gem_rakefile.rb +14 -0
  37. data/lib/makit/content/ruby_gitlab-ci.yml +15 -0
  38. data/lib/makit/data.rb +50 -0
  39. data/lib/makit/directories.rb +140 -0
  40. data/lib/makit/directory.rb +120 -0
  41. data/lib/makit/dotnet.rb +16 -0
  42. data/lib/makit/environment.rb +123 -0
  43. data/lib/makit/files.rb +47 -0
  44. data/lib/makit/git.rb +66 -0
  45. data/lib/makit/gitlab_runner.rb +60 -0
  46. data/lib/makit/humanize.rb +89 -0
  47. data/lib/makit/logging.rb +96 -0
  48. data/lib/makit/markdown.rb +75 -0
  49. data/lib/makit/mp/basic_object_mp.rb +16 -0
  50. data/lib/makit/mp/project_mp.rb +160 -0
  51. data/lib/makit/mp/string_mp.rb +101 -0
  52. data/lib/makit/nuget.rb +57 -0
  53. data/lib/makit/protoc.rb +61 -0
  54. data/lib/makit/serializer.rb +70 -0
  55. data/lib/makit/storage.rb +131 -0
  56. data/lib/makit/symbols.rb +149 -0
  57. data/lib/makit/tasks.rb +63 -0
  58. data/lib/makit/tree.rb +37 -0
  59. data/lib/makit/v1/makit.v1.proto +103 -0
  60. data/lib/makit/v1/makit.v1_pb.rb +30 -0
  61. data/lib/makit/v1/makit.v1_services_pb.rb +26 -0
  62. data/lib/makit/version.rb +12 -0
  63. data/lib/makit/wix.rb +92 -0
  64. data/lib/makit/zip.rb +17 -0
  65. data/lib/makit.rb +243 -0
  66. data/makit.generated.sln +30 -0
  67. data/makit.sln +69 -0
  68. data/pages/.gitignore +5 -0
  69. data/pages/404.html +25 -0
  70. data/pages/Gemfile +33 -0
  71. data/pages/Gemfile.lock +88 -0
  72. data/pages/_config.yml +55 -0
  73. data/pages/_layouts/default.html +1 -0
  74. data/pages/_posts/2024-10-05-welcome-to-jekyll.markdown +29 -0
  75. data/pages/about.markdown +18 -0
  76. data/pages/index.markdown +6 -0
  77. data/sig/makit.rbs +4 -0
  78. data/src/ClassLib/Class1.cs +6 -0
  79. data/src/ClassLib/ClassLib.csproj +13 -0
  80. metadata +251 -0
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+ require_relative "../../makit"
5
+
6
+ module Makit
7
+ module Cli
8
+ # Define the 'init' subcommand
9
+ class InitCommand < Clamp::Command
10
+ parameter "DIRECTORY", "The directory to init as a git repository", attribute_name: :directory, required: true
11
+
12
+ def execute
13
+ begin
14
+ Makit::init(directory)
15
+ puts "initialized local repository: #{directory}"
16
+ rescue => e
17
+ $stderr.puts "failed to initialize repository: #{directory}"
18
+ puts e.message
19
+ puts e.backtrace
20
+ exit 1
21
+ end
22
+ end
23
+
24
+ #def self.init(directory)
25
+ # if !Dir.exist?(directory)
26
+ # FileUtils.mkdir_p(directory)
27
+ # end
28
+ # Dir.chdir(directory) do
29
+ # init = Makit::RUNNER.execute "git init"
30
+ # if init.exit_code != 0
31
+ # raise Makit::Error.new("failed to initialize local repository: #{directory}\n#{Makit::Humanize.get_command_summary(init)}")
32
+ # end#
33
+
34
+ # end
35
+ #end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+ require_relative "new"
5
+ require_relative "setup"
6
+ require_relative "make"
7
+ require_relative "work"
8
+ require_relative "clean"
9
+ require_relative "clone"
10
+ require_relative "pull"
11
+ require_relative "init"
12
+ require_relative "nuget_cache"
13
+
14
+ module Makit
15
+ module Cli
16
+ # Define the main command which includes the subcommands
17
+ class MainCommand < Clamp::Command
18
+ option ["-v", "--version"], :flag, "Show version" do
19
+ puts "makit version #{Makit::VERSION}"
20
+ exit(0)
21
+ end
22
+ subcommand "new", "Create a new entity", NewCommand
23
+ subcommand "setup", "Setup a project directory", SetupCommand
24
+ subcommand "work", "Work on a project", WorkCommand
25
+ subcommand "make", "Make a project", MakeCommand
26
+ subcommand "clean", "Clean a project", CleanCommand
27
+ subcommand "clone", "Clone a git repository", CloneCommand
28
+ subcommand "pull", "Pull latest changes from a git repository", PullCommand
29
+ subcommand "init", "Initialize a directory as a git repository", InitCommand
30
+ subcommand "nuget_cache", "Manage the NuGet cache", NugetCacheCommand
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+ #require "git"
5
+ require "socket"
6
+ require_relative "../humanize"
7
+
8
+ module Makit
9
+ module Cli
10
+ # Define the 'make' subcommand
11
+ class MakeCommand < Clamp::Command
12
+ parameter "GIT_REPOSITORY", "The git repository URL or NAME", attribute_name: :git_repository, required: true
13
+ #option ["-f", "--force"], "FORCE", "Force the command to be run, even if a result already exists", attribute_name: :force
14
+
15
+ def execute
16
+ begin
17
+ # make sure a local clone of the repository exists
18
+ clone_dir = Directories::get_clone_directory(git_repository)
19
+ if Dir.exist?(clone_dir)
20
+ # attempt to the pull the latest changes
21
+ begin
22
+ PullCommand::pull(git_repository)
23
+ rescue => e
24
+ puts "warning: failed to pull repository: #{git_repository}"
25
+ end
26
+ else
27
+ CloneCommand::clone(git_repository)
28
+ end
29
+ rescue => e
30
+ $stderr.puts "failed to make repository: #{git_repository}"
31
+ puts "Please check the URL and your network connection."
32
+ puts e.message
33
+ exit 1
34
+ end
35
+
36
+ # determine the latest commit id for the repository
37
+ g = Git.open(clone_dir)
38
+ latest_commit = g.log.first
39
+ commit = latest_commit.sha
40
+
41
+ begin
42
+ #make_result = MakeCommand::make(git_repository, commit)
43
+ make_result = Makit::make(git_repository, commit)
44
+ puts make_result.summary
45
+ rescue => e
46
+ $stderr.puts "failed to make repository: #{git_repository} commit: #{commit}"
47
+ puts e.message
48
+ puts Makit::Humanize::get_make_result_summary make_result
49
+ exit 1
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+
5
+ module Makit
6
+ module Cli
7
+ # Define the 'new' subcommand
8
+ class NewCommand < Clamp::Command
9
+ AVAILABLE_TYPES = %w[gem crate nuget].freeze
10
+ option "--list", :flag, "List available types"
11
+ option ["-o", "--output"], "OUTPUT_DIR", "Specify output directory", default: "."
12
+ option ["-t", "--type"], "TYPE", "Type of the new entity", default: "gem"
13
+ parameter "TYPE", "Type of the new entity", attribute_name: :type, required: false
14
+ parameter "NAME", "Name of the new entity", attribute_name: :name, required: false
15
+ parameter "DIRECTORY", "The output directory", attribute_name: :name, required: false
16
+
17
+ def execute
18
+ if list?
19
+ puts "Available types:"
20
+ AVAILABLE_TYPES.each { |t| puts " - #{t}" }
21
+ else
22
+ if type.nil? || name.nil?
23
+ puts "Error: TYPE and NAME are required unless using --list"
24
+ exit(1)
25
+ end
26
+
27
+ unless AVAILABLE_TYPES.include?(type)
28
+ puts "Error: '#{type}' is not a valid type. Use --list to see available types."
29
+ exit(1)
30
+ end
31
+
32
+ puts "Creating a new #{type} named #{name}."
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+
5
+ module Makit
6
+ module Cli
7
+ # Define the 'nuget_cache' subcommand
8
+ #
9
+ # nuget_cache Google.Protobuf
10
+ # nuget_cache Google.Protobuf 3.27.2
11
+ class NugetCacheCommand < Clamp::Command
12
+ parameter "PACKAGE", "The package id", attribute_name: :package, required: true
13
+ parameter "VERSION", "The package version", attribute_name: :version, default: nil
14
+
15
+ def execute
16
+ if version.nil?
17
+ # look up the latest version of the package
18
+ raise "TODO: implement latest version lookup"
19
+ end
20
+
21
+ # download the package
22
+ url = "https://www.nuget.org/api/v2/package/#{package}/#{version}"
23
+ if !url.nil?
24
+ # download the package
25
+
26
+ raise "TODO: implement package download"
27
+ puts "url: #{url}"
28
+ puts "relative directoyr: #{Makit::Environment.get_relative_directory(url)}"
29
+ puts "work directory: #{Makit::Environment.get_work_directory(url)}"
30
+ end
31
+ puts "TODO: implement work command"
32
+ end
33
+ end
34
+
35
+ def install_cache_package(package, version)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+ #require "git"
5
+
6
+ module Makit
7
+ module Cli
8
+ # Define the 'pull' subcommand
9
+ class PullCommand < Clamp::Command
10
+ parameter "GIT_REPOSITORY", "The git repository url", attribute_name: :git_repository, required: true
11
+ option "--ignore-errors", :flag, "Ignore errors and present warnings instead of exiting"
12
+
13
+ def execute
14
+ puts "pulling latest changes for repository: #{git_repository}"
15
+ begin
16
+ Makit::pull(git_repository)
17
+ rescue Git::GitExecuteError => e
18
+ $stderr.puts "failed to pull repository: #{git_repository}"
19
+ puts "Please check the URL and your network connection."
20
+ exit 1
21
+ rescue => e
22
+ $stderr.puts "failed to pull repository: #{git_repository}"
23
+ puts e.message
24
+ exit 1
25
+ end
26
+ clone_dir = Directories::get_clone_directory(git_repository)
27
+ puts "size of clone directory: #{clone_dir} is #{Humanize::get_humanized_size(Directory::get_size(clone_dir))}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+
5
+ module Makit
6
+ module Cli
7
+ # Define the 'new' subcommand
8
+ class SetupCommand < Clamp::Command
9
+ PACKAGE_TYPES = %w[gem crate nuget].freeze
10
+ option "--list", :flag, "List available package types"
11
+ option ["-t", "--type"], "TYPE", "The package type", default: "gem"
12
+ option ["-o", "--output"], "OUTPUT", "The output directory", default: "."
13
+ parameter "TYPE", "Type of the package", attribute_name: :type, required: false
14
+ parameter "NAME", "Name of the package", attribute_name: :name, required: false
15
+
16
+ def execute
17
+ if list?
18
+ puts "Available package types:"
19
+ PACKAGE_TYPES.each { |t| puts " - #{t}" }
20
+ else
21
+ if type.nil? || name.nil?
22
+ puts "Error: TYPE and NAME are required unless using --list"
23
+ exit(1)
24
+ end
25
+
26
+ unless PACKAGE_TYPES.include?(type)
27
+ puts "Error: '#{type}' is not a valid type. Use --list to see available types."
28
+ exit(1)
29
+ end
30
+
31
+ if !Makit::IS_GIT_REPO
32
+ Makit::LOGGER.error("#{Dir.pwd} does not appear to be a git repository.")
33
+ exit(1)
34
+ end
35
+ if Makit::IS_READ_ONLY
36
+ Makit::LOGGER.error("The git repository is in a read-only state.")
37
+ exit(1)
38
+ end
39
+
40
+ # if a Rakefile already exists, then the project has already been setup
41
+ if File.exist?("Rakefile")
42
+ Makit::LOGGER.error("Rakefile detected, The project has already been setup.")
43
+ exit(1)
44
+ end
45
+
46
+ # verify the root directory has a .gitignore file
47
+ if !File.exist?(".gitignore")
48
+ Makit::LOGGER.info("added .gitignore file")
49
+ File.open(".gitignore", "w") do |file|
50
+ file.puts Makit::Content::GITIGNORE
51
+ end
52
+ end
53
+
54
+ # verify the root directory has a Rakefile
55
+
56
+ if (type == "gem")
57
+ if !File.exist?("Gemfile")
58
+ Makit::RUNNER.run("bundle gem . --coc --mit --exe --no-git --ci=gitlab_ci --test=minitest --changelog --linter=rubocop")
59
+
60
+ # overwrite the Rakefile with the one from the gem template
61
+ File.open("Rakefile", "w") do |file|
62
+ file.puts Makit::Content::GEM_RAKEFILE.gsub("GEM_NAME", name)
63
+ end
64
+ end
65
+ end
66
+ # Makit::LOGGER.info("bundle gem . --coc --mit --exe --no-git --ci=gitlab_ci --test=minitest --changelog --linter=rubocop --skip=Rakefile,README.md")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "clamp"
4
+
5
+ module Makit
6
+ module Cli
7
+ # Define the 'new' subcommand
8
+ class WorkCommand < Clamp::Command
9
+ option ["-u", "--url"], "URL", "The git repository url"
10
+
11
+ def execute
12
+ if !url.nil?
13
+ puts "url: #{url}"
14
+ puts "relative directoyr: #{Makit::Environment.get_relative_directory(url)}"
15
+ puts "work directory: #{Makit::Environment.get_work_directory(url)}"
16
+ end
17
+ puts "TODO: implement work command"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,237 @@
1
+ require "English"
2
+ require "open3"
3
+ require "socket"
4
+ require "etc"
5
+ require "logger"
6
+
7
+ # This module provides classes for the Makit gem.
8
+ module Makit
9
+ # This class provide methods running commands.
10
+ #
11
+ class CommandRunner
12
+ attr_accessor :show_output_on_success, :log_to_artifacts
13
+
14
+ def initialize
15
+ @show_output_on_success = false
16
+ @log_to_artifacts = false
17
+ end
18
+
19
+ def run(command_request)
20
+ raise "Invalid command_request" unless command_request.is_a? Makit::V1::CommandRequest
21
+ command = execute(command_request)
22
+ show_output = true
23
+ exit_on_error = true
24
+
25
+ log_to_artifacts(command) if @log_to_artifacts
26
+ if command.exit_code != 0
27
+ puts Makit::CommandRunner.get_command_summary(command) + " (exit code #{command.exit_code})".colorize(:default)
28
+ puts " directory: #{command.directory}\n"
29
+ puts " duration: #{command.duration.seconds} seconds\n"
30
+ puts Makit::Humanize::indent_string(command.output, 2) if command.output.length > 0
31
+ puts Makit::Humanize::indent_string(command.error, 2) if command.error.length > 0
32
+ exit 1 if command_request.exit_on_error
33
+ else
34
+ puts Makit::CommandRunner.get_command_summary(command) + " (#{command.duration.seconds} seconds)".colorize(:cyan)
35
+ puts Makit::Humanize::indent_string(command.output, 2).colorize(:default) if show_output_on_success
36
+ end
37
+
38
+ command
39
+ end
40
+
41
+ def log_to_artifacts(command)
42
+ dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
43
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
44
+ filename_friendly_timestamp = Time.now.strftime("%Y.%m.%d_%H%M%S")
45
+ log_filename = File.join(dir, "#{filename_friendly_timestamp}.json")
46
+ # serialize to protobuf json
47
+ json = command.to_json
48
+ pretty_json = JSON.pretty_generate(JSON.parse(json))
49
+ File.write(log_filename, pretty_json)
50
+ end
51
+
52
+ # Run a command and return a Makit::V1::Command.
53
+ def try(args)
54
+ request = parse_command_request(args)
55
+ request.exit_on_error = false
56
+ run(request)
57
+ #run2(args, false)
58
+ end
59
+
60
+ # Show the output of a command and return a Makit::V1::Command.
61
+ def show(args)
62
+ request = parse_args(args)
63
+ command = execute(request)
64
+
65
+ show_output = true
66
+ exit_on_error = true
67
+ Makit::LOGGER.info(Makit::CommandRunner.get_command_summary(command))
68
+ show_output = true if command.exit_code != 0
69
+ Makit::LOGGER.info(indent_string("\n#{command.output}\n#{command.error}\n".strip, 2)) if show_output
70
+ exit(command.exit_code) if exit_on_error && command.exit_code != 0 # unless process_status.success?
71
+ command
72
+ end
73
+
74
+ # Parse and return a Makit::V1::CommandRequest.
75
+ def parse_command_request(source)
76
+ return Makit::V1::CommandRequest.new(source) if source.is_a? Hash
77
+ return source if source.is_a? Makit::V1::CommandRequest
78
+ if source.is_a? String
79
+ return parse_args(source)
80
+ end
81
+
82
+ raise "Invalid source" unless source.is_a? Makit::V1::CommandRequest
83
+ end
84
+
85
+ def parse_command_request_from_hash(hash)
86
+ raise "Invalid hash" unless hash.is_a? Hash
87
+ Makit::V1::CommandRequest.new(hash)
88
+ end
89
+
90
+ def parse_command_request_from_string(source)
91
+ raise "Invalid source" unless source.is_a? String
92
+ words = source.split(" ")
93
+ hash = {
94
+ name: words.shift,
95
+ arguments: words,
96
+ exit_on_error: true,
97
+ }
98
+ end
99
+
100
+ # Parse the command line arguments into a Makit::V1::CommandRequest.
101
+ def parse_args(args)
102
+ #raise "No command specified" if args.empty?
103
+ if args.is_a? Makit::V1::CommandRequest
104
+ args
105
+ else
106
+ if args.is_a? String
107
+ args = args.split(" ")
108
+ if (args.length == 1)
109
+ hash = {
110
+ name: args[0],
111
+ arguments: [],
112
+ exit_on_error: true,
113
+ }
114
+ Makit::V1::CommandRequest.new(hash)
115
+ else
116
+ hash = {
117
+ name: args.shift,
118
+ arguments: args,
119
+ exit_on_error: true,
120
+ }
121
+
122
+ Makit::V1::CommandRequest.new(hash)
123
+ end
124
+ else
125
+ Makit::V1::CommandRequest.new(args)
126
+ end
127
+ end
128
+ end
129
+
130
+ def get_path_name(name)
131
+ # replace all characters that a not valid in a filename with an underscore
132
+ name.gsub(/[^0-9a-z]/i, "_")
133
+ end
134
+
135
+ # Given a Makit::V1::CommandRequest, execute the command and return a Makit::V1::Command.
136
+ def execute(args)
137
+ command_request = parse_args(args)
138
+ command_request.directory = Dir.pwd if command_request.directory.nil?
139
+ command_request.directory = Dir.pwd if command_request.directory.length == 0
140
+ result = Makit::V1::Command.new(name: command_request.name)
141
+ command_request.arguments.each do |arg|
142
+ result.arguments.push(arg)
143
+ end
144
+ command = "#{command_request.name} #{command_request.arguments.join(" ")}"
145
+ result.directory = command_request.directory
146
+ start = Time.now
147
+ filename_friendly_timestamp = Time.now.strftime("%Y.%m.%d_%H%M%S")
148
+ log_filename = File.join(Makit::Directories::LOG, "#{filename_friendly_timestamp}.log")
149
+
150
+ # assign a directory variable to the current working directory, if not specified,
151
+ # otherwise assign the specified directory
152
+ command_request.directory = Dir.pwd if command_request.directory.nil?
153
+ command_request.directory = Dir.pwd if command_request.directory.length == 0
154
+ raise "Invalid directory" unless Dir.exist?(command_request.directory)
155
+
156
+ result.started_at = Google::Protobuf::Timestamp.new(seconds: start.to_i, nanos: start.nsec.to_i)
157
+ ############# execute the command
158
+ (output, error, exit_code) = execute_command(command, command_request.directory, command_request.timeout)
159
+ result.output = output.force_encoding("ASCII-8BIT")
160
+ result.error = error.force_encoding("ASCII-8BIT")
161
+ result.exit_code = exit_code.nil? ? 0 : exit_code
162
+
163
+
164
+ elapsed_time = Time.now - start
165
+ seconds = elapsed_time.to_i
166
+ nanos = ((elapsed_time - seconds) * 1_000_000_000).to_i
167
+
168
+ result.duration = Google::Protobuf::Duration.new(seconds: seconds, nanos: nanos)
169
+
170
+ result
171
+ end
172
+
173
+ # pure function to execute a command
174
+ # returns (stdout, stderr, exit_code) or raise an exception
175
+ def execute_command(command, directory, timeout)
176
+ original_directory = Dir.pwd
177
+ begin
178
+ output = nil
179
+ error = nil
180
+ process_status = nil
181
+ Dir.chdir(directory) do
182
+ output, error, process_status = Open3.capture3(command)
183
+ end
184
+ return [output, error, process_status.exitstatus]
185
+ rescue => e
186
+ # restore the original working directory
187
+ Dir.chdir(original_directory)
188
+ message_parts = []
189
+ message_parts << "failed to execute #{command}"
190
+ message_parts << "directory: #{directory}"
191
+ message_parts << "timeout: #{timeout}" unless timeout.nil?
192
+ message_parts << "error: #{e.message}"
193
+ message = message_parts.join("\n") + "\n"
194
+ return ["", message, 1]
195
+ #raise Makit::Error, message
196
+ end
197
+ end
198
+
199
+ def execute_command_request(command_request)
200
+ # if the command_request is not a Makit::V1::CommandRequest, raise an error
201
+ raise "Invalid command_request" unless command_request.is_a? Makit::V1::CommandRequest
202
+
203
+ args = Array.new
204
+ command_request.arguments.each do |arg|
205
+ args.push(arg)
206
+ end
207
+ result = Makit::V1::Command.new({
208
+ name: command_request.name,
209
+ arguments: args,
210
+ started_at: Google::Protobuf::Timestamp.new({ seconds: Time.now.to_i, nanos: Time.now.nsec }),
211
+ })
212
+
213
+ begin
214
+ rescue => e
215
+ end
216
+ end
217
+
218
+ def indent_string(input_string, indent_spaces)
219
+ indentation = " " * indent_spaces
220
+ input_string.lines.map { |line| indentation + line }.join
221
+ end
222
+
223
+ def self.get_command_summary(command)
224
+ symbol = Makit::Symbols.warning
225
+ symbol = Makit::Symbols.checkmark if !command.exit_code.nil? && command.exit_code.zero?
226
+ symbol = Makit::Symbols.error if command.exit_code != 0
227
+ summary = "#{symbol} #{command.name.colorize(:yellow)} #{command.arguments.join(" ")}"
228
+
229
+ if summary.length > 80
230
+ summary = summary.to_lines(80,command.name.length+3)
231
+ end
232
+
233
+ summary
234
+ end
235
+
236
+ end # class CommandRunner
237
+ end # module Makit
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+ require "open3"
5
+ require "socket"
6
+ require "etc"
7
+ require "logger"
8
+
9
+ # This module provides classes for the Makit gem.
10
+ module Makit
11
+ # This class provide methods running commands.
12
+ #
13
+ class Commands < Array
14
+
15
+ # Generate the commands based on the current directory.
16
+ def auto_generate
17
+ self << Makit::V1::CommandRequest.new(name: "bundle", arguments: ["install"]) if File.exist?("Gemfile")
18
+ self << Makit::V1::CommandRequest.new(name: "bundle", arguments: ["exec", "rake"]) if File.exist?("Rakefile")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Makit
2
+ module Content
3
+ GITIGNORE = File.read(File.join(__dir__, "default_gitignore.txt"))
4
+ end # module Content
5
+ end # module Makit