makit 0.0.75 → 0.0.76
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/generated/makit/v1/makit.v1_pb.rb +35 -0
- data/lib/generated/makit/v1/web/link_pb.rb +20 -0
- data/lib/makit/apache.rb +32 -32
- data/lib/makit/cli/clean.rb +14 -14
- data/lib/makit/cli/clone.rb +59 -59
- data/lib/makit/cli/init.rb +38 -38
- data/lib/makit/cli/main.rb +33 -33
- data/lib/makit/cli/make.rb +54 -54
- data/lib/makit/cli/new.rb +37 -37
- data/lib/makit/cli/nuget_cache.rb +38 -38
- data/lib/makit/cli/pull.rb +31 -31
- data/lib/makit/cli/setup.rb +71 -71
- data/lib/makit/cli/work.rb +21 -21
- data/lib/makit/command_runner.rb +404 -404
- data/lib/makit/commands.rb +21 -21
- data/lib/makit/content/default_gitignore.rb +5 -5
- data/lib/makit/content/default_gitignore.txt +222 -222
- data/lib/makit/content/default_rakefile.rb +11 -11
- data/lib/makit/content/gem_rakefile.rb +14 -14
- data/lib/makit/data.rb +50 -50
- data/lib/makit/directories.rb +143 -144
- data/lib/makit/directory.rb +264 -264
- data/lib/makit/docs/files.rb +94 -94
- data/lib/makit/docs/rake.rb +106 -106
- data/lib/makit/dotnet.rb +212 -182
- data/lib/makit/environment.rb +131 -131
- data/lib/makit/fileinfo.rb +26 -26
- data/lib/makit/files.rb +47 -47
- data/lib/makit/git.rb +145 -145
- data/lib/makit/gitlab_runner.rb +60 -60
- data/lib/makit/humanize.rb +129 -129
- data/lib/makit/indexer.rb +56 -56
- data/lib/makit/logging.rb +106 -106
- data/lib/makit/markdown.rb +75 -75
- data/lib/makit/mp/basic_object_mp.rb +16 -16
- data/lib/makit/mp/command_mp.rb +13 -13
- data/lib/makit/mp/command_request.mp.rb +16 -16
- data/lib/makit/mp/project_mp.rb +210 -210
- data/lib/makit/mp/string_mp.rb +137 -137
- data/lib/makit/nuget.rb +62 -62
- data/lib/makit/process.rb +26 -26
- data/lib/makit/protoc.rb +104 -104
- data/lib/makit/secrets.rb +51 -51
- data/lib/makit/serializer.rb +115 -115
- data/lib/makit/show.rb +110 -110
- data/lib/makit/storage.rb +131 -131
- data/lib/makit/symbols.rb +149 -149
- data/lib/makit/task_info.rb +86 -86
- data/lib/makit/tasks.rb +137 -137
- data/lib/makit/tree.rb +37 -37
- data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
- data/lib/makit/version.rb +65 -65
- data/lib/makit/wix.rb +95 -95
- data/lib/makit/yaml.rb +17 -17
- data/lib/makit/zip.rb +17 -17
- data/lib/makit.rb +267 -267
- metadata +5 -3
data/lib/makit/humanize.rb
CHANGED
@@ -1,129 +1,129 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This module provides classes for the Makit gem.
|
4
|
-
module Makit
|
5
|
-
class Humanize
|
6
|
-
def self.get_humanized_size(bytes, precision = 2)
|
7
|
-
units = ["B", "KB", "MB", "GB", "TB", "PB"]
|
8
|
-
return "0 B" if bytes == 0
|
9
|
-
|
10
|
-
exp = (Math.log(bytes) / Math.log(1024)).to_i
|
11
|
-
exp = units.size - 1 if exp >= units.size
|
12
|
-
|
13
|
-
size = bytes.to_f / (1024 ** exp)
|
14
|
-
format("%.#{precision}f %s", size, units[exp])
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.get_humanized_timestamp(timestamp)
|
18
|
-
return timestamp.strftime("%Y-%m-%d %I:%M:%S %p") if timestamp.respond_to?(:strftime)
|
19
|
-
timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.get_make_result_summary(make_result)
|
23
|
-
summary = "Make Result\n"
|
24
|
-
summary += " Repository: #{make_result.repository}\n"
|
25
|
-
summary += " Commit: #{make_result.commit}\n"
|
26
|
-
summary += " Branch: #{make_result.branch}\n"
|
27
|
-
summary += " Tag: #{make_result.tag}\n"
|
28
|
-
summary += " Device: #{make_result.device}\n"
|
29
|
-
summary += " Runtime Identifier: #{make_result.runtime_identifier}\n"
|
30
|
-
summary += " Initial Size: #{get_humanized_size(make_result.initial_size)}\n"
|
31
|
-
summary += " Final Size: #{get_humanized_size(make_result.final_size)}\n"
|
32
|
-
summary += " Delta Size: #{get_humanized_size(make_result.final_size - make_result.initial_size)}\n"
|
33
|
-
summary += " Commands: (#{make_result.commands.length})\n"
|
34
|
-
make_result.commands.each do |command|
|
35
|
-
details = get_command_details(command)
|
36
|
-
summary += "\n"
|
37
|
-
summary += indent_string(details, 4)
|
38
|
-
summary += "\n"
|
39
|
-
end
|
40
|
-
|
41
|
-
summary
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.get_commands(commands)
|
45
|
-
message = ""
|
46
|
-
commands.each do |command|
|
47
|
-
message += Makit::Humanize::get_command_details(command)
|
48
|
-
end
|
49
|
-
message
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.get_command_summary(command)
|
53
|
-
symbol = Makit::Symbols.warning
|
54
|
-
symbol = Makit::Symbols.checkmark if !command.exit_code.nil? && command.exit_code.zero?
|
55
|
-
symbol = Makit::Symbols.error if command.exit_code != 0
|
56
|
-
"#{symbol} #{command.name} #{command.arguments.join(" ")}"
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.get_command_details(command)
|
60
|
-
summary = "#{get_command_summary(command)}\n"
|
61
|
-
summary += " Name: #{command.name}\n"
|
62
|
-
summary += " Arguments: #{command.arguments.join(" ")}\n"
|
63
|
-
summary += " Directory: #{command.directory}\n"
|
64
|
-
summary += " Exit Code: #{command.exit_code}\n"
|
65
|
-
if command.output.length > 0
|
66
|
-
summary += " Output:\n"
|
67
|
-
summary += indent_string(command.output, 4)
|
68
|
-
summary += "\n"
|
69
|
-
end
|
70
|
-
if command.error.length > 0
|
71
|
-
summary += " Error:\n"
|
72
|
-
summary += indent_string(command.error, 4)
|
73
|
-
summary += "\n"
|
74
|
-
end
|
75
|
-
summary
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.indent_string(string, spaces)
|
79
|
-
string.split("\n").map { |line| " " * spaces + line }.join("\n")
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.get_protobuf_timestamp(timestamp)
|
83
|
-
Time.at(timestamp.seconds, timestamp.nanos / 1000.0).strftime("%Y-%m-%d %H:%M:%S")
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.get_protobuf_duration(duration)
|
87
|
-
total_seconds = duration.seconds + (duration.nanos / 1_000_000_000.0)
|
88
|
-
hours = (total_seconds / 3600).to_i
|
89
|
-
minutes = ((total_seconds % 3600) / 60).to_i
|
90
|
-
seconds = (total_seconds % 60).round(2)
|
91
|
-
"#{hours}h #{minutes}m #{seconds}s"
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.get_humanized_duration(seconds_value)
|
95
|
-
minutes = (seconds_value / 60).to_i
|
96
|
-
seconds = (seconds_value % 60).to_i
|
97
|
-
hours = (minutes / 60).to_i
|
98
|
-
minutes = minutes % 60
|
99
|
-
days = (hours / 24).to_i
|
100
|
-
hours = hours % 24
|
101
|
-
milliseconds = (seconds_value % 1 * 1000).to_i
|
102
|
-
|
103
|
-
parts = []
|
104
|
-
parts << "#{days} days" if days > 0
|
105
|
-
parts << "#{hours} hours" if hours > 0
|
106
|
-
if (minutes > 0)
|
107
|
-
if (minutes == 1)
|
108
|
-
parts << "1 minute"
|
109
|
-
else
|
110
|
-
parts << "#{minutes} minutes"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
if (seconds > 0)
|
114
|
-
if (seconds == 1)
|
115
|
-
parts << "1 second"
|
116
|
-
else
|
117
|
-
parts << "#{seconds} seconds"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
#parts << "#{seconds} seconds" if seconds > 0
|
121
|
-
parts << "#{milliseconds} milliseconds" if milliseconds > 0 && seconds < 1
|
122
|
-
|
123
|
-
if (parts.length == 0)
|
124
|
-
parts << "0 seconds"
|
125
|
-
end
|
126
|
-
parts.join(", ")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module provides classes for the Makit gem.
|
4
|
+
module Makit
|
5
|
+
class Humanize
|
6
|
+
def self.get_humanized_size(bytes, precision = 2)
|
7
|
+
units = ["B", "KB", "MB", "GB", "TB", "PB"]
|
8
|
+
return "0 B" if bytes == 0
|
9
|
+
|
10
|
+
exp = (Math.log(bytes) / Math.log(1024)).to_i
|
11
|
+
exp = units.size - 1 if exp >= units.size
|
12
|
+
|
13
|
+
size = bytes.to_f / (1024 ** exp)
|
14
|
+
format("%.#{precision}f %s", size, units[exp])
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_humanized_timestamp(timestamp)
|
18
|
+
return timestamp.strftime("%Y-%m-%d %I:%M:%S %p") if timestamp.respond_to?(:strftime)
|
19
|
+
timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_make_result_summary(make_result)
|
23
|
+
summary = "Make Result\n"
|
24
|
+
summary += " Repository: #{make_result.repository}\n"
|
25
|
+
summary += " Commit: #{make_result.commit}\n"
|
26
|
+
summary += " Branch: #{make_result.branch}\n"
|
27
|
+
summary += " Tag: #{make_result.tag}\n"
|
28
|
+
summary += " Device: #{make_result.device}\n"
|
29
|
+
summary += " Runtime Identifier: #{make_result.runtime_identifier}\n"
|
30
|
+
summary += " Initial Size: #{get_humanized_size(make_result.initial_size)}\n"
|
31
|
+
summary += " Final Size: #{get_humanized_size(make_result.final_size)}\n"
|
32
|
+
summary += " Delta Size: #{get_humanized_size(make_result.final_size - make_result.initial_size)}\n"
|
33
|
+
summary += " Commands: (#{make_result.commands.length})\n"
|
34
|
+
make_result.commands.each do |command|
|
35
|
+
details = get_command_details(command)
|
36
|
+
summary += "\n"
|
37
|
+
summary += indent_string(details, 4)
|
38
|
+
summary += "\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
summary
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_commands(commands)
|
45
|
+
message = ""
|
46
|
+
commands.each do |command|
|
47
|
+
message += Makit::Humanize::get_command_details(command)
|
48
|
+
end
|
49
|
+
message
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.get_command_summary(command)
|
53
|
+
symbol = Makit::Symbols.warning
|
54
|
+
symbol = Makit::Symbols.checkmark if !command.exit_code.nil? && command.exit_code.zero?
|
55
|
+
symbol = Makit::Symbols.error if command.exit_code != 0
|
56
|
+
"#{symbol} #{command.name} #{command.arguments.join(" ")}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.get_command_details(command)
|
60
|
+
summary = "#{get_command_summary(command)}\n"
|
61
|
+
summary += " Name: #{command.name}\n"
|
62
|
+
summary += " Arguments: #{command.arguments.join(" ")}\n"
|
63
|
+
summary += " Directory: #{command.directory}\n"
|
64
|
+
summary += " Exit Code: #{command.exit_code}\n"
|
65
|
+
if command.output.length > 0
|
66
|
+
summary += " Output:\n"
|
67
|
+
summary += indent_string(command.output, 4)
|
68
|
+
summary += "\n"
|
69
|
+
end
|
70
|
+
if command.error.length > 0
|
71
|
+
summary += " Error:\n"
|
72
|
+
summary += indent_string(command.error, 4)
|
73
|
+
summary += "\n"
|
74
|
+
end
|
75
|
+
summary
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.indent_string(string, spaces)
|
79
|
+
string.split("\n").map { |line| " " * spaces + line }.join("\n")
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.get_protobuf_timestamp(timestamp)
|
83
|
+
Time.at(timestamp.seconds, timestamp.nanos / 1000.0).strftime("%Y-%m-%d %H:%M:%S")
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.get_protobuf_duration(duration)
|
87
|
+
total_seconds = duration.seconds + (duration.nanos / 1_000_000_000.0)
|
88
|
+
hours = (total_seconds / 3600).to_i
|
89
|
+
minutes = ((total_seconds % 3600) / 60).to_i
|
90
|
+
seconds = (total_seconds % 60).round(2)
|
91
|
+
"#{hours}h #{minutes}m #{seconds}s"
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.get_humanized_duration(seconds_value)
|
95
|
+
minutes = (seconds_value / 60).to_i
|
96
|
+
seconds = (seconds_value % 60).to_i
|
97
|
+
hours = (minutes / 60).to_i
|
98
|
+
minutes = minutes % 60
|
99
|
+
days = (hours / 24).to_i
|
100
|
+
hours = hours % 24
|
101
|
+
milliseconds = (seconds_value % 1 * 1000).to_i
|
102
|
+
|
103
|
+
parts = []
|
104
|
+
parts << "#{days} days" if days > 0
|
105
|
+
parts << "#{hours} hours" if hours > 0
|
106
|
+
if (minutes > 0)
|
107
|
+
if (minutes == 1)
|
108
|
+
parts << "1 minute"
|
109
|
+
else
|
110
|
+
parts << "#{minutes} minutes"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
if (seconds > 0)
|
114
|
+
if (seconds == 1)
|
115
|
+
parts << "1 second"
|
116
|
+
else
|
117
|
+
parts << "#{seconds} seconds"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
#parts << "#{seconds} seconds" if seconds > 0
|
121
|
+
parts << "#{milliseconds} milliseconds" if milliseconds > 0 && seconds < 1
|
122
|
+
|
123
|
+
if (parts.length == 0)
|
124
|
+
parts << "0 seconds"
|
125
|
+
end
|
126
|
+
parts.join(", ")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/makit/indexer.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This module provides classes for the Makit gem.
|
4
|
-
module Makit
|
5
|
-
# This class provide methods for indexing objects.
|
6
|
-
#
|
7
|
-
class Indexer
|
8
|
-
attr_accessor :keywords_index # Hash of string key to string[] of keyword
|
9
|
-
attr_accessor :protoc_json_serializer
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@keywords_index = Hash.new
|
13
|
-
@protoc_json_serializer = Makit::Serializer::new(Makit::Proto3Formats::JSON)
|
14
|
-
end
|
15
|
-
|
16
|
-
def index(key, item)
|
17
|
-
# item must be serializable to json
|
18
|
-
keywords = []
|
19
|
-
hash = JSON.parse(item.to_json)
|
20
|
-
hash.each do |key, value|
|
21
|
-
value = value.to_s.downcase
|
22
|
-
if (value.length >= 3 && !keywords.include?(value))
|
23
|
-
keywords << value
|
24
|
-
end
|
25
|
-
end
|
26
|
-
keywords.each do |keyword|
|
27
|
-
if !@keywords_index.key?(keyword)
|
28
|
-
@keywords_index[keyword] = []
|
29
|
-
end
|
30
|
-
@keywords_index[keyword] << key unless @keywords_index[keyword].include?(key)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def search(query)
|
35
|
-
keys = []
|
36
|
-
# todo, remove terms less that length of 3
|
37
|
-
terms = query.downcase.split(" ").reject { |term| term.length < 3 }
|
38
|
-
keywords_index.each do |key, value| #{|kvp|
|
39
|
-
if (get_match_count(terms, value) == terms.length)
|
40
|
-
keys << key
|
41
|
-
end
|
42
|
-
end
|
43
|
-
keys
|
44
|
-
end
|
45
|
-
|
46
|
-
def get_match_count(terms, keywords)
|
47
|
-
match_count = 0
|
48
|
-
terms.each { |term|
|
49
|
-
if (keywords.include?(term))
|
50
|
-
match_count += 1
|
51
|
-
end
|
52
|
-
}
|
53
|
-
return match_count
|
54
|
-
end
|
55
|
-
end # class Indexer
|
56
|
-
end # module Makit
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module provides classes for the Makit gem.
|
4
|
+
module Makit
|
5
|
+
# This class provide methods for indexing objects.
|
6
|
+
#
|
7
|
+
class Indexer
|
8
|
+
attr_accessor :keywords_index # Hash of string key to string[] of keyword
|
9
|
+
attr_accessor :protoc_json_serializer
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@keywords_index = Hash.new
|
13
|
+
@protoc_json_serializer = Makit::Serializer::new(Makit::Proto3Formats::JSON)
|
14
|
+
end
|
15
|
+
|
16
|
+
def index(key, item)
|
17
|
+
# item must be serializable to json
|
18
|
+
keywords = []
|
19
|
+
hash = JSON.parse(item.to_json)
|
20
|
+
hash.each do |key, value|
|
21
|
+
value = value.to_s.downcase
|
22
|
+
if (value.length >= 3 && !keywords.include?(value))
|
23
|
+
keywords << value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
keywords.each do |keyword|
|
27
|
+
if !@keywords_index.key?(keyword)
|
28
|
+
@keywords_index[keyword] = []
|
29
|
+
end
|
30
|
+
@keywords_index[keyword] << key unless @keywords_index[keyword].include?(key)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def search(query)
|
35
|
+
keys = []
|
36
|
+
# todo, remove terms less that length of 3
|
37
|
+
terms = query.downcase.split(" ").reject { |term| term.length < 3 }
|
38
|
+
keywords_index.each do |key, value| #{|kvp|
|
39
|
+
if (get_match_count(terms, value) == terms.length)
|
40
|
+
keys << key
|
41
|
+
end
|
42
|
+
end
|
43
|
+
keys
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_match_count(terms, keywords)
|
47
|
+
match_count = 0
|
48
|
+
terms.each { |term|
|
49
|
+
if (keywords.include?(term))
|
50
|
+
match_count += 1
|
51
|
+
end
|
52
|
+
}
|
53
|
+
return match_count
|
54
|
+
end
|
55
|
+
end # class Indexer
|
56
|
+
end # module Makit
|
data/lib/makit/logging.rb
CHANGED
@@ -1,106 +1,106 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "logger"
|
4
|
-
require "colorize"
|
5
|
-
require_relative "symbols"
|
6
|
-
|
7
|
-
# This module provides classes for the Makit gem.
|
8
|
-
module Makit
|
9
|
-
module Logging
|
10
|
-
ANSI_COLOR_REGEX = /\e\[[0-9;]*m/
|
11
|
-
|
12
|
-
def self.log_rake_duration
|
13
|
-
# use the STARTTIME constant to log the duration of the rake task
|
14
|
-
# to the log/rake.duration.txt file
|
15
|
-
duration = Time.now - STARTTIME
|
16
|
-
FileUtils.mkdir_p("log") unless Dir.exist?("log")
|
17
|
-
File.open("log/rake.duration.txt", "a") do |file|
|
18
|
-
file.puts "Rake task duration: #{duration} seconds"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class PlainFormatter < Logger::Formatter
|
23
|
-
def call(_severity, _time, _progname, msg)
|
24
|
-
stripped_msg = msg.gsub(ANSI_COLOR_REGEX, "") # Remove ANSI color codes
|
25
|
-
"#{stripped_msg}\n"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class ColorFormatter < Logger::Formatter
|
30
|
-
def call(_severity, _time, _progname, msg)
|
31
|
-
"#{msg}\n"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# This class provide methods for working with Directories/
|
36
|
-
#
|
37
|
-
# Example:
|
38
|
-
#
|
39
|
-
# Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
|
40
|
-
#
|
41
|
-
class MultiLogger
|
42
|
-
def initialize(*targets)
|
43
|
-
@targets = targets
|
44
|
-
end
|
45
|
-
|
46
|
-
def add(severity, message = nil, progname = nil, &block)
|
47
|
-
@targets.each do |logger|
|
48
|
-
logger.add(severity, message, progname, &block)
|
49
|
-
logger.flush if logger.respond_to?(:flush)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def <<(message)
|
54
|
-
@targets.each do |logger|
|
55
|
-
logger << message
|
56
|
-
logger.flush if logger.respond_to?(:flush)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def close
|
61
|
-
@targets.each(&:close)
|
62
|
-
end
|
63
|
-
|
64
|
-
def method_missing(method, *args, &block)
|
65
|
-
@targets.each { |logger| logger.send(method, *args, &block) }
|
66
|
-
end
|
67
|
-
|
68
|
-
def respond_to_missing?(method, include_private = false)
|
69
|
-
@targets.all? { |logger| logger.respond_to?(method, include_private) }
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.create_logger
|
73
|
-
stdout_logger = Logger.new($stdout) # ColoredLogger.new(STDOUT)
|
74
|
-
stdout_logger.level = Logger::DEBUG
|
75
|
-
# Assign the custom formatter to the file_logger
|
76
|
-
stdout_logger.formatter = ColorFormatter.new
|
77
|
-
|
78
|
-
# if clean or clobber commands are used, then log ONLY to stdout
|
79
|
-
if ARGV.include?("clean") || ARGV.include?("clobber")
|
80
|
-
return stdout_logger
|
81
|
-
end
|
82
|
-
if Makit::Environment.project_root_directory.nil?
|
83
|
-
logger = stdout_logger
|
84
|
-
else
|
85
|
-
#log_filename = if ARGV.empty?
|
86
|
-
# "#{Makit::Environment.project_root_directory}/artifacts/rake.log"
|
87
|
-
# else
|
88
|
-
# "#{Makit::Environment.project_root_directory}/artifacts/rake_#{ARGV.join("_").gsub(":",
|
89
|
-
# "_")}.log"
|
90
|
-
# end
|
91
|
-
# FileUtils.remove_file(log_file) if File.exist?(log_file)
|
92
|
-
#FileUtils.mkdir_p(File.dirname(log_filename)) unless Dir.exist?(File.dirname(log_filename))
|
93
|
-
#File.open(log_filename, "w")
|
94
|
-
#file_logger = Logger.new(log_filename)
|
95
|
-
#file_logger.level = Logger::DEBUG
|
96
|
-
# Assign the custom formatter to the file_logger
|
97
|
-
#file_logger.formatter = PlainFormatter.new
|
98
|
-
#logger = MultiLogger.new(file_logger, stdout_logger)
|
99
|
-
logger = stdout_logger
|
100
|
-
end
|
101
|
-
|
102
|
-
logger
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require "colorize"
|
5
|
+
require_relative "symbols"
|
6
|
+
|
7
|
+
# This module provides classes for the Makit gem.
|
8
|
+
module Makit
|
9
|
+
module Logging
|
10
|
+
ANSI_COLOR_REGEX = /\e\[[0-9;]*m/
|
11
|
+
|
12
|
+
def self.log_rake_duration
|
13
|
+
# use the STARTTIME constant to log the duration of the rake task
|
14
|
+
# to the log/rake.duration.txt file
|
15
|
+
duration = Time.now - STARTTIME
|
16
|
+
FileUtils.mkdir_p("log") unless Dir.exist?("log")
|
17
|
+
File.open("log/rake.duration.txt", "a") do |file|
|
18
|
+
file.puts "Rake task duration: #{duration} seconds"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class PlainFormatter < Logger::Formatter
|
23
|
+
def call(_severity, _time, _progname, msg)
|
24
|
+
stripped_msg = msg.gsub(ANSI_COLOR_REGEX, "") # Remove ANSI color codes
|
25
|
+
"#{stripped_msg}\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ColorFormatter < Logger::Formatter
|
30
|
+
def call(_severity, _time, _progname, msg)
|
31
|
+
"#{msg}\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# This class provide methods for working with Directories/
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
#
|
39
|
+
# Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
|
40
|
+
#
|
41
|
+
class MultiLogger
|
42
|
+
def initialize(*targets)
|
43
|
+
@targets = targets
|
44
|
+
end
|
45
|
+
|
46
|
+
def add(severity, message = nil, progname = nil, &block)
|
47
|
+
@targets.each do |logger|
|
48
|
+
logger.add(severity, message, progname, &block)
|
49
|
+
logger.flush if logger.respond_to?(:flush)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def <<(message)
|
54
|
+
@targets.each do |logger|
|
55
|
+
logger << message
|
56
|
+
logger.flush if logger.respond_to?(:flush)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def close
|
61
|
+
@targets.each(&:close)
|
62
|
+
end
|
63
|
+
|
64
|
+
def method_missing(method, *args, &block)
|
65
|
+
@targets.each { |logger| logger.send(method, *args, &block) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def respond_to_missing?(method, include_private = false)
|
69
|
+
@targets.all? { |logger| logger.respond_to?(method, include_private) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.create_logger
|
73
|
+
stdout_logger = Logger.new($stdout) # ColoredLogger.new(STDOUT)
|
74
|
+
stdout_logger.level = Logger::DEBUG
|
75
|
+
# Assign the custom formatter to the file_logger
|
76
|
+
stdout_logger.formatter = ColorFormatter.new
|
77
|
+
|
78
|
+
# if clean or clobber commands are used, then log ONLY to stdout
|
79
|
+
if ARGV.include?("clean") || ARGV.include?("clobber")
|
80
|
+
return stdout_logger
|
81
|
+
end
|
82
|
+
if Makit::Environment.project_root_directory.nil?
|
83
|
+
logger = stdout_logger
|
84
|
+
else
|
85
|
+
#log_filename = if ARGV.empty?
|
86
|
+
# "#{Makit::Environment.project_root_directory}/artifacts/rake.log"
|
87
|
+
# else
|
88
|
+
# "#{Makit::Environment.project_root_directory}/artifacts/rake_#{ARGV.join("_").gsub(":",
|
89
|
+
# "_")}.log"
|
90
|
+
# end
|
91
|
+
# FileUtils.remove_file(log_file) if File.exist?(log_file)
|
92
|
+
#FileUtils.mkdir_p(File.dirname(log_filename)) unless Dir.exist?(File.dirname(log_filename))
|
93
|
+
#File.open(log_filename, "w")
|
94
|
+
#file_logger = Logger.new(log_filename)
|
95
|
+
#file_logger.level = Logger::DEBUG
|
96
|
+
# Assign the custom formatter to the file_logger
|
97
|
+
#file_logger.formatter = PlainFormatter.new
|
98
|
+
#logger = MultiLogger.new(file_logger, stdout_logger)
|
99
|
+
logger = stdout_logger
|
100
|
+
end
|
101
|
+
|
102
|
+
logger
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|