makit 0.0.162 → 0.0.163

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f77dc0621ad5f53cc7670638ebd8857ec30daf466babfc8a896b4ef1bdfd5aad
4
- data.tar.gz: 28e892048f2393c70d4431891f5352310489c22e4fd594b555f9939f40d52355
3
+ metadata.gz: 599b26976cbb6cc29f17237f53aa31d334594eb637425b0d534c0eaf53cc215c
4
+ data.tar.gz: 953a603a359bd3e2535cad44b76eaac2d590761b831b3c3367ff8a67c21f8da0
5
5
  SHA512:
6
- metadata.gz: 315622470f6f2f86fbb81c8bfecdffdd9ac4efc2fcca625451e4d2b996ba7aa62e64b8e1320873e4efd70767af1a836be5c53b4ede198bc61c88be8bb5a88654
7
- data.tar.gz: 0036fd66c4ae5789f7bf3de8eca2305e49f4c6431ce4d508eb51504ec490d0e02ec2d51941d0b071fb815d59ac1c0d5f33aeba6cbdfb1b07109af439ac771add
6
+ metadata.gz: 95d25294ff19b0a8dfaa611f0a45e471423555b95f1ced18b04b6945b2ece3e5279a9d77df3e0b370d239d4ebf30e87cc0f91598c0e0a33ae1ca16b6b4ecd9f1
7
+ data.tar.gz: 2fd32bc4994feb7492182ad20becea5f3a4bcb0d946e6bf939925a3921986c455abb0bc1b3378d75e6318b311c534e629af30824c17764e67fbcd5b89e447932
@@ -30,6 +30,161 @@ module Makit
30
30
  end
31
31
  end
32
32
 
33
+ # Installs a .NET global tool if it's not already installed
34
+ #
35
+ # @param tool_name [String] The name of the tool to install (e.g., "docfx", "dotnet-outdated-tool")
36
+ # @return [Boolean] true if the tool was installed or already exists, false if installation failed
37
+ def self.install_global_tool(tool_name)
38
+ raise ArgumentError, "tool_name is required" if tool_name.nil? || tool_name.strip.empty?
39
+
40
+ tool_name = tool_name.strip
41
+
42
+ # Check if tool is already installed
43
+ # Parse the output to find exact tool name matches
44
+ list_output = `dotnet tool list --global 2>&1`
45
+ if $CHILD_STATUS.success?
46
+ # The output format is typically:
47
+ # Package Id Version Commands
48
+ # ----------------------------------------
49
+ # docfx 2.x.x docfx
50
+ # Parse lines to find exact tool name matches
51
+ installed = list_output.lines.any? do |line|
52
+ # Match tool name at the start of a line (after optional whitespace)
53
+ # or as a word boundary to avoid substring matches
54
+ line.strip.split(/\s+/).first == tool_name
55
+ end
56
+
57
+ if installed
58
+ Makit::Logging.default_logger.info("Global tool '#{tool_name}' is already installed")
59
+ return true
60
+ end
61
+ end
62
+
63
+ # Install the tool
64
+ Makit::Logging.default_logger.info("Installing global tool '#{tool_name}'...")
65
+ "dotnet tool install --global #{tool_name}".run
66
+ $CHILD_STATUS.success?
67
+ end
68
+
69
+ # Gets the currently installed version of a global tool
70
+ #
71
+ # @param tool_name [String] The name of the tool
72
+ # @return [String, nil] The installed version, or nil if not installed
73
+ def self.get_installed_tool_version(tool_name)
74
+ list_output = `dotnet tool list --global 2>&1`
75
+ return nil unless $CHILD_STATUS.success?
76
+
77
+ # Skip header lines
78
+ list_output.lines.each do |line|
79
+ line_stripped = line.strip
80
+ next if line_stripped.empty?
81
+ next if line_stripped.start_with?("Package") || line_stripped.start_with?("-")
82
+
83
+ # Split by whitespace - columns are: Package Id, Version, Commands
84
+ parts = line_stripped.split(/\s+/)
85
+ next if parts.empty?
86
+
87
+ # Match tool name at the start of the line
88
+ if parts.first == tool_name && parts.length >= 2
89
+ # Version is the second column
90
+ return parts[1]
91
+ end
92
+ end
93
+
94
+ nil
95
+ end
96
+ private_class_method :get_installed_tool_version
97
+
98
+ # Gets the latest available version of a tool from NuGet
99
+ #
100
+ # @param tool_name [String] The name of the tool
101
+ # @return [String, nil] The latest version, or nil if not found
102
+ def self.get_latest_tool_version(tool_name)
103
+ search_output = `dotnet tool search #{tool_name} --take 1 2>&1`
104
+ return nil unless $CHILD_STATUS.success?
105
+
106
+ # Parse output format:
107
+ # Package ID Latest Version Authors Downloads Verified
108
+ # -------------------------------------------------------------------------------------------------
109
+ # docfx 2.78.4 .NET Foundation and Contributors 4091347 x
110
+ search_output.lines.each do |line|
111
+ line_stripped = line.strip
112
+ next if line_stripped.empty?
113
+ next if line_stripped.start_with?("Package") || line_stripped.start_with?("-")
114
+
115
+ # Split by whitespace - columns are: Package ID, Latest Version, Authors, Downloads, Verified
116
+ parts = line_stripped.split(/\s+/)
117
+ next if parts.empty?
118
+
119
+ # Match tool name at the start of the line
120
+ if parts.first == tool_name && parts.length >= 2
121
+ # Latest Version is the second column
122
+ return parts[1]
123
+ end
124
+ end
125
+
126
+ nil
127
+ end
128
+ private_class_method :get_latest_tool_version
129
+
130
+ # Updates a .NET global tool to the latest version if a newer version is available
131
+ #
132
+ # If a newer version is available, the tool will be uninstalled and then reinstalled
133
+ # to ensure the latest version is installed.
134
+ #
135
+ # @param tool_name [String] The name of the tool to update (e.g., "docfx", "dotnet-outdated-tool")
136
+ # @return [Boolean] true if the tool was updated or already at latest version, false if update failed
137
+ def self.update_global_tool(tool_name)
138
+ raise ArgumentError, "tool_name is required" if tool_name.nil? || tool_name.strip.empty?
139
+
140
+ tool_name = tool_name.strip
141
+
142
+ # Get currently installed version
143
+ installed_version = get_installed_tool_version(tool_name)
144
+
145
+ if installed_version.nil?
146
+ Makit::Logging.default_logger.info("Global tool '#{tool_name}' is not installed, installing...")
147
+ return install_global_tool(tool_name)
148
+ end
149
+
150
+ # Get latest available version
151
+ latest_version = get_latest_tool_version(tool_name)
152
+
153
+ if latest_version.nil?
154
+ Makit::Logging.default_logger.warn("Could not determine latest version for '#{tool_name}', skipping update")
155
+ return false
156
+ end
157
+
158
+ # Compare versions
159
+ begin
160
+ versions_to_compare = [installed_version, latest_version]
161
+ highest_version = Makit::Version.get_highest_version(versions_to_compare)
162
+
163
+ if highest_version == installed_version
164
+ Makit::Logging.default_logger.info("Global tool '#{tool_name}' is already at latest version (#{installed_version})")
165
+ return true
166
+ end
167
+ rescue => e
168
+ Makit::Logging.default_logger.warn("Could not compare versions for '#{tool_name}': #{e.message}, attempting update anyway")
169
+ end
170
+
171
+ # Newer version available - uninstall and reinstall
172
+ Makit::Logging.default_logger.info("Updating global tool '#{tool_name}' from #{installed_version} to #{latest_version}...")
173
+
174
+ # Uninstall the tool
175
+ Makit::Logging.default_logger.info("Uninstalling global tool '#{tool_name}'...")
176
+ "dotnet tool uninstall --global #{tool_name}".run
177
+ unless $CHILD_STATUS.success?
178
+ Makit::Logging.default_logger.error("Failed to uninstall global tool '#{tool_name}'")
179
+ return false
180
+ end
181
+
182
+ # Install the latest version
183
+ Makit::Logging.default_logger.info("Installing global tool '#{tool_name}' version #{latest_version}...")
184
+ "dotnet tool install --global #{tool_name}".run
185
+ $CHILD_STATUS.success?
186
+ end
187
+
33
188
  #
34
189
  # generate docs/DotNet.md
35
190
  #
data/lib/makit/dotnet.rb CHANGED
@@ -98,5 +98,13 @@ module Makit
98
98
  def self.generate_docs
99
99
  CLI.generate_docs
100
100
  end
101
+
102
+ def self.install_global_tool(tool_name)
103
+ CLI.install_global_tool(tool_name)
104
+ end
105
+
106
+ def self.update_global_tool(tool_name)
107
+ CLI.update_global_tool(tool_name)
108
+ end
101
109
  end
102
110
  end
data/lib/makit/nuget.rb CHANGED
@@ -239,5 +239,191 @@ module Makit
239
239
  # Add the source
240
240
  add_source(name, url, username: username, password: password, store_password_in_clear_text: store_password_in_clear_text)
241
241
  end
242
+
243
+ # Migrates packages from one NuGet source to another, matching a pattern
244
+ #
245
+ # For local directory feeds, packages are found by scanning the directory structure:
246
+ # {source_path}/{package_name}/{version}/{package_name}.{version}.nupkg
247
+ #
248
+ # @param source_name [String] The name of the source to migrate from
249
+ # @param package_pattern [String] The package name pattern to match (e.g., "rep*", "MyPackage.*")
250
+ # @param destination_name [String] The name of the destination source
251
+ # @return [Integer] The number of packages migrated, or -1 if an error occurred
252
+ def self.migrate_packages(source_name, package_pattern, destination_name)
253
+ raise ArgumentError, "source_name is required" if source_name.nil? || source_name.strip.empty?
254
+ raise ArgumentError, "package_pattern is required" if package_pattern.nil? || package_pattern.strip.empty?
255
+ raise ArgumentError, "destination_name is required" if destination_name.nil? || destination_name.strip.empty?
256
+
257
+ source_name = source_name.strip
258
+ package_pattern = package_pattern.strip
259
+ destination_name = destination_name.strip
260
+
261
+ # Get source information
262
+ sources = list_sources
263
+ source_info = sources.find { |s| s[:name] == source_name }
264
+ destination_info = sources.find { |s| s[:name] == destination_name }
265
+
266
+ unless source_info
267
+ Makit::Logging.default_logger.error("Source '#{source_name}' not found")
268
+ return -1
269
+ end
270
+
271
+ unless destination_info
272
+ Makit::Logging.default_logger.error("Destination source '#{destination_name}' not found")
273
+ return -1
274
+ end
275
+
276
+ source_path = source_info[:url]
277
+ destination_path = destination_info[:url]
278
+
279
+ # Check if sources are local directory feeds (not URLs)
280
+ unless source_path && !source_path.match?(/^https?:\/\//)
281
+ Makit::Logging.default_logger.error("Source '#{source_name}' is not a local directory feed (URL: #{source_path})")
282
+ return -1
283
+ end
284
+
285
+ unless destination_path && !destination_path.match?(/^https?:\/\//)
286
+ Makit::Logging.default_logger.error("Destination source '#{destination_name}' is not a local directory feed (URL: #{destination_path})")
287
+ return -1
288
+ end
289
+
290
+ # Expand and normalize the source path
291
+ source_path = File.expand_path(source_path)
292
+ destination_path = File.expand_path(destination_path)
293
+
294
+ # Ensure source directory exists
295
+ unless Dir.exist?(source_path)
296
+ Makit::Logging.default_logger.error("Source directory does not exist: #{source_path}")
297
+ return -1
298
+ end
299
+
300
+ Makit::Logging.default_logger.info("Searching for packages matching '#{package_pattern}' in source '#{source_name}' (#{source_path})")
301
+
302
+ # Ensure destination directory exists
303
+ FileUtils.mkdir_p(destination_path) unless Dir.exist?(destination_path)
304
+
305
+ # Find all .nupkg files matching the pattern
306
+ # Simply search recursively for all .nupkg files and match package names
307
+ matching_packages = []
308
+
309
+ # Glob for all .nupkg files recursively in the source directory
310
+ Dir.glob(File.join(source_path, "**", "*.nupkg")) do |nupkg_file|
311
+ # Extract package name from the file path
312
+ # Path structure is typically: {source_path}/{package_name}/{version}/{package_name}.{version}.nupkg
313
+ relative_path = nupkg_file.sub(/^#{Regexp.escape(source_path)}[\/\\]?/, "")
314
+ path_parts = relative_path.split(/[\/\\]/)
315
+
316
+ # Get package name from directory structure (first directory after source_path)
317
+ package_name = path_parts.length >= 1 ? path_parts[0] : nil
318
+
319
+ # If we can't get it from path, try to extract from filename
320
+ if package_name.nil? || package_name.empty?
321
+ filename = File.basename(nupkg_file, ".nupkg")
322
+ # Try to extract package name by removing version suffix (e.g., "1.2.3" or "1.2.3-beta")
323
+ if filename.match?(/^(.+?)\.(\d+\.\d+.*)$/)
324
+ package_name = $1
325
+ else
326
+ package_name = filename
327
+ end
328
+ end
329
+
330
+ # Check if package name matches pattern
331
+ if package_name && File.fnmatch?(package_pattern, package_name, File::FNM_DOTMATCH)
332
+ # Extract version from path (second directory) or from filename
333
+ version = path_parts.length >= 2 ? path_parts[1] : nil
334
+
335
+ # If we couldn't extract version from path, try from filename
336
+ if version.nil? || version.empty?
337
+ filename = File.basename(nupkg_file, ".nupkg")
338
+ if filename.match?(/^.+?\.(\d+\.\d+.*)$/)
339
+ version = $1
340
+ else
341
+ version = "unknown"
342
+ end
343
+ end
344
+
345
+ matching_packages << {
346
+ package_name: package_name,
347
+ version: version,
348
+ nupkg_path: nupkg_file
349
+ }
350
+ end
351
+ end
352
+
353
+ if matching_packages.empty?
354
+ Makit::Logging.default_logger.info("No packages found matching pattern '#{package_pattern}' in source '#{source_name}'")
355
+ return 0
356
+ end
357
+
358
+ Makit::Logging.default_logger.info("Found #{matching_packages.length} package(s) matching pattern '#{package_pattern}' in source '#{source_name}'")
359
+
360
+ # Migrate each package
361
+ migrated_count = 0
362
+ failed_count = 0
363
+
364
+ matching_packages.each do |package_info|
365
+ package_name = package_info[:package_name]
366
+ version = package_info[:version]
367
+ nupkg_path = package_info[:nupkg_path]
368
+
369
+ Makit::Logging.default_logger.info("Migrating #{package_name}.#{version} from '#{source_name}' to '#{destination_name}'...")
370
+
371
+ # Determine target path in organized structure: {package_name}/{version}/{package_name}.{version}.nupkg
372
+ # Use lowercase for directory structure to match NuGet conventions
373
+ target_package_dir = File.join(destination_path, package_name.downcase, version)
374
+ target_package_path = File.join(target_package_dir, File.basename(nupkg_path).downcase)
375
+
376
+ if File.exist?(target_package_path)
377
+ Makit::Logging.default_logger.info(" Package already exists in destination, skipping: #{package_name}.#{version}")
378
+ migrated_count += 1
379
+ next
380
+ end
381
+
382
+ # For local directory feeds, use 'nuget add' which automatically organizes packages
383
+ # into the hierarchical structure: {packageID}/{version}/packageID.version.nupkg
384
+ # This is the recommended command for local feeds as it handles organization and metadata
385
+ stdout, stderr, status = Open3.capture3("nuget", "add", nupkg_path, "-Source", destination_path)
386
+
387
+ if status.success?
388
+ Makit::Logging.default_logger.info(" Successfully migrated and organized #{package_name}.#{version}")
389
+ migrated_count += 1
390
+ else
391
+ # Fallback to dotnet nuget push if nuget.exe is not available
392
+ # Check if nuget.exe exists, otherwise try dotnet nuget push
393
+ nuget_exe = Makit::Environment.which("nuget")
394
+ if nuget_exe.nil? || nuget_exe.empty?
395
+ Makit::Logging.default_logger.info(" nuget.exe not found, falling back to dotnet nuget push")
396
+
397
+ # Manually organize package into proper directory structure
398
+ Makit::Logging.default_logger.info(" Organizing package into directory structure: #{target_package_dir}")
399
+ FileUtils.mkdir_p(target_package_dir)
400
+ FileUtils.cp(nupkg_path, target_package_path)
401
+
402
+ # Push using dotnet nuget push from the organized location
403
+ stdout, stderr, status = Open3.capture3("dotnet", "nuget", "push", target_package_path, "--source", destination_path)
404
+
405
+ if status.success?
406
+ Makit::Logging.default_logger.info(" Successfully migrated and organized #{package_name}.#{version}")
407
+ migrated_count += 1
408
+ else
409
+ Makit::Logging.default_logger.warn(" Package copied to organized structure but dotnet nuget push failed: #{stderr}")
410
+ Makit::Logging.default_logger.warn(" Package is available at #{target_package_path} but may need manual indexing")
411
+ migrated_count += 1
412
+ end
413
+ else
414
+ Makit::Logging.default_logger.error(" Failed to migrate #{package_name}.#{version}: #{stderr}")
415
+ failed_count += 1
416
+ end
417
+ end
418
+ end
419
+
420
+ if failed_count > 0
421
+ Makit::Logging.default_logger.warn("Migration completed with #{failed_count} failure(s). #{migrated_count} package(s) migrated successfully.")
422
+ else
423
+ Makit::Logging.default_logger.info("Successfully migrated #{migrated_count} package(s) from '#{source_name}' to '#{destination_name}'")
424
+ end
425
+
426
+ migrated_count
427
+ end
242
428
  end
243
429
  end
data/lib/makit/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Makit
4
4
  # Static version for now to avoid circular dependency issues
5
- #VERSION = "0.0.162"
5
+ #VERSION = "0.0.163"
6
6
 
7
7
  # Version management utilities for various file formats
8
8
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: makit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.162
4
+ version: 0.0.163
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Parslow