makit 0.0.65 → 0.0.67

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generated/makit/v1/makit.v1_pb.rb +35 -0
  3. data/lib/generated/makit/v1/web/link_pb.rb +20 -0
  4. data/lib/makit/apache.rb +32 -32
  5. data/lib/makit/cli/clean.rb +14 -14
  6. data/lib/makit/cli/clone.rb +59 -59
  7. data/lib/makit/cli/init.rb +38 -38
  8. data/lib/makit/cli/main.rb +33 -33
  9. data/lib/makit/cli/make.rb +54 -54
  10. data/lib/makit/cli/new.rb +37 -37
  11. data/lib/makit/cli/nuget_cache.rb +38 -38
  12. data/lib/makit/cli/pull.rb +31 -31
  13. data/lib/makit/cli/setup.rb +71 -71
  14. data/lib/makit/cli/work.rb +21 -21
  15. data/lib/makit/command_runner.rb +404 -404
  16. data/lib/makit/commands.rb +21 -21
  17. data/lib/makit/content/default_gitignore.rb +5 -5
  18. data/lib/makit/content/default_rakefile.rb +11 -11
  19. data/lib/makit/content/gem_rakefile.rb +14 -14
  20. data/lib/makit/data.rb +50 -50
  21. data/lib/makit/directories.rb +143 -143
  22. data/lib/makit/directory.rb +264 -219
  23. data/lib/makit/dotnet.rb +182 -182
  24. data/lib/makit/environment.rb +127 -127
  25. data/lib/makit/fileinfo.rb +16 -16
  26. data/lib/makit/files.rb +47 -47
  27. data/lib/makit/git.rb +96 -96
  28. data/lib/makit/gitlab_runner.rb +60 -60
  29. data/lib/makit/humanize.rb +129 -129
  30. data/lib/makit/indexer.rb +56 -56
  31. data/lib/makit/logging.rb +106 -96
  32. data/lib/makit/markdown.rb +75 -75
  33. data/lib/makit/mp/basic_object_mp.rb +16 -16
  34. data/lib/makit/mp/command_request.mp.rb +16 -16
  35. data/lib/makit/mp/project_mp.rb +210 -210
  36. data/lib/makit/mp/string_mp.rb +137 -137
  37. data/lib/makit/nuget.rb +62 -62
  38. data/lib/makit/process.rb +26 -26
  39. data/lib/makit/protoc.rb +104 -104
  40. data/lib/makit/secrets.rb +51 -51
  41. data/lib/makit/serializer.rb +115 -115
  42. data/lib/makit/show.rb +110 -110
  43. data/lib/makit/storage.rb +131 -131
  44. data/lib/makit/symbols.rb +149 -149
  45. data/lib/makit/tasks.rb +68 -61
  46. data/lib/makit/tree.rb +37 -37
  47. data/lib/makit/v1/makit.v1_pb.rb +34 -34
  48. data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
  49. data/lib/makit/version.rb +65 -65
  50. data/lib/makit/wix.rb +95 -95
  51. data/lib/makit/yaml.rb +17 -17
  52. data/lib/makit/zip.rb +17 -17
  53. data/lib/makit.rb +267 -267
  54. metadata +5 -3
@@ -1,219 +1,264 @@
1
- # frozen_string_literal: true
2
-
3
- require "find"
4
- require "pathname"
5
- #require "gitignore"
6
-
7
- # This module provides classes for the Makit gem.
8
- module Makit
9
- # This class provide methods for working with Directories/
10
- #
11
- # Example:
12
- #
13
- # Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
14
- #
15
- class Directory
16
- def self.get_line_count(file)
17
- line_count = 0
18
- File.foreach(file) { line_count += 1 }
19
- line_count
20
- end
21
-
22
- def self.find_directory_with_patterns(starting_directory, patterns)
23
- patterns.each do |pattern|
24
- result = find_directory_with_pattern(starting_directory, pattern)
25
- if (Dir.exist?(result))
26
- return result
27
- end
28
- end
29
-
30
- nil
31
- end
32
-
33
- def self.find_directory_with_pattern(starting_directory, pattern)
34
- current_directory = File.expand_path(starting_directory)
35
-
36
- loop do
37
- return current_directory if contains_pattern?(current_directory, pattern)
38
-
39
- parent_directory = File.dirname(current_directory)
40
- break if parent_directory == current_directory # Reached the root directory
41
-
42
- current_directory = parent_directory
43
- end
44
-
45
- nil
46
- end
47
-
48
- def self.contains_pattern?(directory, pattern)
49
- Dir.foreach(directory) do |entry|
50
- next if [".", ".."].include?(entry)
51
- return true if File.fnmatch(pattern, entry)
52
- end
53
- false
54
- end
55
-
56
- def self.get_size(directory)
57
- total_size = 0
58
-
59
- Find.find(directory) do |file|
60
- total_size += File.size(file) if File.file?(file)
61
- end
62
-
63
- total_size
64
- end
65
-
66
- def self.get_humanized_size(size_in_bytes, precision = 2)
67
- end
68
-
69
- def self.zip_source_files(directory_path, zip_file_name)
70
- raise ArgumentError, "Directory path cannot be nil" if directory_path.nil?
71
- raise ArgumentError, "Zip file name cannot be nil or empty" if zip_file_name.nil? || zip_file_name.strip.empty?
72
-
73
- unless Dir.exist?(directory_path)
74
- raise ArgumentError, "Directory '#{directory_path}' does not exist."
75
- end
76
-
77
- tracked_files = get_git_tracked_files(directory_path)
78
-
79
- if tracked_files.empty?
80
- raise "No tracked files found in the directory."
81
- end
82
-
83
- Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipfile|
84
- tracked_files.each do |file|
85
- full_path = File.join(directory_path, file)
86
- if File.exist?(full_path)
87
- zipfile.add(file, full_path)
88
- end
89
- end
90
- end
91
- end
92
-
93
- def self.get_git_tracked_files(directory_path)
94
- #raise "do not use this method"
95
- #output, status = Open3.capture2("git ls-files directory", chdir: directory_path)
96
- #raise "Failed to list git-tracked files" unless status.success?
97
- #command = "git ls-files #{directory_path}".run
98
-
99
- #command.output.split("\n")
100
- `git ls-files #{directory_path}`.split("\n")
101
- end
102
-
103
- def self.get_newest_git_file(directory_path)
104
- get_git_tracked_files(directory_path).select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
105
- end
106
-
107
- def self.get_newest_git_file_timestamp(directory_path)
108
- get_newest_git_file(directory_path).nil? ? Time.now : File.mtime(get_newest_git_file(directory_path))
109
- end
110
-
111
- def self.get_newest_file_timestamp(directory_path)
112
- newest_file = get_git_tracked_files(directory_path).select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
113
- newest_file.nil? ? Time.now : File.mtime(newest_file)
114
- end
115
-
116
- # Normalize the path by removing any leading or trailing slashes
117
- # and replacing any backslashes with forward slashes
118
- def self.normalize(path)
119
- path = path.gsub("\\", "/")
120
- #path = path[1..-1] if path.start_with?("/")
121
- path = path[0..-2] if path.end_with?("/")
122
- path
123
- end
124
-
125
- # for a given path, collect all the subdirectories that match a version pattern.
126
- # for example 2.57.0, 2.62, or 2.65.0
127
- def self.get_version_directories(path)
128
- version_directories = []
129
- Dir.foreach(path) do |entry|
130
- next if [".", ".."].include?(entry)
131
- version_directories << entry if entry.match?(/^\d+\.\d+\.\d+$/)
132
- end
133
- version_directories
134
- end
135
-
136
- def self.modified(path)
137
- self.get_newest_file(path)
138
- end
139
- # for a given path, get the most recent file change date for any file in the directory
140
- def self.get_latest_file_change_date(path)
141
- # loop over all files in the directory
142
- latest_date = nil
143
- Find.find(path) do |file|
144
- if File.file?(file)
145
- date = File.mtime(file)
146
- latest_date = date if latest_date.nil? || date > latest_date
147
- end
148
- end
149
- latest_date
150
- end
151
-
152
- # for a given path, return the filename of the most recently modified file
153
- def self.get_newest_file(path)
154
- newest_file = nil
155
- latest_date = nil
156
- if (Dir.exist?(path))
157
- Find.find(path) do |file|
158
- if File.file?(file)
159
- date = File.mtime(file)
160
- latest_date = date if latest_date.nil? || date > latest_date
161
- newest_file = file if date == latest_date
162
- end
163
- end
164
- end
165
- newest_file
166
- end
167
-
168
- def self.copy(src_dir, dst_dir, verbose = false)
169
- FileUtils.cp_r(src_dir, dst_dir, verbose: verbose)
170
- end
171
-
172
- def self.generate_manifest(dir)
173
- if File.exist?("#{dir}/manifest.txt")
174
- File.delete("#{dir}/manifest.txt")
175
- end
176
- File.open("#{dir}/manifest.txt", "w") do |f|
177
- Dir.glob("#{dir}/**/*").each do |file|
178
- next if File.directory?(file)
179
- f.puts file.sub("#{dir}/", "")
180
- end
181
- end
182
- end
183
-
184
- def self.remove_empty_directories(dir)
185
- Find.find(dir) do |path|
186
- if File.directory?(path) && Dir.empty?(path)
187
- FileUtils.rm_rf(path)
188
- end
189
- end
190
- end
191
-
192
- def self.remove_empty_directories_recursively(dir)
193
- Find.find(dir) do |path|
194
- if File.directory?(path) && Dir.empty?(path)
195
- FileUtils.rm_rf(path)
196
- end
197
- end
198
- end
199
-
200
- def self.deep_clean(dir)
201
- git_dirs = []
202
- #Dir.chdir(dir) do
203
- # scan all subdirectories for git repositories
204
- puts " scanning #{dir} for git repositories".colorize(:green)
205
- Find.find(dir) do |path|
206
- if File.directory?(path) && File.exist?("#{path}/.git")
207
- git_dirs << path
208
- end
209
- end
210
- #end
211
- git_dirs.each do |path|
212
- puts " cleaning #{path} of untracked files".colorize(:green)
213
- Dir.chdir(path) do
214
- puts `git clean -fdx`
215
- end
216
- end
217
- end
218
- end
219
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "find"
4
+ require "pathname"
5
+ #require "gitignore"
6
+
7
+ # This module provides classes for the Makit gem.
8
+ module Makit
9
+ # This class provide methods for working with Directories/
10
+ #
11
+ # Example:
12
+ #
13
+ # Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
14
+ #
15
+ class Directory
16
+ def self.show_dir_size(dir)
17
+ total_bytes = Dir.glob(File.join(dir, "**", "*"))
18
+ .select { |f| File.file?(f) }
19
+ .sum { |f| File.size(f) }
20
+
21
+ human_size(total_bytes)
22
+ puts " directory " + "#{dir}".colorize(:green) + " size is " + "#{human_size(total_bytes)}".colorize(:green)
23
+ end
24
+
25
+ def self.show_largest_files(dir, limit)
26
+ puts " directory " + "#{dir}".colorize(:green) + " #{limit} largest files"
27
+ files = Dir.glob(File.join(dir, '**', '*'), File::FNM_DOTMATCH)
28
+ .select { |f| File.file?(f) }
29
+
30
+ sorted = files.map { |f| [f, File.size(f)] }
31
+ .sort_by { |_, size| -size }
32
+ .first(limit)
33
+
34
+ sorted.each do |path, size|
35
+ # right justify human_size to be at least 10 characters wide
36
+ padded_size = human_size(size).rjust(10)
37
+ puts " #{padded_size}" + " rake#{path}".colorize(:green)
38
+ end
39
+ end
40
+
41
+ def human_size(bytes)
42
+ units = ['B', 'KB', 'MB', 'GB', 'TB']
43
+ return "0 B" if bytes == 0
44
+
45
+ exp = (Math.log(bytes) / Math.log(1024)).to_i
46
+ exp = units.size - 1 if exp >= units.size
47
+
48
+ "%.2f %s" % [bytes.to_f / 1024**exp, units[exp]]
49
+ end
50
+
51
+
52
+ def self.human_size(bytes)
53
+ units = ["B", "KB", "MB", "GB", "TB"]
54
+ return "0 B" if bytes == 0
55
+
56
+ exp = (Math.log(bytes) / Math.log(1024)).to_i
57
+ exp = units.size - 1 if exp >= units.size
58
+
59
+ "%.2f %s" % [bytes.to_f / 1024 ** exp, units[exp]]
60
+ end
61
+ def self.get_line_count(file)
62
+ line_count = 0
63
+ File.foreach(file) { line_count += 1 }
64
+ line_count
65
+ end
66
+
67
+ def self.find_directory_with_patterns(starting_directory, patterns)
68
+ patterns.each do |pattern|
69
+ result = find_directory_with_pattern(starting_directory, pattern)
70
+ if (Dir.exist?(result))
71
+ return result
72
+ end
73
+ end
74
+
75
+ nil
76
+ end
77
+
78
+ def self.find_directory_with_pattern(starting_directory, pattern)
79
+ current_directory = File.expand_path(starting_directory)
80
+
81
+ loop do
82
+ return current_directory if contains_pattern?(current_directory, pattern)
83
+
84
+ parent_directory = File.dirname(current_directory)
85
+ break if parent_directory == current_directory # Reached the root directory
86
+
87
+ current_directory = parent_directory
88
+ end
89
+
90
+ nil
91
+ end
92
+
93
+ def self.contains_pattern?(directory, pattern)
94
+ Dir.foreach(directory) do |entry|
95
+ next if [".", ".."].include?(entry)
96
+ return true if File.fnmatch(pattern, entry)
97
+ end
98
+ false
99
+ end
100
+
101
+ def self.get_size(directory)
102
+ total_size = 0
103
+
104
+ Find.find(directory) do |file|
105
+ total_size += File.size(file) if File.file?(file)
106
+ end
107
+
108
+ total_size
109
+ end
110
+
111
+ def self.get_humanized_size(size_in_bytes, precision = 2)
112
+ end
113
+
114
+ def self.zip_source_files(directory_path, zip_file_name)
115
+ raise ArgumentError, "Directory path cannot be nil" if directory_path.nil?
116
+ raise ArgumentError, "Zip file name cannot be nil or empty" if zip_file_name.nil? || zip_file_name.strip.empty?
117
+
118
+ unless Dir.exist?(directory_path)
119
+ raise ArgumentError, "Directory '#{directory_path}' does not exist."
120
+ end
121
+
122
+ tracked_files = get_git_tracked_files(directory_path)
123
+
124
+ if tracked_files.empty?
125
+ raise "No tracked files found in the directory."
126
+ end
127
+
128
+ Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipfile|
129
+ tracked_files.each do |file|
130
+ full_path = File.join(directory_path, file)
131
+ if File.exist?(full_path)
132
+ zipfile.add(file, full_path)
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ def self.get_git_tracked_files(directory_path)
139
+ #raise "do not use this method"
140
+ #output, status = Open3.capture2("git ls-files directory", chdir: directory_path)
141
+ #raise "Failed to list git-tracked files" unless status.success?
142
+ #command = "git ls-files #{directory_path}".run
143
+
144
+ #command.output.split("\n")
145
+ `git ls-files #{directory_path}`.split("\n")
146
+ end
147
+
148
+ def self.get_newest_git_file(directory_path)
149
+ get_git_tracked_files(directory_path).select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
150
+ end
151
+
152
+ def self.get_newest_git_file_timestamp(directory_path)
153
+ get_newest_git_file(directory_path).nil? ? Time.now : File.mtime(get_newest_git_file(directory_path))
154
+ end
155
+
156
+ def self.get_newest_file_timestamp(directory_path)
157
+ newest_file = get_git_tracked_files(directory_path).select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
158
+ newest_file.nil? ? Time.now : File.mtime(newest_file)
159
+ end
160
+
161
+ # Normalize the path by removing any leading or trailing slashes
162
+ # and replacing any backslashes with forward slashes
163
+ def self.normalize(path)
164
+ path = path.gsub("\\", "/")
165
+ #path = path[1..-1] if path.start_with?("/")
166
+ path = path[0..-2] if path.end_with?("/")
167
+ path
168
+ end
169
+
170
+ # for a given path, collect all the subdirectories that match a version pattern.
171
+ # for example 2.57.0, 2.62, or 2.65.0
172
+ def self.get_version_directories(path)
173
+ version_directories = []
174
+ Dir.foreach(path) do |entry|
175
+ next if [".", ".."].include?(entry)
176
+ version_directories << entry if entry.match?(/^\d+\.\d+\.\d+$/)
177
+ end
178
+ version_directories
179
+ end
180
+
181
+ def self.modified(path)
182
+ self.get_newest_file(path)
183
+ end
184
+ # for a given path, get the most recent file change date for any file in the directory
185
+ def self.get_latest_file_change_date(path)
186
+ # loop over all files in the directory
187
+ latest_date = nil
188
+ Find.find(path) do |file|
189
+ if File.file?(file)
190
+ date = File.mtime(file)
191
+ latest_date = date if latest_date.nil? || date > latest_date
192
+ end
193
+ end
194
+ latest_date
195
+ end
196
+
197
+ # for a given path, return the filename of the most recently modified file
198
+ def self.get_newest_file(path)
199
+ newest_file = nil
200
+ latest_date = nil
201
+ if (Dir.exist?(path))
202
+ Find.find(path) do |file|
203
+ if File.file?(file)
204
+ date = File.mtime(file)
205
+ latest_date = date if latest_date.nil? || date > latest_date
206
+ newest_file = file if date == latest_date
207
+ end
208
+ end
209
+ end
210
+ newest_file
211
+ end
212
+
213
+ def self.copy(src_dir, dst_dir, verbose = false)
214
+ FileUtils.cp_r(src_dir, dst_dir, verbose: verbose)
215
+ end
216
+
217
+ def self.generate_manifest(dir)
218
+ if File.exist?("#{dir}/manifest.txt")
219
+ File.delete("#{dir}/manifest.txt")
220
+ end
221
+ File.open("#{dir}/manifest.txt", "w") do |f|
222
+ Dir.glob("#{dir}/**/*").each do |file|
223
+ next if File.directory?(file)
224
+ f.puts file.sub("#{dir}/", "")
225
+ end
226
+ end
227
+ end
228
+
229
+ def self.remove_empty_directories(dir)
230
+ Find.find(dir) do |path|
231
+ if File.directory?(path) && Dir.empty?(path)
232
+ FileUtils.rm_rf(path)
233
+ end
234
+ end
235
+ end
236
+
237
+ def self.remove_empty_directories_recursively(dir)
238
+ Find.find(dir) do |path|
239
+ if File.directory?(path) && Dir.empty?(path)
240
+ FileUtils.rm_rf(path)
241
+ end
242
+ end
243
+ end
244
+
245
+ def self.deep_clean(dir)
246
+ git_dirs = []
247
+ #Dir.chdir(dir) do
248
+ # scan all subdirectories for git repositories
249
+ puts " scanning #{dir} for git repositories".colorize(:green)
250
+ Find.find(dir) do |path|
251
+ if File.directory?(path) && File.exist?("#{path}/.git")
252
+ git_dirs << path
253
+ end
254
+ end
255
+ #end
256
+ git_dirs.each do |path|
257
+ puts " cleaning #{path} of untracked files".colorize(:green)
258
+ Dir.chdir(path) do
259
+ puts `git clean -fdx`
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end