makit 0.0.153 → 0.0.154
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.
- checksums.yaml +4 -4
- data/lib/makit/tasks/info.rb +209 -45
- data/lib/makit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ad406746e87035bfd4254571783e18949321ad6e6c4e3fe773fbaf82cb306320
|
|
4
|
+
data.tar.gz: 1bde5d1063f2de07e559ee3faa5a0cd63aad46a94e4b5676b0f08eca68337b49
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78967fd3ee402daffaec89af96194fee21d7fbc1c8c327309c6463b300c1880c9ee3a993ca72c07f1652183d436f425277cbb2259018d418d365bd2edee34413
|
|
7
|
+
data.tar.gz: '0281c16cdd5f55e125d757c4d5594f3fedc660f49c211b96302da458cf8eae4286d128208eff3a742dd1586e6555e9619bd5b599c55f361f3427ab61adcc6232'
|
data/lib/makit/tasks/info.rb
CHANGED
|
@@ -1,51 +1,199 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "pathname"
|
|
4
|
+
require "open3"
|
|
4
5
|
|
|
5
6
|
desc "Display information about the current project"
|
|
6
7
|
task :info do
|
|
8
|
+
# Start timing for debug logging
|
|
9
|
+
start_time = Time.now
|
|
10
|
+
is_debug = Makit::Logging.current_log_level == :debug
|
|
11
|
+
|
|
12
|
+
if is_debug
|
|
13
|
+
Makit::Logging.debug("rake info task started")
|
|
14
|
+
end
|
|
15
|
+
|
|
7
16
|
# Get verbosity level
|
|
8
17
|
verbosity = Makit::Logging.current_verbosity
|
|
9
18
|
|
|
10
|
-
# Get GIT_REMOTE_URL - try multiple sources
|
|
11
|
-
|
|
19
|
+
# Get GIT_REMOTE_URL - try multiple sources (optimized: check constant first, avoid slow operations)
|
|
20
|
+
git_remote_url_start = Time.now if is_debug
|
|
21
|
+
git_remote_url = if defined?(GIT_REMOTE_URL) && !GIT_REMOTE_URL.nil? && !GIT_REMOTE_URL.empty?
|
|
12
22
|
GIT_REMOTE_URL
|
|
13
|
-
elsif
|
|
14
|
-
Makit::Git.
|
|
23
|
+
elsif Dir.exist?(".git") || File.exist?(".git")
|
|
24
|
+
# Fast check: directly check for .git directory/file instead of calling Makit::Git.git_repo?
|
|
25
|
+
# which executes multiple git commands. Then directly get remote URL.
|
|
26
|
+
begin
|
|
27
|
+
# Direct git command execution - much faster than going through repository state
|
|
28
|
+
remote_url_output, _stderr, status = Open3.capture3('git', 'remote', 'get-url', 'origin')
|
|
29
|
+
if status.success? && remote_url_output && !remote_url_output.strip.empty?
|
|
30
|
+
remote_url_output.strip
|
|
31
|
+
else
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
rescue
|
|
35
|
+
nil
|
|
36
|
+
end
|
|
37
|
+
elsif File.exist?(".makit.json")
|
|
38
|
+
# Only load project config if .makit.json exists (avoid creating it unnecessarily)
|
|
39
|
+
begin
|
|
40
|
+
project = Makit::Configuration::Project.default
|
|
41
|
+
project.git_remote_url unless project.git_remote_url.nil? || project.git_remote_url.empty?
|
|
42
|
+
rescue
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
15
45
|
else
|
|
16
|
-
|
|
17
|
-
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
if is_debug
|
|
49
|
+
elapsed = Time.now - git_remote_url_start
|
|
50
|
+
Makit::Logging.debug("GIT_REMOTE_URL lookup took #{sprintf('%.3f', elapsed)} seconds")
|
|
18
51
|
end
|
|
19
52
|
|
|
20
|
-
# Get VERSION -
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
53
|
+
# Get VERSION and VERSION_FILE - using same logic as rake version
|
|
54
|
+
# This ensures consistency between rake info and rake version
|
|
55
|
+
# Optimized: Use Makit::Directories::PROJECT_ROOT directly, check specific files before glob
|
|
56
|
+
version_start = Time.now if is_debug
|
|
57
|
+
version_file = nil
|
|
58
|
+
version = nil
|
|
59
|
+
|
|
60
|
+
begin
|
|
61
|
+
# Use Makit::Directories::PROJECT_ROOT directly (already loaded, fast)
|
|
62
|
+
project_root = Makit::Directories::PROJECT_ROOT
|
|
26
63
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
64
|
+
if project_root && Dir.exist?(project_root)
|
|
65
|
+
# Check for manually defined VERSION_FILE constant first
|
|
66
|
+
if defined?(VERSION_FILE) && !VERSION_FILE.nil?
|
|
67
|
+
version_file = File.expand_path(VERSION_FILE, project_root)
|
|
68
|
+
version_file = nil unless File.exist?(version_file)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# If no VERSION_FILE constant, search for common version files
|
|
72
|
+
# Optimized: Check specific files first (fast File.exist?) before using glob (slower)
|
|
73
|
+
unless version_file
|
|
74
|
+
# Check specific files first (much faster than glob patterns)
|
|
75
|
+
specific_files = [
|
|
76
|
+
"Directory.Build.props",
|
|
77
|
+
"Cargo.toml",
|
|
78
|
+
"package.json",
|
|
79
|
+
"pyproject.toml",
|
|
80
|
+
"pom.xml"
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
specific_files.each do |filename|
|
|
84
|
+
file_path = File.join(project_root, filename)
|
|
85
|
+
if File.exist?(file_path)
|
|
86
|
+
version_file = file_path
|
|
87
|
+
break
|
|
36
88
|
end
|
|
37
89
|
end
|
|
38
|
-
|
|
39
|
-
#
|
|
90
|
+
|
|
91
|
+
# Only use glob for gemspec if no specific file found (glob can be slow on large dirs)
|
|
92
|
+
unless version_file
|
|
93
|
+
gemspec_matches = Dir.glob(File.join(project_root, "*.gemspec"))
|
|
94
|
+
version_file = gemspec_matches.first unless gemspec_matches.empty?
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Extract version from the file if found (same logic as Makit::Version.extract_version_from_ssot_file)
|
|
99
|
+
if version_file && File.exist?(version_file)
|
|
100
|
+
case File.basename(version_file)
|
|
101
|
+
when /\.gemspec$/
|
|
102
|
+
content = File.read(version_file)
|
|
103
|
+
match = content.match(/spec\.version\s*=\s*["']([^"']+)["']/)
|
|
104
|
+
version = match[1] if match
|
|
105
|
+
when "Directory.Build.props"
|
|
106
|
+
content = File.read(version_file)
|
|
107
|
+
match = content.match(%r{<Version>([^<]+)</Version>})
|
|
108
|
+
version = match[1] if match
|
|
109
|
+
when "Cargo.toml"
|
|
110
|
+
content = File.read(version_file)
|
|
111
|
+
match = content.match(/version\s*=\s*["']([^"']+)["']/)
|
|
112
|
+
version = match[1] if match
|
|
113
|
+
when "package.json"
|
|
114
|
+
require "json"
|
|
115
|
+
json = JSON.parse(File.read(version_file))
|
|
116
|
+
version = json["version"]
|
|
117
|
+
when "pyproject.toml"
|
|
118
|
+
content = File.read(version_file)
|
|
119
|
+
match = content.match(/\[project\]\s*version\s*=\s*["']([^"']+)["']/)
|
|
120
|
+
version = match[1] if match
|
|
121
|
+
unless version
|
|
122
|
+
match = content.match(/\[tool\.poetry\]\s*version\s*=\s*["']([^"']+)["']/)
|
|
123
|
+
version = match[1] if match
|
|
124
|
+
end
|
|
125
|
+
when "pom.xml"
|
|
126
|
+
content = File.read(version_file)
|
|
127
|
+
match = content.match(%r{<version>([^<]+)</version>})
|
|
128
|
+
version = match[1] if match
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Convert to relative path for display (same as Makit::Version.info)
|
|
132
|
+
if version_file && project_root
|
|
133
|
+
# Normalize paths to use forward slashes for consistency (Windows-safe)
|
|
134
|
+
normalized_version_file = version_file.gsub(/\\/, "/")
|
|
135
|
+
normalized_project_root = project_root.gsub(/\\/, "/")
|
|
136
|
+
version_file = normalized_version_file.sub(normalized_project_root + "/", "")
|
|
137
|
+
end
|
|
40
138
|
end
|
|
41
139
|
end
|
|
42
|
-
|
|
43
|
-
|
|
140
|
+
rescue => e
|
|
141
|
+
# Silently handle errors - fall back to VERSION constant
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Fallback to Rakefile VERSION constant or Makit::Version.version if no version file found
|
|
145
|
+
unless version
|
|
146
|
+
version = defined?(VERSION) ? VERSION : Makit::Version.version
|
|
147
|
+
end
|
|
148
|
+
if is_debug
|
|
149
|
+
elapsed = Time.now - version_start
|
|
150
|
+
Makit::Logging.debug("VERSION and VERSION_FILE lookup took #{sprintf('%.3f', elapsed)} seconds")
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Get BRANCH - from git if available (optimized, Windows-safe)
|
|
154
|
+
# Reuse git repo check from GIT_REMOTE_URL lookup to avoid duplicate check
|
|
155
|
+
branch_start = Time.now if is_debug
|
|
156
|
+
branch = if git_remote_url || Dir.exist?(".git") || File.exist?(".git")
|
|
157
|
+
# Fast check: directly execute git branch command instead of calling Makit::Git.branch
|
|
158
|
+
# which executes the expensive get_repository_state with multiple git commands
|
|
159
|
+
begin
|
|
160
|
+
branch_output, _stderr, status = Open3.capture3('git', 'branch', '--show-current')
|
|
161
|
+
current_branch = if status.success? && branch_output && !branch_output.strip.empty?
|
|
162
|
+
branch_output.strip
|
|
163
|
+
else
|
|
164
|
+
'(unknown)'
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Check if current branch is the default branch (Windows-safe error handling)
|
|
168
|
+
if current_branch != '(unknown)'
|
|
169
|
+
begin
|
|
170
|
+
# Get default branch from remote (Windows-safe: use Open3 for proper error handling)
|
|
171
|
+
default_branch_output, _stderr, status = Open3.capture3('git', 'symbolic-ref', 'refs/remotes/origin/HEAD')
|
|
172
|
+
if status.success? && default_branch_output && !default_branch_output.strip.empty?
|
|
173
|
+
default_branch = default_branch_output.strip.sub('refs/remotes/origin/', '')
|
|
174
|
+
if current_branch == default_branch
|
|
175
|
+
current_branch = "#{current_branch} (default)"
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
rescue
|
|
179
|
+
# Silently fail if we can't determine default branch
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
current_branch
|
|
184
|
+
rescue
|
|
185
|
+
'(unknown)'
|
|
186
|
+
end
|
|
44
187
|
else
|
|
45
188
|
'(not a git repo)'
|
|
46
189
|
end
|
|
190
|
+
if is_debug
|
|
191
|
+
elapsed = Time.now - branch_start
|
|
192
|
+
Makit::Logging.debug("BRANCH lookup took #{sprintf('%.3f', elapsed)} seconds")
|
|
193
|
+
end
|
|
47
194
|
|
|
48
195
|
# Display information with colors
|
|
196
|
+
display_start = Time.now if is_debug
|
|
49
197
|
name_color = :grey
|
|
50
198
|
value_color = :green
|
|
51
199
|
label_width = 20 # Fixed width for label column
|
|
@@ -61,6 +209,12 @@ task :info do
|
|
|
61
209
|
value2 = version.to_s.colorize(value_color)
|
|
62
210
|
puts " #{label2} #{value2}"
|
|
63
211
|
|
|
212
|
+
if version_file
|
|
213
|
+
label_version_file = 'VERSION_FILE'.rjust(label_width).colorize(name_color)
|
|
214
|
+
value_version_file = version_file.colorize(value_color)
|
|
215
|
+
puts " #{label_version_file} #{value_version_file}"
|
|
216
|
+
end
|
|
217
|
+
|
|
64
218
|
label3 = 'BRANCH'.rjust(label_width).colorize(name_color)
|
|
65
219
|
value3 = branch.colorize(value_color)
|
|
66
220
|
puts " #{label3} #{value3}"
|
|
@@ -107,30 +261,29 @@ task :info do
|
|
|
107
261
|
# Silently handle errors loading project info
|
|
108
262
|
end
|
|
109
263
|
|
|
110
|
-
# Git section
|
|
111
|
-
if
|
|
264
|
+
# Git section (optimized: reuse branch from main section, avoid expensive git operations)
|
|
265
|
+
if branch && branch != '(not a git repo)'
|
|
112
266
|
begin
|
|
113
|
-
|
|
267
|
+
# Reuse branch from main section (already optimized)
|
|
268
|
+
verbose_branch = branch
|
|
114
269
|
|
|
115
|
-
#
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if verbose_branch == default_branch
|
|
123
|
-
verbose_branch = "#{verbose_branch} (default)"
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
rescue
|
|
127
|
-
# Silently fail if we can't determine default branch
|
|
128
|
-
end
|
|
270
|
+
# Get git status and commit info (optimized: direct git commands instead of get_repository_state)
|
|
271
|
+
begin
|
|
272
|
+
# Check if clean using direct git command (faster than Makit::Git.clean?)
|
|
273
|
+
status_output, _stderr, status = Open3.capture3('git', 'status', '--porcelain')
|
|
274
|
+
status = status.success? && status_output.strip.empty? ? 'clean' : 'dirty'
|
|
275
|
+
rescue
|
|
276
|
+
status = 'unknown'
|
|
129
277
|
end
|
|
130
278
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
279
|
+
begin
|
|
280
|
+
# Get commit SHA using direct git command (faster than Makit::Git.commitsha)
|
|
281
|
+
commit_output, _stderr, commit_status = Open3.capture3('git', 'rev-parse', 'HEAD')
|
|
282
|
+
commit = commit_status.success? && commit_output ? commit_output.strip : nil
|
|
283
|
+
commit_display = commit ? commit[0, 7] : '(unknown)'
|
|
284
|
+
rescue
|
|
285
|
+
commit_display = '(unknown)'
|
|
286
|
+
end
|
|
134
287
|
|
|
135
288
|
puts ""
|
|
136
289
|
puts "Git:".colorize(:cyan)
|
|
@@ -194,6 +347,17 @@ task :info do
|
|
|
194
347
|
# Silently handle errors loading paths info
|
|
195
348
|
end
|
|
196
349
|
end
|
|
350
|
+
|
|
351
|
+
if is_debug
|
|
352
|
+
display_elapsed = Time.now - display_start
|
|
353
|
+
Makit::Logging.debug("Display operations took #{sprintf('%.3f', display_elapsed)} seconds")
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
# Log total execution time in debug mode
|
|
357
|
+
if is_debug
|
|
358
|
+
elapsed_time = Time.now - start_time
|
|
359
|
+
Makit::Logging.debug("rake info task completed in #{sprintf('%.3f', elapsed_time)} seconds")
|
|
360
|
+
end
|
|
197
361
|
end
|
|
198
362
|
|
|
199
363
|
# Helper method to display a field with consistent formatting
|
data/lib/makit/version.rb
CHANGED