raykit 0.0.540 → 0.0.541

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +25 -25
  4. data/bin/raykit +6 -6
  5. data/lib/raykit/auto_setup.rb +69 -69
  6. data/lib/raykit/command.rb +374 -374
  7. data/lib/raykit/conan/buildinfo.rb +69 -69
  8. data/lib/raykit/conanpackage.rb +49 -49
  9. data/lib/raykit/configuration.rb +53 -53
  10. data/lib/raykit/console.rb +310 -310
  11. data/lib/raykit/default_content.rb +8 -8
  12. data/lib/raykit/default_content.txt +219 -219
  13. data/lib/raykit/dir.rb +127 -127
  14. data/lib/raykit/dotnet.rb +174 -174
  15. data/lib/raykit/environment.rb +115 -115
  16. data/lib/raykit/filesystem.rb +34 -34
  17. data/lib/raykit/git/commit.rb +16 -16
  18. data/lib/raykit/git/directory.rb +275 -273
  19. data/lib/raykit/git/files.rb +46 -46
  20. data/lib/raykit/git/repositories.rb +89 -89
  21. data/lib/raykit/git/repository.rb +362 -362
  22. data/lib/raykit/installer.rb +17 -17
  23. data/lib/raykit/log.rb +80 -80
  24. data/lib/raykit/logevent.rb +29 -29
  25. data/lib/raykit/logger.rb +100 -100
  26. data/lib/raykit/logging.rb +57 -57
  27. data/lib/raykit/markdown.rb +21 -21
  28. data/lib/raykit/msbuild.rb +54 -54
  29. data/lib/raykit/nugetpackage.rb +54 -54
  30. data/lib/raykit/nunit.rb +13 -13
  31. data/lib/raykit/project.rb +343 -343
  32. data/lib/raykit/rake.rb +39 -39
  33. data/lib/raykit/runner.rb +42 -42
  34. data/lib/raykit/secrets.rb +38 -38
  35. data/lib/raykit/sourceImport.rb +76 -76
  36. data/lib/raykit/sourceImports.rb +43 -43
  37. data/lib/raykit/string.rb +18 -18
  38. data/lib/raykit/symbols.rb +115 -115
  39. data/lib/raykit/tasks.rb +91 -91
  40. data/lib/raykit/text.rb +32 -32
  41. data/lib/raykit/timer.rb +31 -31
  42. data/lib/raykit/version.rb +95 -95
  43. data/lib/raykit/vstest.rb +24 -24
  44. data/lib/raykit/wix.rb +61 -61
  45. data/lib/raykit/wt.rb +28 -28
  46. data/lib/raykit/zip.rb +73 -73
  47. data/lib/raykit.rb +140 -140
  48. metadata +2 -2
@@ -1,16 +1,16 @@
1
- # frozen_string_literal: true
2
-
3
- module Raykit
4
- module Git
5
- # Functionality to manage a git commit
6
- class Commit
7
- attr_accessor :url, :branch, :commit_id
8
-
9
- def initialize(url, branch, commit_id)
10
- @url = url
11
- @branch = branch
12
- @commit_id = commit_id
13
- end
14
- end
15
- end
16
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Raykit
4
+ module Git
5
+ # Functionality to manage a git commit
6
+ class Commit
7
+ attr_accessor :url, :branch, :commit_id
8
+
9
+ def initialize(url, branch, commit_id)
10
+ @url = url
11
+ @branch = branch
12
+ @commit_id = commit_id
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,273 +1,275 @@
1
- # frozen_string_literal: true
2
-
3
- module Raykit
4
- module Git
5
- # Functionality to manage a local clone of a git repository
6
- class Directory
7
- # The directory name of the local repository clone
8
- attr_accessor :directory
9
-
10
- @repository
11
-
12
- def initialize(directory)
13
- @directory = directory
14
- end
15
-
16
- def outstanding_commit?
17
- Dir.chdir(directory) do
18
- return false if !File.exist?(".git")
19
- if user_can_commit
20
- return !`git status`.include?("nothing to commit,")
21
- else
22
- return false
23
- end
24
- end
25
- end
26
-
27
- def detached?
28
- Dir.chdir(directory) do
29
- status = `git status`.strip
30
- if status.include?("detached")
31
- true
32
- else
33
- false
34
- end
35
- end
36
- end
37
-
38
- def pull
39
- Dir.chdir(directory) do
40
- diff = `git diff`.strip
41
- status = `git status`.strip
42
- PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
43
- end
44
- end
45
-
46
- def rake(task)
47
- unless Dir.exist?(@directory)
48
- puts "directory not found."
49
- return 1
50
- end
51
- debug = false
52
- sub_dir = "work"
53
- sub_dir = "make" if @directory.include?("/make/")
54
- rake_log = repository.get_dev_dir("log") + "/#{sub_dir}.rake.#{task}.json"
55
-
56
- puts "log filename #{rake_log}" if debug
57
- if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
58
- puts "using logged data" if debug
59
- cmd = Raykit::Command.parse(File.read(rake_log))
60
- cmd.summary
61
- return
62
- end
63
-
64
- Dir.chdir(@directory) do
65
- if File.exist?("rakefile.rb")
66
- cmd = Raykit::Command.new("rake #{task}")
67
- cmd.summary
68
- FileUtils.mkdir_p(File.dirname(rake_log))
69
- File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
70
- else
71
- puts "rakefile.rb not found"
72
- end
73
- end
74
- end
75
-
76
- def last_modified_time
77
- Dir.chdir(@directory) do
78
-
79
- # Find the most recently modified file
80
- most_recent_file = Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
81
-
82
- # Use File.mtime if a file was found, otherwise handle the nil case
83
- if most_recent_file
84
- last_modified_time = File.mtime(most_recent_file)
85
- else
86
- # Handle the case where no files are found. This could be setting a default value,
87
- # raising a custom error, or any other appropriate action depending on your needs.
88
- # For example, setting last_modified_time to Time.now or raising a custom error.
89
- last_modified_time = Time.now # Or any other appropriate action
90
- end
91
-
92
- #File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
93
- end
94
- end
95
-
96
- def last_modified_filename
97
- Dir.chdir(@directory) do
98
- # TODO: consider handling the case where glob can fail because of filename length
99
- # Errno::ENAMETOOLONG: File name too long @ dir_s_glob - /Users/username/...
100
- #
101
- begin
102
- # Use Dir.glob to find all files, select the actual files, find the one with the latest modification time, and return its name
103
- files = Dir.glob("**/*.*").select { |f| File.file?(f) }
104
-
105
- # Find the file with the latest modification time
106
- latest_file = files.max_by { |f| File.mtime(f) }
107
-
108
- return latest_file
109
-
110
- #Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
111
- rescue Errno::ENAMETOOLONG => e
112
- puts "Error: #{e.message}"
113
- return handle_long_filename_error
114
- end
115
- end
116
- end
117
-
118
- # git ls-tree -r master --name-only
119
- def src_files
120
- files = Array.new
121
- Dir.chdir(@directory) do
122
- `git ls-tree -r #{branch} --name-only`.each_line { |line|
123
- file = line.strip
124
- files << file if file.length > 0 && File.exist?(file)
125
- }
126
- end
127
- files
128
- end
129
-
130
- def last_modified_src_time
131
- Dir.chdir(@directory) do
132
- last_file = self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
133
- last_file ? File.mtime(last_file) : Time.at(0) # Return a default time if no file is found
134
- end
135
- end
136
-
137
- #def last_modified_src_time
138
- # #File.mtim(src_files.max_by { |f| File.mtime(f) }#
139
- # Dir.chdir(@directory) do
140
- # File.mtime(self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
141
- # end
142
- #end
143
-
144
- def last_modified_src_file
145
- Dir.chdir(@directory) do
146
- # Select the source files that are actual files, not directories
147
- src_files.select { |f| File.file?(f) }
148
- # Find the max by modification time
149
- .max_by { |f| File.mtime(f) }
150
- end
151
- end
152
-
153
- def last_modified_artifact_time
154
- self.last_modified_time
155
- end
156
-
157
- # The latest tag for a branch of the repository
158
- def latest_tag(_branch)
159
- Dir.chdir(directory) do
160
- return `git describe --abbrev=0`.strip
161
- end
162
- ""
163
- end
164
-
165
- def get_tag_commit_id(name)
166
- cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
167
- if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
168
- cmd.output.strip
169
- else
170
- ""
171
- end
172
- end
173
-
174
- def has_tag(name)
175
- cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
176
- if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
177
- true
178
- else
179
- false
180
- end
181
- end
182
-
183
- def get_sha(filename)
184
- if File.exist?(filename)
185
- Digest::SHA256.file(filename).hexdigest.to_s
186
- else
187
- "#{filename} not found"
188
- end
189
- # ''
190
- end
191
-
192
- def user_name
193
- `git config --get user.name`.strip
194
- end
195
-
196
- def user_email
197
- `git config --get user.email`.strip
198
- end
199
-
200
- def user_can_commit
201
- return false if user_name.length.zero?
202
- return false if user_email.length.zero?
203
-
204
- true
205
- end
206
-
207
- def branch
208
- Dir.chdir(directory) do
209
- scan = `git branch`.scan(/\*\s([\w.-]+)/)
210
- return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
211
- end
212
- "master"
213
- end
214
-
215
- def repository
216
- @repository = Raykit::Git::Repository.new(remote) if @repository.nil?
217
- @repository
218
- end
219
-
220
- def remote
221
- if Dir.exist?(directory)
222
- Dir.chdir(directory) do
223
- return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
224
- end
225
- end
226
- ""
227
- end
228
-
229
- def tag_version(version)
230
- if has_tag "v#{version}"
231
- puts " git tag v#{version} already exists"
232
- else
233
- if outstanding_commit?
234
- raise "outstanding commit, will not tag"
235
- else
236
- puts " git tag v#{version} does not exist"
237
- run("git tag -a v#{version} -m\"version #{version}\"")
238
- end
239
- end
240
- end
241
-
242
- def get_unique_ruby_constants
243
- # Define the regular expression pattern
244
- pattern = /\b([A-Z][A-Z0-9_]*)\b\s*=/
245
-
246
- constants = []
247
-
248
- # Loop through each .rb file in the specified directory
249
- Dir.glob("#{directory}/**/*.rb").each do |file|
250
- # Read the contents of the file
251
- content = File.read(file)
252
-
253
- # Scan the content for constants and add the matches to the array.
254
- content.scan(pattern) do |match|
255
- # Add matched constant name to the constants array.
256
- constants << match[0]
257
- end
258
- # Scan the content for constants and add the matches to the array
259
- #constants.concat(content.scan(pattern))
260
- end
261
-
262
- # Return unique constants
263
- constants.uniq
264
- end
265
-
266
- #def setup
267
- # DEFAULT_SUBDIRECTORIES.each do |subdirectory|
268
- # FileUtils.mkdir_p(subdirectory)
269
- # end
270
- #end
271
- end # class Directory
272
- end # module Git
273
- end # module Raykit
1
+ # frozen_string_literal: true
2
+
3
+ module Raykit
4
+ module Git
5
+ # Functionality to manage a local clone of a git repository
6
+ class Directory
7
+ # The directory name of the local repository clone
8
+ attr_accessor :directory
9
+
10
+ @repository
11
+
12
+ def initialize(directory)
13
+ @directory = directory
14
+ end
15
+
16
+ def outstanding_commit?
17
+ Dir.chdir(directory) do
18
+ return false if !File.exist?(".git")
19
+ if user_can_commit
20
+ return !`git status`.include?("nothing to commit,")
21
+ else
22
+ return false
23
+ end
24
+ end
25
+ end
26
+
27
+ def detached?
28
+ Dir.chdir(directory) do
29
+ status = `git status`.strip
30
+ if status.include?("detached")
31
+ true
32
+ else
33
+ false
34
+ end
35
+ end
36
+ end
37
+
38
+ def pull
39
+ Dir.chdir(directory) do
40
+ diff = `git diff`.strip
41
+ status = `git status`.strip
42
+ PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
43
+ end
44
+ end
45
+
46
+ def rake(task)
47
+ unless Dir.exist?(@directory)
48
+ puts "directory not found."
49
+ return 1
50
+ end
51
+ debug = false
52
+ sub_dir = "work"
53
+ sub_dir = "make" if @directory.include?("/make/")
54
+ rake_log = repository.get_dev_dir("log") + "/#{sub_dir}.rake.#{task}.json"
55
+
56
+ puts "log filename #{rake_log}" if debug
57
+ if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
58
+ puts "using logged data" if debug
59
+ cmd = Raykit::Command.parse(File.read(rake_log))
60
+ cmd.summary
61
+ return
62
+ end
63
+
64
+ Dir.chdir(@directory) do
65
+ if File.exist?("rakefile.rb")
66
+ cmd = Raykit::Command.new("rake #{task}")
67
+ cmd.summary
68
+ FileUtils.mkdir_p(File.dirname(rake_log))
69
+ File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
70
+ else
71
+ puts "rakefile.rb not found"
72
+ end
73
+ end
74
+ end
75
+
76
+ def last_modified_time
77
+ Dir.chdir(@directory) do
78
+
79
+ # Find the most recently modified file
80
+ most_recent_file = Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
81
+
82
+ # Use File.mtime if a file was found, otherwise handle the nil case
83
+ if most_recent_file
84
+ last_modified_time = File.mtime(most_recent_file)
85
+ else
86
+ # Handle the case where no files are found. This could be setting a default value,
87
+ # raising a custom error, or any other appropriate action depending on your needs.
88
+ # For example, setting last_modified_time to Time.now or raising a custom error.
89
+ last_modified_time = Time.now # Or any other appropriate action
90
+ end
91
+
92
+ #File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
93
+ end
94
+ end
95
+
96
+ def last_modified_filename
97
+ Dir.chdir(@directory) do
98
+ # TODO: consider handling the case where glob can fail because of filename length
99
+ # Errno::ENAMETOOLONG: File name too long @ dir_s_glob - /Users/username/...
100
+ #
101
+ begin
102
+ # Use Dir.glob to find all files, select the actual files, find the one with the latest modification time, and return its name
103
+ files = Dir.glob("**/*.*").select { |f| File.file?(f) }
104
+
105
+ # Find the file with the latest modification time
106
+ latest_file = files.max_by { |f| File.mtime(f) }
107
+
108
+ return latest_file
109
+
110
+ #Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
111
+ rescue Errno::ENAMETOOLONG => e
112
+ puts "Error: #{e.message}"
113
+ # return the first src file found
114
+ src_files.each { |f| return f if File.file?(f) }
115
+ #return handle_long_filename_error
116
+ end
117
+ end
118
+ end
119
+
120
+ # git ls-tree -r master --name-only
121
+ def src_files
122
+ files = Array.new
123
+ Dir.chdir(@directory) do
124
+ `git ls-tree -r #{branch} --name-only`.each_line { |line|
125
+ file = line.strip
126
+ files << file if file.length > 0 && File.exist?(file)
127
+ }
128
+ end
129
+ files
130
+ end
131
+
132
+ def last_modified_src_time
133
+ Dir.chdir(@directory) do
134
+ last_file = self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
135
+ last_file ? File.mtime(last_file) : Time.at(0) # Return a default time if no file is found
136
+ end
137
+ end
138
+
139
+ #def last_modified_src_time
140
+ # #File.mtim(src_files.max_by { |f| File.mtime(f) }#
141
+ # Dir.chdir(@directory) do
142
+ # File.mtime(self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
143
+ # end
144
+ #end
145
+
146
+ def last_modified_src_file
147
+ Dir.chdir(@directory) do
148
+ # Select the source files that are actual files, not directories
149
+ src_files.select { |f| File.file?(f) }
150
+ # Find the max by modification time
151
+ .max_by { |f| File.mtime(f) }
152
+ end
153
+ end
154
+
155
+ def last_modified_artifact_time
156
+ self.last_modified_time
157
+ end
158
+
159
+ # The latest tag for a branch of the repository
160
+ def latest_tag(_branch)
161
+ Dir.chdir(directory) do
162
+ return `git describe --abbrev=0`.strip
163
+ end
164
+ ""
165
+ end
166
+
167
+ def get_tag_commit_id(name)
168
+ cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
169
+ if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
170
+ cmd.output.strip
171
+ else
172
+ ""
173
+ end
174
+ end
175
+
176
+ def has_tag(name)
177
+ cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
178
+ if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
179
+ true
180
+ else
181
+ false
182
+ end
183
+ end
184
+
185
+ def get_sha(filename)
186
+ if File.exist?(filename)
187
+ Digest::SHA256.file(filename).hexdigest.to_s
188
+ else
189
+ "#{filename} not found"
190
+ end
191
+ # ''
192
+ end
193
+
194
+ def user_name
195
+ `git config --get user.name`.strip
196
+ end
197
+
198
+ def user_email
199
+ `git config --get user.email`.strip
200
+ end
201
+
202
+ def user_can_commit
203
+ return false if user_name.length.zero?
204
+ return false if user_email.length.zero?
205
+
206
+ true
207
+ end
208
+
209
+ def branch
210
+ Dir.chdir(directory) do
211
+ scan = `git branch`.scan(/\*\s([\w.-]+)/)
212
+ return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
213
+ end
214
+ "master"
215
+ end
216
+
217
+ def repository
218
+ @repository = Raykit::Git::Repository.new(remote) if @repository.nil?
219
+ @repository
220
+ end
221
+
222
+ def remote
223
+ if Dir.exist?(directory)
224
+ Dir.chdir(directory) do
225
+ return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
226
+ end
227
+ end
228
+ ""
229
+ end
230
+
231
+ def tag_version(version)
232
+ if has_tag "v#{version}"
233
+ puts " git tag v#{version} already exists"
234
+ else
235
+ if outstanding_commit?
236
+ raise "outstanding commit, will not tag"
237
+ else
238
+ puts " git tag v#{version} does not exist"
239
+ run("git tag -a v#{version} -m\"version #{version}\"")
240
+ end
241
+ end
242
+ end
243
+
244
+ def get_unique_ruby_constants
245
+ # Define the regular expression pattern
246
+ pattern = /\b([A-Z][A-Z0-9_]*)\b\s*=/
247
+
248
+ constants = []
249
+
250
+ # Loop through each .rb file in the specified directory
251
+ Dir.glob("#{directory}/**/*.rb").each do |file|
252
+ # Read the contents of the file
253
+ content = File.read(file)
254
+
255
+ # Scan the content for constants and add the matches to the array.
256
+ content.scan(pattern) do |match|
257
+ # Add matched constant name to the constants array.
258
+ constants << match[0]
259
+ end
260
+ # Scan the content for constants and add the matches to the array
261
+ #constants.concat(content.scan(pattern))
262
+ end
263
+
264
+ # Return unique constants
265
+ constants.uniq
266
+ end
267
+
268
+ #def setup
269
+ # DEFAULT_SUBDIRECTORIES.each do |subdirectory|
270
+ # FileUtils.mkdir_p(subdirectory)
271
+ # end
272
+ #end
273
+ end # class Directory
274
+ end # module Git
275
+ end # module Raykit