makit 0.0.2 → 0.0.3

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: a87da93549378cea2c13dbd6d1dcc4a1fc5b8eb79969c456a97c44c8f90a9bc4
4
- data.tar.gz: eccf1b3e8176bea2f0d0888855f24e733cee65a3bc7b82a50bacbfc8c26d9601
3
+ metadata.gz: d5ccf5a0952c59f63f6df2e59d7238fb85c8b67c1f8b7473727737800de77e88
4
+ data.tar.gz: b5aa85780eca251aa9fd4ee65e8242c59fdc1b0f6e4e74f5101654421f1bd689
5
5
  SHA512:
6
- metadata.gz: e734aa176bad0e765ef142444eea81908398fb0e716a0f40765c3aec4812b424f30cab5d567f9c14d52ef875869fcecacc434f0d7cfeeb8d6f1ca7fe6487c308
7
- data.tar.gz: f5fa4d9a6a04cda52f591d2cfb4fd8300fadcfe1a3af9cb77466474c6ee3c9c0a0f7e7134a5f965c020217881f96d5abda72d78ee403407dcd5ea9a0b652fc6b
6
+ metadata.gz: 1b7b163e38a8e6292ab70d8152bacfc006b7b6d976e2be70e2a87a41c5fbbbd0fb76d66c5c470656590a13588e79034b3cc7d7be5ab02266b50d21a885499099
7
+ data.tar.gz: bd82445d0365a5c6dfd1c5b9bbb6ba8b9980b5fad794c909c173b7e6b6a8cdf27283cb3a2af7b11636fa883ede91bc58693a68585061b0a88d7538f13200b634
@@ -13,10 +13,24 @@ module Makit
13
13
 
14
14
  def initialize
15
15
  @show_output_on_success = false
16
- @log_to_artifacts = false
16
+ @log_to_artifacts = true
17
17
  @commands = []
18
18
  end
19
19
 
20
+ def get_cache_filename(command)
21
+ # test if the command_request is a Makit::V1::CommandRequest
22
+ #if command_request.is_a? Makit::V1::CommandRequest || command_request.is_a? Makit::V1::Command
23
+ # also replacing any path delimiters with an underscore
24
+ int_hash = Digest::SHA256.hexdigest("{command.name}.#{command.arguments.join(" ")}")
25
+ # int_hash
26
+ #int_hash = command_request.to_hash
27
+ hash_string = "#{int_hash}"[0, 8]
28
+ cache_filename = Makit::Directories::PROJECT_ARTIFACTS +
29
+ "/commands/cache/#{hash_string}.pb"
30
+ # create the directory if it does not already exist
31
+ FileUtils.mkdir_p(File.dirname(cache_filename))
32
+ cache_filename
33
+ end
20
34
  # if there is a matching cached command result, that then the specified timestamp,
21
35
  # then return the cached result
22
36
  # otherwise run the command and save the result to a cache file
@@ -26,15 +40,16 @@ module Makit
26
40
  # and use it to create a cache filename, making sure it is a valid filename,
27
41
  # by replacing all characters that are not valid in a filename with an underscore
28
42
  # also replacing any path delimiters with an underscore
43
+ int_hash = command_request.to_hash
44
+ hash_string = "#{int_hash}"[0, 8]
29
45
  cache_filename = Makit::Directories::PROJECT_ARTIFACTS +
30
- "/commands/#{command_request.to_hash}.pb"
46
+ "/commands/#{hash_string}.pb"
31
47
  puts "cache_filename: #{cache_filename}"
32
48
 
33
-
34
49
  #cache_filename = Makit::Directories::PROJECT_ARTIFACTS + "/commands/#{command_request.name}.#{command_request.arguments.join("_")}.#{timestamp.seconds}.pb"
35
- if File.exist?(cache_filename)
50
+ if File.exist?(cache_filename)
36
51
  puts "cache file date: #{File.mtime(cache_filename)}"
37
- if(File.mtime(cache_filename) > timestamp)
52
+ if (File.mtime(cache_filename) > timestamp)
38
53
  puts "cache_filename exists and is newer than #{timestamp}"
39
54
  return Makit::Serializer.open(cache_filename, Makit::V1::Command)
40
55
  else
@@ -42,15 +57,12 @@ module Makit
42
57
  end
43
58
  end
44
59
 
45
-
46
-
47
- command = run(command_request)
48
- # make sure the cache directory exists
49
- FileUtils.mkdir_p(File.dirname(cache_filename))
50
- puts "saving command to cache_filename"
51
- Makit::Serializer.save_as(cache_filename, command)
52
- command
53
-
60
+ command = run(command_request)
61
+ # make sure the cache directory exists
62
+ FileUtils.mkdir_p(File.dirname(cache_filename))
63
+ puts "saving command to cache_filename"
64
+ Makit::Serializer.save_as(cache_filename, command)
65
+ command
54
66
  end
55
67
 
56
68
  # Run a command and return a Makit::V1::Command.
@@ -78,10 +90,11 @@ module Makit
78
90
  end
79
91
 
80
92
  def log_to_artifacts(command)
81
- dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
82
- FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
83
- filename_friendly_timestamp = Time.now.strftime("%Y.%m.%d_%H%M%S")
84
- log_filename = File.join(dir, "#{filename_friendly_timestamp}.json")
93
+ #dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
94
+ #FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
95
+ #filename_friendly_timestamp = Time.now.strftime("%Y.%m.%d_%H%M%S")
96
+ #log_filename = File.join(dir, "#{filename_friendly_timestamp}.json")
97
+ log_filename = get_cache_filename(command)
85
98
  # serialize to protobuf json
86
99
  json = command.to_json
87
100
  pretty_json = JSON.pretty_generate(JSON.parse(json))
@@ -270,5 +283,36 @@ module Makit
270
283
 
271
284
  summary
272
285
  end
286
+
287
+ def log_rake_commands
288
+ dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
289
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
290
+
291
+ # open a text file to write to
292
+ File.open(File.join(dir, "rake.commands.txt"), "w") do |file|
293
+ #rake_commands = commands.select { |command| command.name == "rake" }
294
+ commands.each do |command|
295
+ file.puts " " + Makit::CommandRunner.get_command_summary(command).strip_color_codes
296
+ file.puts " start time: #{command.started_at}"
297
+ file.puts command.output.strip_color_codes unless command.output.strip_color_codes.strip.length == 0
298
+ file.puts command.error.strip_color_codes unless command.error.strip_color_codes.strip.length == 0
299
+ file.puts " "
300
+ end
301
+ end
302
+ end
303
+ def log_slowest_commands
304
+ dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
305
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
306
+
307
+ # open a text file to write to
308
+ File.open(File.join(dir, "slow.commands.txt"), "w") do |file|
309
+ Makit::RUNNER.commands.sort_by { |command| (command.duration.seconds + (command.duration.nanos / 1_000_000_000.0)) }.reverse.first(5).each do |command|
310
+ # Convert to float representation
311
+ duration_in_float = command.duration.seconds + (command.duration.nanos / 1_000_000_000.0)
312
+ #puts " #{command.name} took #{duration_in_float} seconds"
313
+ file.puts " " + Makit::CommandRunner.get_command_summary(command).strip_color_codes + " (#{command.duration.seconds} seconds)"
314
+ end
315
+ end
316
+ end
273
317
  end # class CommandRunner
274
318
  end # module Makit
@@ -138,11 +138,13 @@ module Makit
138
138
  def self.get_newest_file(path)
139
139
  newest_file = nil
140
140
  latest_date = nil
141
- Find.find(path) do |file|
142
- if File.file?(file)
143
- date = File.mtime(file)
144
- latest_date = date if latest_date.nil? || date > latest_date
145
- newest_file = file if date == latest_date
141
+ if (Dir.exist?(path))
142
+ Find.find(path) do |file|
143
+ if File.file?(file)
144
+ date = File.mtime(file)
145
+ latest_date = date if latest_date.nil? || date > latest_date
146
+ newest_file = file if date == latest_date
147
+ end
146
148
  end
147
149
  end
148
150
  newest_file
data/lib/makit/dotnet.rb CHANGED
@@ -10,7 +10,7 @@ module Makit
10
10
 
11
11
  def self.new_project(template, name, output)
12
12
  if Dir.exist? output
13
- puts " #{output}".colorize(:green) + " exists.".colorize(:grey)
13
+ #puts " #{output}".colorize(:green) + " exists.".colorize(:grey)
14
14
  #puts "Directory #{output} already exists".colorize(:yellow)
15
15
  else
16
16
  "dotnet new #{template} --name #{name} --output #{output}".run
@@ -22,14 +22,14 @@ module Makit
22
22
  if (!project_content.include?("\"#{package_name}\""))
23
23
  "dotnet add #{project_path} package #{package_name}".run
24
24
  else
25
- puts " package ".colorize(:grey) + "#{package_name}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
25
+ #puts " package ".colorize(:grey) + "#{package_name}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
26
26
  end
27
27
  end
28
28
 
29
29
  def self.add_reference(project_path, reference_path)
30
30
  project_content = File.read(project_path)
31
31
  if (project_content.include?("<PackageReference Include=\"#{package}\""))
32
- puts " reference ".colorize(:grey) + "#{reference_path}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
32
+ #puts " reference ".colorize(:grey) + "#{reference_path}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
33
33
  else
34
34
  "dotnet add #{project_path} reference #{reference_path}".run
35
35
  end
@@ -38,7 +38,7 @@ module Makit
38
38
  def self.new_solution(name)
39
39
  if File.exist? "#{name}.sln"
40
40
  #puts "Solution #{name}.sln already exists".colorize(:yellow)
41
- puts " #{name}.sln".colorize(:green) + " exists".colorize(:grey)
41
+ #puts " #{name}.sln".colorize(:green) + " exists".colorize(:grey)
42
42
  else
43
43
  "dotnet new sln --name #{name}".run
44
44
  end
@@ -114,7 +114,7 @@ module Makit
114
114
  puts " Creating solution file: " + "#{self.name}.sln".colorize(:green)
115
115
  "dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln")
116
116
  else
117
- puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
117
+ #puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
118
118
  end
119
119
  self.dotnet_projects.each do |project|
120
120
  add_project = true
@@ -74,6 +74,12 @@ class String
74
74
  # Alias for set_json_value
75
75
  alias_method :assign, :set_json_value
76
76
 
77
+ def strip_color_codes
78
+ # Regular expression to remove ANSI color codes
79
+ cleaned_content = self.gsub(/\e\[[\d;]+m/, "")
80
+ cleaned_content
81
+ end
82
+
77
83
  def to_lines(max_length = 80, indent_length = 5)
78
84
  if (self.length <= max_length)
79
85
  return self
data/lib/makit/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Makit
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
 
6
6
  class Version
7
7
  # given an array of version strings, return the highest version
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Parslow