makit 0.0.98 → 0.0.111

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -0
  3. data/exe/makit +5 -0
  4. data/lib/makit/apache.rb +7 -11
  5. data/lib/makit/cli/build_commands.rb +500 -0
  6. data/lib/makit/cli/generators/base_generator.rb +74 -0
  7. data/lib/makit/cli/generators/dotnet_generator.rb +50 -0
  8. data/lib/makit/cli/generators/generator_factory.rb +49 -0
  9. data/lib/makit/cli/generators/node_generator.rb +50 -0
  10. data/lib/makit/cli/generators/ruby_generator.rb +77 -0
  11. data/lib/makit/cli/generators/rust_generator.rb +50 -0
  12. data/lib/makit/cli/generators/templates/dotnet_templates.rb +167 -0
  13. data/lib/makit/cli/generators/templates/node_templates.rb +161 -0
  14. data/lib/makit/cli/generators/templates/ruby/gemfile.rb +26 -0
  15. data/lib/makit/cli/generators/templates/ruby/gemspec.rb +40 -0
  16. data/lib/makit/cli/generators/templates/ruby/main_lib.rb +33 -0
  17. data/lib/makit/cli/generators/templates/ruby/rakefile.rb +35 -0
  18. data/lib/makit/cli/generators/templates/ruby/readme.rb +63 -0
  19. data/lib/makit/cli/generators/templates/ruby/test.rb +39 -0
  20. data/lib/makit/cli/generators/templates/ruby/test_helper.rb +29 -0
  21. data/lib/makit/cli/generators/templates/ruby/version.rb +29 -0
  22. data/lib/makit/cli/generators/templates/rust_templates.rb +128 -0
  23. data/lib/makit/cli/main.rb +48 -19
  24. data/lib/makit/cli/project_commands.rb +868 -0
  25. data/lib/makit/cli/repository_commands.rb +661 -0
  26. data/lib/makit/cli/utility_commands.rb +521 -0
  27. data/lib/makit/command_runner.rb +187 -128
  28. data/lib/makit/commands/compatibility.rb +365 -0
  29. data/lib/makit/commands/factory.rb +359 -0
  30. data/lib/makit/commands/middleware/base.rb +73 -0
  31. data/lib/makit/commands/middleware/cache.rb +248 -0
  32. data/lib/makit/commands/middleware/command_logger.rb +323 -0
  33. data/lib/makit/commands/middleware/unified_logger.rb +243 -0
  34. data/lib/makit/commands/middleware/validator.rb +269 -0
  35. data/lib/makit/commands/request.rb +254 -0
  36. data/lib/makit/commands/result.rb +323 -0
  37. data/lib/makit/commands/runner.rb +317 -0
  38. data/lib/makit/commands/strategies/base.rb +160 -0
  39. data/lib/makit/commands/strategies/synchronous.rb +134 -0
  40. data/lib/makit/commands.rb +24 -3
  41. data/lib/makit/configuration/gitlab_helper.rb +60 -0
  42. data/lib/makit/configuration/project.rb +127 -0
  43. data/lib/makit/configuration/rakefile_helper.rb +43 -0
  44. data/lib/makit/configuration/step.rb +34 -0
  45. data/lib/makit/configuration.rb +14 -0
  46. data/lib/makit/content/default_gitignore.rb +4 -2
  47. data/lib/makit/content/default_rakefile.rb +4 -2
  48. data/lib/makit/content/gem_rakefile.rb +4 -2
  49. data/lib/makit/context.rb +1 -0
  50. data/lib/makit/data.rb +9 -10
  51. data/lib/makit/directories.rb +48 -52
  52. data/lib/makit/directory.rb +38 -52
  53. data/lib/makit/docs/files.rb +5 -10
  54. data/lib/makit/docs/rake.rb +16 -20
  55. data/lib/makit/dotnet/cli.rb +65 -0
  56. data/lib/makit/dotnet/project.rb +153 -0
  57. data/lib/makit/dotnet/solution.rb +38 -0
  58. data/lib/makit/dotnet/solution_classlib.rb +239 -0
  59. data/lib/makit/dotnet/solution_console.rb +264 -0
  60. data/lib/makit/dotnet/solution_maui.rb +354 -0
  61. data/lib/makit/dotnet/solution_wasm.rb +275 -0
  62. data/lib/makit/dotnet/solution_wpf.rb +304 -0
  63. data/lib/makit/dotnet.rb +54 -171
  64. data/lib/makit/email.rb +46 -17
  65. data/lib/makit/environment.rb +22 -19
  66. data/lib/makit/examples/runner.rb +370 -0
  67. data/lib/makit/exceptions.rb +45 -0
  68. data/lib/makit/fileinfo.rb +3 -5
  69. data/lib/makit/files.rb +12 -16
  70. data/lib/makit/gems.rb +40 -39
  71. data/lib/makit/git/cli.rb +54 -0
  72. data/lib/makit/git/repository.rb +90 -0
  73. data/lib/makit/git.rb +44 -91
  74. data/lib/makit/gitlab_runner.rb +0 -1
  75. data/lib/makit/humanize.rb +31 -23
  76. data/lib/makit/indexer.rb +15 -24
  77. data/lib/makit/logging/configuration.rb +305 -0
  78. data/lib/makit/logging/format_registry.rb +84 -0
  79. data/lib/makit/logging/formatters/base.rb +39 -0
  80. data/lib/makit/logging/formatters/console_formatter.rb +127 -0
  81. data/lib/makit/logging/formatters/json_formatter.rb +65 -0
  82. data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -0
  83. data/lib/makit/logging/formatters/text_formatter.rb +64 -0
  84. data/lib/makit/logging/log_request.rb +115 -0
  85. data/lib/makit/logging/logger.rb +159 -0
  86. data/lib/makit/logging/sinks/base.rb +91 -0
  87. data/lib/makit/logging/sinks/console.rb +72 -0
  88. data/lib/makit/logging/sinks/file_sink.rb +92 -0
  89. data/lib/makit/logging/sinks/structured.rb +129 -0
  90. data/lib/makit/logging/sinks/unified_file_sink.rb +303 -0
  91. data/lib/makit/logging.rb +452 -37
  92. data/lib/makit/markdown.rb +18 -18
  93. data/lib/makit/mp/basic_object_mp.rb +5 -4
  94. data/lib/makit/mp/command_mp.rb +5 -5
  95. data/lib/makit/mp/command_request.mp.rb +3 -2
  96. data/lib/makit/mp/project_mp.rb +85 -96
  97. data/lib/makit/mp/string_mp.rb +245 -73
  98. data/lib/makit/nuget.rb +27 -25
  99. data/lib/makit/port.rb +25 -27
  100. data/lib/makit/process.rb +127 -29
  101. data/lib/makit/protoc.rb +27 -24
  102. data/lib/makit/rake/cli.rb +196 -0
  103. data/lib/makit/rake.rb +6 -6
  104. data/lib/makit/ruby/cli.rb +185 -0
  105. data/lib/makit/ruby.rb +25 -0
  106. data/lib/makit/secrets.rb +18 -18
  107. data/lib/makit/serializer.rb +29 -27
  108. data/lib/makit/services/builder.rb +186 -0
  109. data/lib/makit/services/error_handler.rb +226 -0
  110. data/lib/makit/services/repository_manager.rb +229 -0
  111. data/lib/makit/services/validator.rb +112 -0
  112. data/lib/makit/setup/classlib.rb +53 -0
  113. data/lib/makit/setup/gem.rb +250 -0
  114. data/lib/makit/setup/runner.rb +40 -0
  115. data/lib/makit/show.rb +16 -16
  116. data/lib/makit/storage.rb +32 -37
  117. data/lib/makit/symbols.rb +12 -0
  118. data/lib/makit/task_hooks.rb +125 -0
  119. data/lib/makit/task_info.rb +63 -21
  120. data/lib/makit/tasks/at_exit.rb +13 -0
  121. data/lib/makit/tasks/build.rb +18 -0
  122. data/lib/makit/tasks/clean.rb +11 -0
  123. data/lib/makit/tasks/hook_manager.rb +239 -0
  124. data/lib/makit/tasks/init.rb +47 -0
  125. data/lib/makit/tasks/integrate.rb +15 -0
  126. data/lib/makit/tasks/pull_incoming.rb +12 -0
  127. data/lib/makit/tasks/setup.rb +6 -0
  128. data/lib/makit/tasks/sync.rb +11 -0
  129. data/lib/makit/tasks/task_monkey_patch.rb +79 -0
  130. data/lib/makit/tasks.rb +5 -150
  131. data/lib/makit/test_cache.rb +239 -0
  132. data/lib/makit/v1/makit.v1_pb.rb +34 -35
  133. data/lib/makit/v1/makit.v1_services_pb.rb +2 -0
  134. data/lib/makit/version.rb +1 -60
  135. data/lib/makit/wix.rb +23 -23
  136. data/lib/makit/yaml.rb +18 -6
  137. data/lib/makit.rb +2 -261
  138. metadata +109 -145
  139. data/lib/makit/cli/clean.rb +0 -14
  140. data/lib/makit/cli/clone.rb +0 -59
  141. data/lib/makit/cli/init.rb +0 -38
  142. data/lib/makit/cli/make.rb +0 -54
  143. data/lib/makit/cli/new.rb +0 -37
  144. data/lib/makit/cli/nuget_cache.rb +0 -38
  145. data/lib/makit/cli/pull.rb +0 -31
  146. data/lib/makit/cli/setup.rb +0 -71
  147. data/lib/makit/cli/work.rb +0 -21
  148. data/lib/makit/content/default_gitignore.txt +0 -222
@@ -1,57 +1,93 @@
1
- # lib/task_guard.rb
1
+ # frozen_string_literal: true
2
+
3
+ # Task timing and performance tracking utilities
2
4
  module Makit
5
+ # Task execution time tracking and reporting
6
+ #
7
+ # This class provides functionality to track the execution time of tasks,
8
+ # store timing information, and generate performance reports. It's designed
9
+ # to help identify performance bottlenecks in build processes.
3
10
  class TaskInfo
4
-
5
11
  #
6
- # completed_tasks is a class variable that is used to store the completed tasks
12
+ # Class variable to store completed task information
7
13
  #
8
14
  class << self
9
15
  attr_accessor :completed_tasks
10
16
  end
11
17
  @completed_tasks = {}
12
18
 
19
+ # @return [String] Name of the task being tracked
20
+ # @return [Time] Time when task execution started
21
+ # @return [Time] Time when task execution ended
22
+ # @return [String] Directory path for task artifacts
13
23
  attr_reader :task_name, :start_time, :end_time, :artifacts_dir
14
24
 
25
+ # Get the name of the slowest completed task
26
+ #
27
+ # Analyzes all completed tasks and returns the name of the one
28
+ # with the longest execution duration.
29
+ #
30
+ # @return [String] Name of the slowest task, or "unknown" if no tasks completed
15
31
  def self.slowest_task_name
16
- if @completed_tasks.empty?
17
- return "unknown"
18
- end
19
- @completed_tasks.max_by { |task_name, task_info| task_info[:duration] }[0]
32
+ return "unknown" if @completed_tasks.empty?
33
+
34
+ @completed_tasks.max_by { |_task_name, task_info| task_info[:duration] }[0]
20
35
  end
21
36
 
37
+ # Track execution time of a task with a block
22
38
  #
23
- # block-yielding initializer
24
- #
25
- # usage:
39
+ # Creates a new TaskInfo instance, displays the task name,
40
+ # executes the provided block, and ensures timing is reported
41
+ # even if an exception occurs.
26
42
  #
27
- # Makit::TaskInfo.track(:generate) do
28
- # # generate code
29
- # end
43
+ # @param task_name [String, Symbol] Name of the task to track
44
+ # @yield [TaskInfo] The task info instance for use within the block
45
+ # @return [Object] Result of the yielded block
30
46
  #
47
+ # @example
48
+ # Makit::TaskInfo.track(:generate) do
49
+ # # generate code
50
+ # end
31
51
  def self.track(task_name)
32
52
  task = new(task_name)
33
53
  Makit::SHOW.task(task_name)
34
54
  yield(task)
35
55
  ensure
36
- task.report_and_store_time_taken if task
56
+ task&.report_and_store_time_taken
37
57
  end
38
58
 
59
+ # Track execution time with inferred task name
39
60
  #
40
- # Block-yielding initializer with inferred task name
61
+ # Similar to track() but attempts to infer the task name automatically.
62
+ # Currently returns nil as task name inference is not implemented.
41
63
  #
42
- def self.track_inferred
64
+ # @yield [TaskInfo] The task info instance for use within the block
65
+ # @return [Object] Result of the yielded block
66
+ def self.track_inferred(&block)
43
67
  task_name = infer_task_name
44
68
  Makit::SHOW.task(task_name)
45
- track(task_name) { |task| yield(task) }
69
+ track(task_name, &block)
46
70
  end
47
71
 
72
+ # Initialize a new task tracking instance
73
+ #
74
+ # Sets up timing tracking for a named task, creates an artifacts
75
+ # directory path, and records the start time.
76
+ #
77
+ # @param task_name [String, Symbol] Name of the task to track
48
78
  def initialize(task_name)
49
79
  @task_name = task_name
50
80
  @artifacts_dir = File.join("artifacts", task_name.to_s.gsub(":", "_"))
51
81
  @start_time = Time.now
52
- #at_exit { report_and_store_time_taken }
82
+ # at_exit { report_and_store_time_taken }
53
83
  end
54
84
 
85
+ # Report and store the task execution time
86
+ #
87
+ # Calculates the duration, displays a human-readable completion message,
88
+ # and stores the timing information in the class-level completed_tasks hash.
89
+ #
90
+ # @return [nil]
55
91
  def report_and_store_time_taken
56
92
  @end_time = Time.now
57
93
  duration = @end_time - @start_time
@@ -59,7 +95,7 @@ module Makit
59
95
  # leverate the Makit::Humanize.get_humanized_duration method
60
96
  humanized_duration = Makit::Humanize.get_humanized_duration(duration)
61
97
  puts " #{@task_name} completed in #{humanized_duration}".colorize(:grey)
62
- #puts "[TaskGuard] Task '#{@task_name}' completed in #{duration}."
98
+ # puts "[TaskGuard] Task '#{@task_name}' completed in #{duration}."
63
99
 
64
100
  # Add to class-level storage
65
101
  self.class.completed_tasks[@task_name] = {
@@ -69,7 +105,7 @@ module Makit
69
105
  }
70
106
  end
71
107
 
72
- #def format_duration(seconds)
108
+ # def format_duration(seconds)
73
109
  # if seconds >= 60
74
110
  # mins = (seconds / 60).to_i
75
111
  # secs = (seconds % 60).round(2)
@@ -79,8 +115,14 @@ module Makit
79
115
  # end
80
116
  # end
81
117
 
118
+ # Attempt to infer the current task name
119
+ #
120
+ # This method would extract the current Rake task name from the
121
+ # application context, but is currently not implemented.
122
+ #
123
+ # @return [String, nil] The inferred task name, or nil if unavailable
82
124
  def self.infer_task_name
83
- #Rake.application.current_scope.join(":") rescue "unknown"
125
+ # Rake.application.current_scope.join(":") rescue "unknown"
84
126
  end
85
127
  end
86
128
  end
@@ -0,0 +1,13 @@
1
+ require "English"
2
+
3
+ at_exit do
4
+ command = "rake #{ARGV.join(" ")}"
5
+ duration = Time.now - Makit::STARTTIME
6
+ message = "#{command} (#{Makit::Humanize.get_humanized_duration(duration)})"
7
+ # detect if the rake execution was successful
8
+ if $ERROR_INFO.nil?
9
+ Makit::Logging.default_logger.info(message)
10
+ else
11
+ Makit::Logging.default_logger.error(message)
12
+ end # display the humanized duration of the rake execution
13
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "../setup/runner"
2
+
3
+ desc "Build project artifacts.."
4
+ task :build do
5
+ # load the default project configuration
6
+ project = Makit::Configuration::Project.default
7
+
8
+ # for each step in the project configuration, run the commands
9
+ project.steps.each do |step|
10
+ step.commands.each do |command|
11
+ request = Makit::Commands::Request.from_string(command)
12
+ result = Makit::Commands::Runner.default.execute(request)
13
+ end
14
+ end
15
+
16
+ # Make sure the build commands are in the project configuration
17
+
18
+ end
@@ -0,0 +1,11 @@
1
+ require "rake/clean"
2
+ require_relative "../git/repository"
3
+ require_relative "../commands/runner"
4
+
5
+ CLEAN.include("artifacts/**/*")
6
+
7
+ task :clean do
8
+ if Makit::Git::Repository.git_repo?
9
+ Makit::Commands::Runner.default.execute(Makit::Commands::Request.from_string("git clean -dXf"))
10
+ end
11
+ end
@@ -0,0 +1,239 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+ require "colorize"
5
+
6
+ # Task hooks system for Makit
7
+ #
8
+ # This module provides a comprehensive hook system for Rake tasks, allowing
9
+ # developers to add pre and post execution hooks globally or for specific tasks.
10
+ # It uses monkey patching to intercept all task invocations and execute hooks
11
+ # at the appropriate times.
12
+ #
13
+ # @example Global hooks
14
+ # Makit::Tasks::HookManager.add_pre_hook do |task_name|
15
+ # Makit::Logging.info("Starting task: #{task_name}")
16
+ # end
17
+ #
18
+ # Makit::Tasks::HookManager.add_post_hook do |task_name, duration, result, error|
19
+ # if error
20
+ # Makit::Logging.error("Task failed: #{task_name}")
21
+ # else
22
+ # Makit::Logging.success("Task completed: #{task_name}")
23
+ # end
24
+ # end
25
+ #
26
+ # @example Task-specific hooks
27
+ # Makit::Tasks::HookManager.add_pre_hook_for(:build) do |task_name|
28
+ # Makit::Logging.info("Building project...")
29
+ # end
30
+ #
31
+ # Makit::Tasks::HookManager.add_post_hook_for(:test) do |task_name, duration, result, error|
32
+ # Makit::Logging.info("Test execution took #{duration.round(2)}s")
33
+ # end
34
+ module Makit
35
+ module Tasks
36
+ class HookManager
37
+ @pre_hooks = []
38
+ @post_hooks = []
39
+ @task_specific_pre_hooks = {}
40
+ @task_specific_post_hooks = {}
41
+ @excluded_tasks = Set.new
42
+ @logged_tasks = Set.new
43
+
44
+ class << self
45
+ # @return [Array<Proc>] Global pre-task hooks
46
+ attr_reader :pre_hooks
47
+
48
+ # @return [Array<Proc>] Global post-task hooks
49
+ attr_reader :post_hooks
50
+
51
+ # @return [Hash<String, Array<Proc>>] Task-specific pre-task hooks
52
+ attr_reader :task_specific_pre_hooks
53
+
54
+ # @return [Hash<String, Array<Proc>>] Task-specific post-task hooks
55
+ attr_reader :task_specific_post_hooks
56
+
57
+ # @return [Set<String>] Tasks excluded from hook execution
58
+ attr_reader :excluded_tasks
59
+
60
+ # Add a global pre-task hook
61
+ #
62
+ # The hook will be executed before every task runs.
63
+ #
64
+ # @yield [task_name] the name of the task being executed
65
+ # @yieldparam task_name [String] the name of the task
66
+ # @return [void]
67
+ def add_pre_hook(&block)
68
+ @pre_hooks << block
69
+ end
70
+
71
+ # Add a global post-task hook
72
+ #
73
+ # The hook will be executed after every task completes (success or failure).
74
+ #
75
+ # @yield [task_name, duration, result, error] hook parameters
76
+ # @yieldparam task_name [String] the name of the task
77
+ # @yieldparam duration [Float] execution duration in seconds
78
+ # @yieldparam result [Object, nil] the result of the task execution
79
+ # @yieldparam error [Exception, nil] any error that occurred during execution
80
+ # @return [void]
81
+ def add_post_hook(&block)
82
+ @post_hooks << block
83
+ end
84
+
85
+ # Add a pre-task hook for a specific task
86
+ #
87
+ # The hook will only be executed before the specified task runs.
88
+ #
89
+ # @param task_name [String, Symbol] the name of the task
90
+ # @yield [task_name] the name of the task being executed
91
+ # @yieldparam task_name [String] the name of the task
92
+ # @return [void]
93
+ def add_pre_hook_for(task_name, &block)
94
+ @task_specific_pre_hooks[task_name.to_s] ||= []
95
+ @task_specific_pre_hooks[task_name.to_s] << block
96
+ end
97
+
98
+ # Add a post-task hook for a specific task
99
+ #
100
+ # The hook will only be executed after the specified task completes.
101
+ #
102
+ # @param task_name [String, Symbol] the name of the task
103
+ # @yield [task_name, duration, result, error] hook parameters
104
+ # @yieldparam task_name [String] the name of the task
105
+ # @yieldparam duration [Float] execution duration in seconds
106
+ # @yieldparam result [Object, nil] the result of the task execution
107
+ # @yieldparam error [Exception, nil] any error that occurred during execution
108
+ # @return [void]
109
+ def add_post_hook_for(task_name, &block)
110
+ @task_specific_post_hooks[task_name.to_s] ||= []
111
+ @task_specific_post_hooks[task_name.to_s] << block
112
+ end
113
+
114
+ # Execute all pre-task hooks for a given task
115
+ #
116
+ # @param task_name [String] the name of the task
117
+ # @return [void]
118
+ def execute_pre_hooks(task_name)
119
+ return if excluded?(task_name)
120
+
121
+ # Execute global pre-hooks
122
+ @pre_hooks.each { |hook| hook.call(task_name) }
123
+
124
+ # Execute task-specific pre-hooks
125
+ task_hooks = @task_specific_pre_hooks[task_name.to_s] || []
126
+ task_hooks.each { |hook| hook.call(task_name) }
127
+ end
128
+
129
+ # Execute all post-task hooks for a given task
130
+ #
131
+ # @param task_name [String] the name of the task
132
+ # @param duration [Float] execution duration in seconds
133
+ # @param result [Object, nil] the result of the task execution
134
+ # @param error [Exception, nil] any error that occurred during execution
135
+ # @return [void]
136
+ def execute_post_hooks(task_name, duration, result, error)
137
+ return if excluded?(task_name)
138
+
139
+ # Execute global post-hooks
140
+ @post_hooks.each { |hook| hook.call(task_name, duration, result, error) }
141
+
142
+ # Execute task-specific post-hooks
143
+ task_hooks = @task_specific_post_hooks[task_name.to_s] || []
144
+ task_hooks.each { |hook| hook.call(task_name, duration, result, error) }
145
+ end
146
+
147
+ # Clear all hooks
148
+ #
149
+ # @return [void]
150
+ def clear_all_hooks
151
+ @pre_hooks.clear
152
+ @post_hooks.clear
153
+ @task_specific_pre_hooks.clear
154
+ @task_specific_post_hooks.clear
155
+ end
156
+
157
+ # Exclude a task from hook execution
158
+ #
159
+ # @param task_name [String, Symbol] the name of the task to exclude
160
+ # @return [void]
161
+ def exclude_task(task_name)
162
+ @excluded_tasks.add(task_name.to_s)
163
+ end
164
+
165
+ # Include a task in hook execution (remove from exclusions)
166
+ #
167
+ # @param task_name [String, Symbol] the name of the task to include
168
+ # @return [void]
169
+ def include_task(task_name)
170
+ @excluded_tasks.delete(task_name.to_s)
171
+ end
172
+
173
+ # Check if a task is excluded from hook execution
174
+ #
175
+ # @param task_name [String, Symbol] the name of the task to check
176
+ # @return [Boolean] true if the task is excluded
177
+ def excluded?(task_name)
178
+ @excluded_tasks.include?(task_name.to_s)
179
+ end
180
+
181
+ # Get statistics about registered hooks
182
+ #
183
+ # @return [Hash] hook statistics
184
+ def stats
185
+ {
186
+ global_pre_hooks: @pre_hooks.size,
187
+ global_post_hooks: @post_hooks.size,
188
+ task_specific_pre_hooks: @task_specific_pre_hooks.values.flatten.size,
189
+ task_specific_post_hooks: @task_specific_post_hooks.values.flatten.size,
190
+ tasks_with_pre_hooks: @task_specific_pre_hooks.keys,
191
+ tasks_with_post_hooks: @task_specific_post_hooks.keys,
192
+ }
193
+ end
194
+
195
+ # Setup default task hooks
196
+ #
197
+ # This method sets up the default task hooks that provide basic
198
+ # task execution feedback. It should be called during initialization.
199
+ #
200
+ # @return [void]
201
+ def setup_default_hooks
202
+ # Only setup if no hooks are already registered
203
+ return unless @pre_hooks.empty? && @post_hooks.empty?
204
+
205
+ # Exclude the init task from hooks to prevent duplication
206
+ exclude_task(:init)
207
+ exclude_task(:default)
208
+
209
+ # Default pre-task hook: log task start to default logger
210
+ add_pre_hook do |task_name|
211
+ log_task_start(task_name)
212
+ end
213
+
214
+ # Default post-task hook: log task completion
215
+ add_post_hook do |task_name, duration, result, error|
216
+ log_task_completion(task_name, duration, result, error)
217
+ end
218
+ end
219
+
220
+ def log_task_start(task_name)
221
+ #return if @logged_tasks.include?(task_name)
222
+ #@logged_tasks.add(task_name)
223
+ #Makit::Logging.info("#{task_name}".colorize(:white).bold)
224
+ end
225
+
226
+ def log_task_completion(task_name, duration, result, error)
227
+ #Makit::Logging.info("#{task_name}".colorize(:white).bold)
228
+ #Makit::Logging.info("Task completed".colorize(:green).bold)
229
+ #Makit::Logging.info("Duration: #{duration.round(2)}s".colorize(:green).bold)
230
+ # Makit::Logging.info("Result: #{result}".colorize(:green).bold)
231
+ #Makit::Logging.info("Error: #{error}".colorize(:red).bold)
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ # Setup default hooks when the module is loaded
239
+ Makit::Tasks::HookManager.setup_default_hooks
@@ -0,0 +1,47 @@
1
+ Rake.application.top_level_tasks.unshift("init")
2
+
3
+ task :init do
4
+ puts "-" * 80
5
+ humanized_timestamp = Makit::Humanize.get_humanized_timestamp(Time.now)
6
+ # log the rake + arguments, as it would be invoke at the console.
7
+ # for instance: rake -T
8
+ # or: rake
9
+ # or: rake clean
10
+ # or: rake LOG_LEVEL=debug
11
+ command = "rake #{ARGV.join(" ")}"
12
+ message = "#{command} (#{humanized_timestamp})"
13
+
14
+ # Create filename-friendly version of rake command
15
+ rake_name = command.gsub(/[^a-zA-Z0-9\-_]/, "_").gsub(/_+/, "_").gsub(/^_|_$/, "")
16
+
17
+ # Get the default logger and add custom file logging sinks
18
+ log = Makit::Logging.default_logger
19
+
20
+ # Add structured JSON and simple text logging sinks to the default logger
21
+ additional_sinks = [
22
+ Makit::Logging::Sinks::UnifiedFileSink.new(
23
+ configurations: [
24
+ # Structured JSON logging
25
+ {
26
+ file: "artifacts/#{rake_name}.json",
27
+ format: :json,
28
+ append: true,
29
+ include_metadata: true,
30
+ },
31
+ # Simple text logging with rendered context
32
+ {
33
+ file: "artifacts/#{rake_name}.txt",
34
+ format: :plain,
35
+ append: true,
36
+ include_context: true,
37
+ },
38
+ ],
39
+ ),
40
+ ]
41
+
42
+ # Add the additional sinks to the default logger
43
+ log.sinks.concat(additional_sinks)
44
+
45
+ # Log with the enhanced default logger
46
+ log.info(message)
47
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "../git/repository"
2
+
3
+ if Makit::Git::Repository.git_repo?
4
+ desc "Integrate changes into the git repository."
5
+ task :integrate do
6
+ unstaged_files = Makit::Git::Repository.unstaged_files
7
+ untracked_files = Makit::Git::Repository.untracked_files
8
+ if unstaged_files.length.positive? || untracked_files.length.positive?
9
+ Makit::Git::CLI.integrate
10
+ else
11
+ Makit::Logging.default_logger.info("No unstaged or untracked files found")
12
+ #puts " No unstaged or untracked files found".colorize(:grey)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../git/repository"
2
+
3
+ if Makit::Git::Repository.git_repo?
4
+ desc "pull changes from the remote branch, preferring incoming changes for conflicts"
5
+ task :pull_incoming do
6
+ Makit::TaskInfo.track(:pull_incoming) do
7
+ # Makit::SHOW.task(:pull_incoming)
8
+ puts " git branch is ".colorize(:grey) + Makit::Git::Repository.branch.to_s.colorize(:green)
9
+ "git pull origin #{Makit::Git::Repository.branch} -X theirs".try
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "../setup/runner"
2
+
3
+ desc "Setup project files.."
4
+ task :setup do
5
+ Makit::Setup::Runner.run
6
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "../git/repository"
2
+
3
+ if Makit::Git::Repository.git_repo?
4
+ desc "Sync changes with the git repository."
5
+ task sync: %i[integrate pull_incoming] do
6
+ Makit::TaskInfo.track(:sync) do
7
+ # Makit::SHOW.task(:sync)
8
+ Makit::Git::CLI.sync
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Monkey patch for Rake::Task to add hook support
4
+ #
5
+ # This module patches Rake::Task to automatically execute pre and post hooks
6
+ # for all task invocations. It preserves the original behavior while adding
7
+ # the hook functionality.
8
+ #
9
+ # @note This file should be required after the HookManager class is defined
10
+ require_relative "hook_manager"
11
+
12
+ # Monkey patch Rake::Task to add hook support
13
+ class Rake::Task
14
+ # Store original methods before patching
15
+ alias_method :original_invoke, :invoke
16
+ alias_method :original_execute, :execute
17
+
18
+ # Enhanced invoke method with hook support
19
+ #
20
+ # This method wraps the original invoke method to execute pre and post hooks
21
+ # around task execution. It handles errors gracefully and ensures hooks are
22
+ # always executed even if the task fails.
23
+ #
24
+ # @param args [Array] arguments passed to the task
25
+ # @return [Object] the result of the task execution
26
+ def invoke(*args)
27
+ start_time = Time.now
28
+ result = nil
29
+ error = nil
30
+
31
+ begin
32
+ # Execute pre-task hooks
33
+ Makit::Tasks::HookManager.execute_pre_hooks(name)
34
+
35
+ # Execute the original task
36
+ result = original_invoke(*args)
37
+ rescue => e
38
+ error = e
39
+ raise
40
+ ensure
41
+ # Execute post-task hooks (always runs, even on error)
42
+ duration = Time.now - start_time
43
+ Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
44
+ end
45
+
46
+ result
47
+ end
48
+
49
+ # Enhanced execute method with hook support
50
+ #
51
+ # This method wraps the original execute method to execute pre and post hooks
52
+ # around task execution. It handles errors gracefully and ensures hooks are
53
+ # always executed even if the task fails.
54
+ #
55
+ # @param args [Array] arguments passed to the task
56
+ # @return [Object] the result of the task execution
57
+ def execute(*args)
58
+ start_time = Time.now
59
+ result = nil
60
+ error = nil
61
+
62
+ begin
63
+ # Execute pre-task hooks
64
+ Makit::Tasks::HookManager.execute_pre_hooks(name)
65
+
66
+ # Execute the original task
67
+ result = original_execute(*args)
68
+ rescue => e
69
+ error = e
70
+ raise
71
+ ensure
72
+ # Execute post-task hooks (always runs, even on error)
73
+ duration = Time.now - start_time
74
+ Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
75
+ end
76
+
77
+ result
78
+ end
79
+ end