makit 0.0.111 → 0.0.126

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/makit/cli/repository_commands.rb +1 -1
  3. data/lib/makit/commands/middleware/cache.rb +3 -3
  4. data/lib/makit/commands/middleware/command_logger.rb +33 -45
  5. data/lib/makit/commands/request.rb +63 -1
  6. data/lib/makit/commands/runner.rb +56 -5
  7. data/lib/makit/commands/strategies/base.rb +13 -2
  8. data/lib/makit/commands/strategies/synchronous.rb +11 -6
  9. data/lib/makit/commands.rb +8 -0
  10. data/lib/makit/configuration/gitlab_helper.rb +0 -2
  11. data/lib/makit/configuration/project.rb +48 -8
  12. data/lib/makit/configuration/step.rb +3 -3
  13. data/lib/makit/content/default_gitignore.txt +226 -0
  14. data/lib/makit/directories.rb +3 -4
  15. data/lib/makit/docs/files.rb +1 -1
  16. data/lib/makit/docs/rake.rb +1 -1
  17. data/lib/makit/dotnet/cli.rb +69 -65
  18. data/lib/makit/dotnet/project.rb +71 -7
  19. data/lib/makit/examples/runner.rb +2 -2
  20. data/lib/makit/logging/configuration.rb +9 -6
  21. data/lib/makit/logging/format_registry.rb +84 -84
  22. data/lib/makit/logging/formatters/console_formatter.rb +22 -9
  23. data/lib/makit/logging/log_request.rb +6 -2
  24. data/lib/makit/logging/logger.rb +45 -5
  25. data/lib/makit/logging/sinks/base.rb +91 -91
  26. data/lib/makit/logging/sinks/structured.rb +123 -129
  27. data/lib/makit/logging/sinks/unified_file_sink.rb +39 -46
  28. data/lib/makit/logging.rb +45 -1
  29. data/lib/makit/mp/project_mp.rb +6 -6
  30. data/lib/makit/mp/string_mp.rb +108 -265
  31. data/lib/makit/serializer.rb +14 -1
  32. data/lib/makit/services/builder.rb +5 -5
  33. data/lib/makit/services/repository_manager.rb +8 -6
  34. data/lib/makit/setup/classlib.rb +44 -7
  35. data/lib/makit/setup/gem.rb +268 -250
  36. data/lib/makit/setup/razorclasslib.rb +91 -0
  37. data/lib/makit/setup/runner.rb +36 -22
  38. data/lib/makit/setup.rb +5 -0
  39. data/lib/makit/symbols.rb +10 -1
  40. data/lib/makit/tasks/at_exit.rb +3 -1
  41. data/lib/makit/tasks/build.rb +16 -12
  42. data/lib/makit/tasks/clean.rb +2 -0
  43. data/lib/makit/tasks/configure.rb +10 -0
  44. data/lib/makit/tasks/format.rb +10 -0
  45. data/lib/makit/tasks/hook_manager.rb +160 -8
  46. data/lib/makit/tasks/init.rb +2 -0
  47. data/lib/makit/tasks/integrate.rb +17 -3
  48. data/lib/makit/tasks/pull_incoming.rb +6 -5
  49. data/lib/makit/tasks/setup.rb +10 -3
  50. data/lib/makit/tasks/sync.rb +13 -7
  51. data/lib/makit/tasks/tag.rb +16 -0
  52. data/lib/makit/tasks/task_monkey_patch.rb +58 -56
  53. data/lib/makit/tasks/test.rb +22 -0
  54. data/lib/makit/tasks/update.rb +18 -0
  55. data/lib/makit/tasks.rb +20 -5
  56. data/lib/makit/v1/makit.v1_pb.rb +1 -0
  57. data/lib/makit/version.rb +1 -1
  58. data/lib/makit/version_util.rb +21 -0
  59. data/lib/makit copy.rb +44 -0
  60. data/lib/makit.rb +31 -0
  61. metadata +118 -13
  62. data/lib/makit/command_runner.rb +0 -463
  63. data/lib/makit/commands/compatibility.rb +0 -365
  64. data/lib/makit/commands/middleware/unified_logger.rb +0 -243
  65. data/lib/makit/task_hooks.rb +0 -125
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
- # monkey patch String class with a run method
4
+ require "fileutils"
5
+ # monkey patch String class with command execution methods
5
6
 
6
7
  class String
7
8
  def run(args = nil)
8
9
  command = self
9
10
  if args.nil?
10
- Makit::COMMANDS_COMPAT.run(Makit::COMMANDS_COMPAT.parse_command_request(command))
11
+ request = Makit::Commands::Request.from_string(command)
11
12
  else
12
13
  # Parse initial request
13
- base_request = Makit::COMMANDS_COMPAT.parse_command_request(command)
14
+ base_request = Makit::Commands::Request.from_string(command)
14
15
 
15
16
  if args.is_a?(Hash)
16
17
  # Create new request with combined options
@@ -28,321 +29,163 @@ class String
28
29
  case key.to_s
29
30
  when "arguments"
30
31
  # Append additional arguments
31
- request_options[:arguments] = request_options[:arguments] + Array(value)
32
+ request_options[:arguments] = (request_options[:arguments] + Array(value)).flatten
32
33
  when "directory"
33
34
  request_options[:directory] = value
34
35
  when "timeout"
35
36
  request_options[:timeout] = value
36
37
  when "environment"
37
- request_options[:environment] = request_options[:environment].merge(value || {})
38
+ request_options[:environment] = (request_options[:environment] || {}).merge(value)
39
+ when "metadata"
40
+ request_options[:metadata] = (request_options[:metadata] || {}).merge(value)
38
41
  else
39
- # Store other options in metadata
40
- request_options[:metadata][key] = value
42
+ # Add unknown keys to metadata
43
+ request_options[:metadata] = (request_options[:metadata] || {}).merge(key.to_s => value)
41
44
  end
42
45
  end
43
46
 
44
- # Create new request with updated options
47
+ # Create new request with combined options
45
48
  request = Makit::Commands::Request.new(**request_options)
46
49
  else
47
- request = base_request
48
- end
49
-
50
- Makit::COMMANDS_COMPAT.run(request)
51
- end
52
- end
53
-
54
- def cache_run(timestamp = nil)
55
- command = self
56
- if timestamp.nil?
57
- # Use default timestamp from compatibility layer
58
- Makit::COMMANDS_COMPAT.cache_run(Makit::COMMANDS_COMPAT.parse_command_request(command))
59
- else
60
- Makit::COMMANDS_COMPAT.cache_run(Makit::COMMANDS_COMPAT.parse_command_request(command), timestamp)
61
- end
62
- end
63
-
64
- def try(args = nil)
65
- command = self
66
- if args.nil?
67
- Makit::COMMANDS_COMPAT.try(command)
68
- else
69
- # Parse initial request
70
- base_request = Makit::COMMANDS_COMPAT.parse_command_request(command)
71
-
72
- if args.is_a?(Hash)
73
- # Create new request with combined options
74
- request_options = {
50
+ # args is an array of additional arguments
51
+ request = Makit::Commands::Request.new(
75
52
  command: base_request.command,
76
- arguments: base_request.arguments || [],
53
+ arguments: (base_request.arguments || []) + Array(args),
77
54
  directory: base_request.directory,
78
55
  timeout: base_request.timeout,
79
56
  environment: base_request.environment || {},
80
57
  metadata: base_request.metadata || {},
81
- }
82
-
83
- # Apply args to the request options
84
- args.each do |key, value|
85
- case key.to_s
86
- when "arguments"
87
- # Append additional arguments
88
- request_options[:arguments] = request_options[:arguments] + Array(value)
89
- when "directory"
90
- request_options[:directory] = value
91
- when "timeout"
92
- request_options[:timeout] = value
93
- when "environment"
94
- request_options[:environment] = request_options[:environment].merge(value || {})
95
- else
96
- # Store other options in metadata
97
- request_options[:metadata][key] = value
98
- end
99
- end
100
-
101
- # Create new request with updated options
102
- request = Makit::Commands::Request.new(**request_options)
103
- else
104
- request = base_request
58
+ )
105
59
  end
106
-
107
- Makit::COMMANDS_COMPAT.try(request)
108
60
  end
61
+ Makit::Commands::Runner.default.execute(request)
109
62
  end
110
63
 
111
- def show(args = nil)
64
+ def cache_run(timestamp = nil)
65
+ puts "cache_run: #{self}"
112
66
  command = self
113
- if args.nil?
114
- Makit::COMMANDS_COMPAT.show(command)
67
+ request = Makit::Commands::Request.from_string(command)
68
+ if timestamp
69
+ # Add timestamp to metadata for cache key generation
70
+ request = Makit::Commands::Request.new(
71
+ command: request.command,
72
+ arguments: request.arguments,
73
+ directory: request.directory,
74
+ timeout: request.timeout,
75
+ environment: request.environment || {},
76
+ metadata: (request.metadata || {}).merge(timestamp: timestamp),
77
+ )
78
+ puts "timestamp: #{timestamp}"
115
79
  else
116
- # Parse initial request
117
- base_request = Makit::COMMANDS_COMPAT.parse_command_request(command)
118
-
119
- if args.is_a?(Hash)
120
- # Create new request with combined options
121
- request_options = {
122
- command: base_request.command,
123
- arguments: base_request.arguments || [],
124
- directory: base_request.directory,
125
- timeout: base_request.timeout,
126
- environment: base_request.environment || {},
127
- metadata: base_request.metadata || {},
128
- }
129
-
130
- # Apply args to the request options
131
- args.each do |key, value|
132
- case key.to_s
133
- when "arguments"
134
- # Append additional arguments
135
- request_options[:arguments] = request_options[:arguments] + Array(value)
136
- when "directory"
137
- request_options[:directory] = value
138
- when "timeout"
139
- request_options[:timeout] = value
140
- when "environment"
141
- request_options[:environment] = request_options[:environment].merge(value || {})
142
- else
143
- # Store other options in metadata
144
- request_options[:metadata][key] = value
145
- end
146
- end
147
-
148
- # Create new request with updated options
149
- request = Makit::Commands::Request.new(**request_options)
150
- else
151
- request = base_request
152
- end
153
-
154
- Makit::COMMANDS_COMPAT.show(request)
80
+ puts "no timestamp"
155
81
  end
82
+ Makit::Commands::Runner.default.execute(request)
156
83
  end
157
84
 
158
- def log(filename)
159
- # Ensure directory exists if filename contains path
160
- if filename.include?("/")
161
- directory = File.dirname(filename)
162
- FileUtils.mkdir_p(directory)
163
- end
85
+ def try
164
86
  command = self
87
+ request = Makit::Commands::Request.from_string(command).exit_on_failure(false)
88
+ Makit::Commands::Runner.default.execute(request)
89
+ end
165
90
 
166
- Makit::Logging.info("Logging command output to file", {
167
- command: command,
168
- log_file: filename,
169
- })
170
-
171
- cmd = Makit::COMMANDS_COMPAT.run(Makit::COMMANDS_COMPAT.parse_command_request(command))
91
+ def show
92
+ command = self
93
+ request = Makit::Commands::Request.from_string(command)
94
+ Makit::Commands::Runner.default.execute(request)
95
+ end
172
96
 
173
- # Write the cmd output and error to the file
174
- File.write(filename, cmd.output + cmd.error)
97
+ def log
98
+ command = self
99
+ request = Makit::Commands::Request.from_string(command)
100
+ result = Makit::Commands::Runner.default.execute(request)
175
101
 
176
- # Log the result
177
- if cmd.success?
178
- Makit::Logging.success("Command logged successfully", {
179
- command: command,
180
- log_file: filename,
181
- output_length: cmd.output.length,
182
- error_length: cmd.error.length,
183
- })
102
+ # Log the command execution result
103
+ if result.success?
104
+ Makit::Logging.info("Command completed successfully: #{command}")
184
105
  else
185
- Makit::Logging.error("Command failed and logged", {
186
- command: command,
187
- log_file: filename,
188
- exit_code: cmd.exit_code,
189
- output_length: cmd.output.length,
190
- error_length: cmd.error.length,
191
- })
106
+ Makit::Logging.error("Command failed: #{command} (exit code: #{result.exit_code})")
192
107
  end
193
108
 
194
- Makit::COMMANDS_COMPAT.show_command(cmd)
109
+ result
195
110
  end
196
111
 
197
- def cache_log(filename, timestamp = nil)
198
- # Ensure directory exists if filename contains path
199
- if filename.include?("/")
200
- directory = File.dirname(filename)
201
- FileUtils.mkdir_p(directory)
202
- end
112
+ def cache_try(timestamp = nil)
203
113
  command = self
114
+ request = Makit::Commands::Request.from_string(command)
115
+ if timestamp
116
+ # Add timestamp to metadata for cache key generation
117
+ request = Makit::Commands::Request.new(
118
+ command: request.command,
119
+ arguments: request.arguments,
120
+ directory: request.directory,
121
+ timeout: request.timeout,
122
+ environment: request.environment || {},
123
+ metadata: (request.metadata || {}).merge(timestamp: timestamp),
124
+ )
125
+ end
126
+ Makit::Commands::Runner.default.execute(request)
127
+ end
204
128
 
205
- #Makit::Logging.info("Cache logging command output", {
206
- # command: command,
207
- # log_file: filename,
208
- # timestamp: timestamp ? Makit::Humanize.get_humanized_timestamp(timestamp) : nil
209
- #})
210
-
211
- # Use cache_run with optional timestamp
212
- cmd = if timestamp.nil?
213
- Makit::COMMANDS_COMPAT.cache_run(Makit::COMMANDS_COMPAT.parse_command_request(command))
214
- else
215
- Makit::COMMANDS_COMPAT.cache_run(Makit::COMMANDS_COMPAT.parse_command_request(command), timestamp)
216
- end
217
-
218
- # Write the cached command output and error to the file
219
- File.write(filename, cmd.output + cmd.error)
220
-
221
- # Log the execution result
129
+ def show_command(cmd)
222
130
  if cmd.success?
223
- Makit::Logging.success(command)
224
- #Makit::Logging.success("Command executed and cached", {
225
- # command: command,
226
- # log_file: filename,
227
- # cached: true,
228
- # output_length: cmd.output.length,
229
- # error_length: cmd.error.length
230
- # })
131
+ puts "✅ #{cmd.command} #{cmd.arguments&.join(" ")}".colorize(:green)
231
132
  else
232
- Makit::Logging.error("Command failed and cached", {
233
- command: command,
234
- log_file: filename,
235
- exit_code: cmd.exit_code,
236
- cached: true,
237
- output_length: cmd.output.length,
238
- error_length: cmd.error.length,
239
- })
133
+ puts "❌ #{cmd.command} #{cmd.arguments&.join(" ")}".colorize(:red)
134
+ puts " Exit code: #{cmd.exit_code}".colorize(:red)
135
+ puts " Error: #{cmd.stderr}".colorize(:red) if cmd.stderr && !cmd.stderr.empty?
240
136
  end
241
-
242
- # Display detailed output and log location only if it failed
243
- return if cmd.success?
244
-
245
- Makit::COMMANDS_COMPAT.show_command(cmd)
246
- Makit::Logging.info("Log written to file", {
247
- log_file: File.expand_path(filename),
248
- })
249
137
  end
250
138
 
251
- def cache_try(timestamp = nil)
139
+ def to_markdown
252
140
  command = self
141
+ request = Makit::Commands::Request.from_string(command)
142
+ result = Makit::Commands::Runner.default.execute(request)
253
143
 
254
- Makit::Logging.info("Trying cached command execution", {
255
- command: command,
256
- timestamp: timestamp ? Makit::Humanize.get_humanized_timestamp(timestamp) : nil,
257
- })
258
-
259
- result = if timestamp.nil?
260
- # Use default timestamp from compatibility layer
261
- Makit::COMMANDS_COMPAT.cache_try(Makit::COMMANDS_COMPAT.parse_command_request(command))
262
- else
263
- Makit::COMMANDS_COMPAT.cache_try(Makit::COMMANDS_COMPAT.parse_command_request(command), timestamp)
264
- end
265
-
266
- # Log the result
267
144
  if result.success?
268
- Makit::Logging.success("Cached command executed successfully", {
269
- command: command,
270
- cached: true,
271
- duration: result.duration,
272
- })
145
+ "```\n#{result.stdout}\n```"
273
146
  else
274
- Makit::Logging.warn("Cached command failed", {
275
- command: command,
276
- exit_code: result.exit_code,
277
- cached: true,
278
- })
147
+ "```\nError: #{result.stderr}\n```"
279
148
  end
280
-
281
- result
282
149
  end
283
150
 
284
- # Read a value from a JSON file
285
- # key is a string with the key to read, e.g. "AzureAd.Authority"
286
- def get_json_value(key)
287
- json = File.read(self)
288
- data = JSON.parse(json)
289
-
290
- # key delimiter is '.' so we can access nested keys
291
- key.split(".").each do |k|
292
- data = data[k]
293
- end
294
- data
151
+ def cache_run_with_timestamp(timestamp)
152
+ command = self
153
+ request = Makit::Commands::Request.from_string(command)
154
+ request = Makit::Commands::Request.new(
155
+ command: request.command,
156
+ arguments: request.arguments,
157
+ directory: request.directory,
158
+ timeout: request.timeout,
159
+ environment: request.environment || {},
160
+ metadata: (request.metadata || {}).merge(timestamp: timestamp),
161
+ )
162
+ Makit::Commands::Runner.default.execute(request)
295
163
  end
296
164
 
297
- alias retrieve get_json_value
298
-
299
- # Set a value in a JSON file
300
- # key is a string with the key to set, e.g. "AzureAd.Authority"
301
- def set_json_value(key, value)
302
- file = File.read(self)
303
- data = JSON.parse(file)
304
- keys = key.split(".")
305
- current = data
306
-
307
- # Traverse and create any missing keys
308
- keys[0..-2].each do |k|
309
- current[k] ||= {} # Create a new hash if the key doesn't exist
310
- current = current[k]
311
- end
312
-
313
- # Set the value for the final key
314
- current[keys[-1]] = value
315
-
316
- # Write the JSON back to the file
317
- File.write(self, JSON.pretty_generate(data))
165
+ def cache_try_with_timestamp(timestamp)
166
+ command = self
167
+ request = Makit::Commands::Request.from_string(command)
168
+ request = Makit::Commands::Request.new(
169
+ command: request.command,
170
+ arguments: request.arguments,
171
+ directory: request.directory,
172
+ timeout: request.timeout,
173
+ environment: request.environment || {},
174
+ metadata: (request.metadata || {}).merge(timestamp: timestamp),
175
+ )
176
+ Makit::Commands::Runner.default.execute(request)
318
177
  end
319
178
 
320
- # Alias for set_json_value
321
- alias assign set_json_value
322
-
323
- def strip_color_codes
324
- # Regular expression to remove ANSI color codes
325
- gsub(/\e\[[\d;]+m/, "")
326
- end
179
+ def cache_log(log_file)
180
+ command = self
181
+ request = Makit::Commands::Request.from_string(command)
182
+ result = Makit::Commands::Runner.default.execute(request)
327
183
 
328
- def to_lines(max_length = 80, indent_length = 5)
329
- return self if length <= max_length
184
+ # Write output to log file
185
+ FileUtils.mkdir_p(File.dirname(log_file))
186
+ File.write(log_file, result.stdout) if result.stdout && !result.stdout.empty?
187
+ File.write(log_file, result.stderr, mode: "a") if result.stderr && !result.stderr.empty?
330
188
 
331
- indent = " " * indent_length
332
- words = split(" ")
333
- lines = []
334
- line = ""
335
- words.each do |word|
336
- if (line + word).length > max_length
337
- lines << line
338
- line = indent + word
339
- elsif line.empty?
340
- line = word
341
- else
342
- line += " #{word}"
343
- end
344
- end
345
- lines << line
346
- lines.join("\n")
189
+ result
347
190
  end
348
191
  end
@@ -1,6 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "google/protobuf"
3
+ begin
4
+ require "google/protobuf"
5
+ rescue LoadError
6
+ # google-protobuf gem not available, define a minimal protobuf interface
7
+ module Google
8
+ module Protobuf
9
+ class Message
10
+ def to_json(*_args)
11
+ {}
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
4
17
  # This module provides classes for the Makit gem.
5
18
  module Makit
6
19
  module Proto3Formats
@@ -110,7 +110,7 @@ module Makit
110
110
  make_dir = Directories.get_make_commit_directory(url, commit)
111
111
  FileUtils.rm_rf(make_dir)
112
112
 
113
- clone_command = Makit::RUNNER.execute("git clone #{clone_dir} #{make_dir}")
113
+ clone_command = Makit::Commands::Runner.default.execute("git clone #{clone_dir} #{make_dir}")
114
114
  commands << clone_command
115
115
 
116
116
  return if Dir.exist?(make_dir)
@@ -132,17 +132,17 @@ module Makit
132
132
 
133
133
  # Execute git-specific commands for the build
134
134
  def execute_git_commands(commit, commands)
135
- commands << Makit::RUNNER.execute("git reset --hard #{commit}")
136
- commands << Makit::RUNNER.execute("git log -n 1")
135
+ commands << Makit::Commands::Runner.default.execute("git reset --hard #{commit}")
136
+ commands << Makit::Commands::Runner.default.execute("git log -n 1")
137
137
  end
138
138
 
139
139
  # Execute build commands (bundle, rake, etc.)
140
140
  def execute_build_commands(commands)
141
- commands << Makit::RUNNER.execute("bundle install") if File.exist?("Gemfile")
141
+ commands << Makit::Commands::Runner.default.execute("bundle install") if File.exist?("Gemfile")
142
142
 
143
143
  return unless File.exist?("Rakefile") || File.exist?("rakefile.rb")
144
144
 
145
- commands << Makit::RUNNER.execute("rake default")
145
+ commands << Makit::Commands::Runner.default.execute("rake default")
146
146
  end
147
147
 
148
148
  # Create the make result object
@@ -22,7 +22,7 @@ module Makit
22
22
 
23
23
  Dir.chdir(directory) do
24
24
  File.write(".gitignore", Makit::Content::GITIGNORE) unless File.exist?(".gitignore")
25
- init_command = Makit::RUNNER.execute("git init")
25
+ init_command = Makit::Commands::Runner.default.execute("git init")
26
26
 
27
27
  if init_command.exit_code != 0
28
28
  raise Makit::GitError, "failed to initialize local repository: #{directory}\\n#{Makit::Humanize.get_command_summary(init_command)}"
@@ -41,7 +41,9 @@ module Makit
41
41
  commands = []
42
42
 
43
43
  clone_dir = Directories.get_clone_directory(git_repository)
44
- commands << Makit::RUNNER.execute("git clone #{git_repository} #{clone_dir}") unless Dir.exist?(clone_dir)
44
+ unless Dir.exist?(clone_dir)
45
+ commands << Makit::Commands::Runner.default.execute("git clone #{git_repository} #{clone_dir}")
46
+ end
45
47
 
46
48
  commands
47
49
  end
@@ -91,7 +93,7 @@ module Makit
91
93
  Validator.validate_directory_exists(clone_dir, "clone directory")
92
94
 
93
95
  Dir.chdir(clone_dir) do
94
- log_command = Makit::RUNNER.execute("git log -n #{limit} --skip #{skip} --date=iso")
96
+ log_command = Makit::Commands::Runner.default.execute("git log -n #{limit} --skip #{skip} --date=iso")
95
97
  parse_git_log_output(log_command)
96
98
  end
97
99
  end
@@ -114,7 +116,7 @@ module Makit
114
116
  # @return [String] the latest commit hash
115
117
  def get_latest_commit(clone_dir, commands)
116
118
  Dir.chdir(clone_dir) do
117
- git_log = Makit::RUNNER.execute("git log -n 1 --date=iso")
119
+ git_log = Makit::Commands::Runner.default.execute("git log -n 1 --date=iso")
118
120
  commands << git_log
119
121
 
120
122
  commit = git_log.output.match(/^commit ([0-9a-f]{#{Validator::COMMIT_HASH_LENGTH}})$/i)&.captures&.first
@@ -146,7 +148,7 @@ module Makit
146
148
  arguments: ["pull"],
147
149
  directory: clone_dir,
148
150
  )
149
- pull_command = Makit::RUNNER.execute(request)
151
+ pull_command = Makit::Commands::Runner.default.execute(request)
150
152
 
151
153
  raise Makit::PullError, Makit::Humanize.get_command_details(pull_command) if pull_command.exit_code != 0
152
154
 
@@ -160,7 +162,7 @@ module Makit
160
162
 
161
163
  unless Dir.exist?(work_dir)
162
164
  FileUtils.mkdir_p(File.dirname(work_dir))
163
- Makit::RUNNER.execute("git clone #{clone_dir} #{work_dir}")
165
+ Makit::Commands::Runner.default.execute("git clone #{clone_dir} #{work_dir}")
164
166
  end
165
167
 
166
168
  Dir.chdir(work_dir) do
@@ -1,31 +1,67 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "../configuration/project"
3
4
 
4
5
  module Makit
5
6
  module Setup
6
7
  class ClassLib
7
8
  def self.run
8
- #puts "Setting up Nuget project..."
9
+ # puts "Setting up Nuget project..."
9
10
  project = Makit::Configuration::Project.default
10
11
  Makit::DotNet::Project.new_project("classlib", project.name, "source/#{project.name}", "--framework net8.0")
12
+ dotnet_project = Makit::DotNet::Project.new("source/#{project.name}/#{project.name}.csproj")
13
+ # set the version to project.version
14
+ dotnet_project.set_version(project.version)
15
+ # set the frameworks = ["net8.0","net8.0-browser"]
16
+ dotnet_project.set_target_frameworks(["net8.0", "net8.0-browser"])
17
+ # set the nuget metadata
18
+ dotnet_project.set_nuget_metadata(project.name, project.authors, project.description,
19
+ project.license_expression)
11
20
  Makit::DotNet::Project.new_project("TUnit", "#{project.name}.Tests", "tests/#{project.name}")
12
- Makit::DotNet::Project.add_reference("tests/#{project.name}/#{project.name}.Tests.csproj", "source/#{project.name}/#{project.name}.csproj")
21
+ dotnet_project = Makit::DotNet::Project.new("tests/#{project.name}/#{project.name}.Tests.csproj")
22
+ # set the version to project.version
23
+ dotnet_project.set_version(project.version)
24
+ # set the frameworks = ["net8.0","net8.0-browser"]
25
+ dotnet_project.set_target_frameworks(["net8.0", "net8.0-browser"])
26
+ # set the nuget metadata
27
+ dotnet_project.set_nuget_metadata("#{project.name}.Tests", project.authors, project.description,
28
+ project.license_expression)
29
+ Makit::DotNet::Project.add_reference("tests/#{project.name}/#{project.name}.Tests.csproj",
30
+ "source/#{project.name}/#{project.name}.csproj")
13
31
  update_build_step(project)
14
32
  update_test_step(project)
15
33
 
16
34
  project.save
17
- Makit::Logging.default_logger.info("Project setup completed")
35
+
36
+ # Setup the sln, then slnx
37
+ Makit::DotNet.new_solution(project.name)
38
+ Makit::DotNet.sln_add_projects(project.name)
39
+ # migrate the sln to slnx
40
+ "dotnet sln migrate #{project.name}.sln".run
41
+ FileUtils.rm_f("#{project.name}.sln") if File.exist?("#{project.name}.slnx")
42
+ Makit::Logging.default_logger.debug("Project setup completed")
18
43
  end
19
44
 
20
45
  def self.update_build_step(project)
21
- build_commands = Array.new
46
+ build_commands = []
47
+ build_commands << "dotnet restore #{project.name}.slnx" if File.exist?("#{project.name}.slnx")
22
48
  build_commands << "dotnet build source/#{project.name}/#{project.name}.csproj --configuration Release"
49
+ build_commands << "dotnet build tests/#{project.name}/#{project.name}.Tests.csproj --configuration Release"
50
+ build_commands << "dotnet pack source/#{project.name}/#{project.name}.csproj --configuration Release --output artifacts/Packages"
51
+ build_commands << "dotnet pack tests/#{project.name}/#{project.name}.Tests.csproj --configuration Release --output artifacts/Packages"
52
+ if File.exist?("source/#{project.name}.Pages/#{project.name}.Pages.csproj")
53
+ build_commands << "dotnet build source/#{project.name}.Pages/#{project.name}.Pages.csproj --configuration Release"
54
+ end
55
+ if File.exist?("source/#{project.name}.Pages/#{project.name}.Pages.csproj")
56
+ build_commands << "dotnet publish source/#{project.name}.Pages/#{project.name}.Pages.csproj --configuration Release --output artifacts/Pages"
57
+ end
23
58
  steps = project.steps
24
59
  if steps.any? { |step| step.name == "build" }
25
60
  build_step = steps.find { |step| step.name == "build" }
26
61
  build_step.commands = build_commands
27
62
  else
28
- build_step = Makit::Configuration::Step.new(name: "build", description: "Build the project artifacts", commands: build_commands)
63
+ build_step = Makit::Configuration::Step.new(name: "build", description: "Build the project artifacts",
64
+ commands: build_commands)
29
65
  build_step.commands = build_commands
30
66
  project.add_step(build_step)
31
67
  end
@@ -35,14 +71,15 @@ module Makit
35
71
  end
36
72
 
37
73
  def self.update_test_step(project)
38
- test_commands = Array.new
74
+ test_commands = []
39
75
  test_commands << "dotnet test tests/#{project.name}/#{project.name}.Tests.csproj"
40
76
  steps = project.steps
41
77
  if steps.any? { |step| step.name == "test" }
42
78
  test_step = steps.find { |step| step.name == "test" }
43
79
  test_step.commands = test_commands
44
80
  else
45
- test_step = Makit::Configuration::Step.new(name: "test", description: "Run the project tests", commands: test_commands)
81
+ test_step = Makit::Configuration::Step.new(name: "test", description: "Run the project tests",
82
+ commands: test_commands)
46
83
  test_step.commands = test_commands
47
84
  project.add_step(test_step)
48
85
  end