makit 0.0.26 → 0.0.27
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/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 +343 -343
- data/lib/makit/commands.rb +21 -21
- data/lib/makit/content/default_gitignore.rb +5 -5
- 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 +140 -140
- data/lib/makit/directory.rb +184 -181
- data/lib/makit/dotnet.rb +104 -104
- data/lib/makit/environment.rb +123 -123
- data/lib/makit/fileinfo.rb +16 -16
- data/lib/makit/files.rb +47 -47
- data/lib/makit/git.rb +80 -80
- data/lib/makit/gitlab_runner.rb +60 -60
- data/lib/makit/humanize.rb +112 -112
- data/lib/makit/logging.rb +96 -96
- data/lib/makit/markdown.rb +75 -75
- data/lib/makit/mp/basic_object_mp.rb +16 -16
- 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 +117 -117
- data/lib/makit/nuget.rb +57 -57
- data/lib/makit/protoc.rb +87 -61
- data/lib/makit/serializer.rb +115 -115
- data/lib/makit/show.rb +65 -0
- data/lib/makit/storage.rb +131 -131
- data/lib/makit/symbols.rb +149 -149
- data/lib/makit/tasks.rb +55 -55
- data/lib/makit/tree.rb +37 -37
- data/lib/makit/v1/makit.v1_pb.rb +3 -4
- data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
- data/lib/makit/version.rb +12 -12
- data/lib/makit/wix.rb +95 -95
- data/lib/makit/zip.rb +17 -17
- data/lib/makit.rb +254 -254
- metadata +4 -3
data/lib/makit/mp/project_mp.rb
CHANGED
@@ -1,210 +1,210 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "json"
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
module Makit
|
6
|
-
module V1
|
7
|
-
class Project
|
8
|
-
#def to_yaml
|
9
|
-
# data = JSON.parse(self.to_pretty_json)
|
10
|
-
# data.to_yaml.sub(/^---\n/, "")
|
11
|
-
#end
|
12
|
-
|
13
|
-
def self.create
|
14
|
-
project = Makit::V1::Project.new
|
15
|
-
project.set_default_values
|
16
|
-
project
|
17
|
-
end
|
18
|
-
|
19
|
-
def open(filename)
|
20
|
-
other = Makit::Serializer.open(filename, Makit::V1::Project)
|
21
|
-
#other = Makit::V1::Project::create_from_file(filename)
|
22
|
-
self.name = other.name
|
23
|
-
self.git_remote_url = other.git_remote_url
|
24
|
-
self.dotnet_projects = other.dotnet_projects
|
25
|
-
self.artifacts = other.artifacts
|
26
|
-
end
|
27
|
-
|
28
|
-
#def self.create_from_file(filename)
|
29
|
-
# extension = File.extname(filename)
|
30
|
-
# case extension
|
31
|
-
# when ".yml"
|
32
|
-
# yaml = File.read(filename)
|
33
|
-
# create_from_yaml(yaml)
|
34
|
-
# when ".json"
|
35
|
-
# json = File.read(filename)
|
36
|
-
# create_from_json(json)
|
37
|
-
# else
|
38
|
-
# raise "unsupported file extension: #{extension}"
|
39
|
-
# end
|
40
|
-
#end
|
41
|
-
|
42
|
-
#def self.create_from_yaml(yaml)
|
43
|
-
# json = JSON.pretty_generate(YAML.load(yaml))
|
44
|
-
# project = Makit::V1::Project.decode_json(json)
|
45
|
-
# project
|
46
|
-
#end
|
47
|
-
|
48
|
-
#def self.create_from_json(json)
|
49
|
-
# project = Makit::V1::Project.decode_json(json)
|
50
|
-
# project
|
51
|
-
#end
|
52
|
-
|
53
|
-
def set_default_values
|
54
|
-
#self.language = "csharp"
|
55
|
-
#self.primary_artifact_type = "nuget"
|
56
|
-
if self.git_remote_url.nil? || self.git_remote_url.empty?
|
57
|
-
self.git_remote_url = `git remote get-url origin`.strip
|
58
|
-
end
|
59
|
-
if self.name.nil? || self.name.empty?
|
60
|
-
if (!self.git_remote_url.nil? && !self.git_remote_url.empty?)
|
61
|
-
self.name = get_name(File.basename(self.git_remote_url, ".git")) # get_capitalized_name(File.basename(self.git_remote_url, ".git"))
|
62
|
-
else
|
63
|
-
self.name = get_name(File.basename(Dir.getwd)) # get_capitalized_name(File.basename(Dir.getwd))
|
64
|
-
end
|
65
|
-
end
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
def get_name(name)
|
70
|
-
if !self.git_remote_url.nil? && !self.git_remote_url.empty?
|
71
|
-
is_dotnet = self.git_remote_url.include?("nuget")
|
72
|
-
if is_dotnet
|
73
|
-
get_capitalized_name(name)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
name.downcase
|
77
|
-
end
|
78
|
-
|
79
|
-
def get_capitalized_name(name)
|
80
|
-
name.split(".").map(&:capitalize).join(".")
|
81
|
-
end
|
82
|
-
|
83
|
-
def save_as(filename)
|
84
|
-
Makit::Serializer.save_as(filename, self)
|
85
|
-
#extension = File.extname(filename)
|
86
|
-
#case extension
|
87
|
-
#when ".json"
|
88
|
-
# File.write(filename, self.to_pretty_json)
|
89
|
-
#when ".yml"
|
90
|
-
# File.write(filename, self.to_yaml)
|
91
|
-
#else
|
92
|
-
# raise "unsupported file extension: #{extension}"
|
93
|
-
#end
|
94
|
-
end
|
95
|
-
|
96
|
-
def with_dotnet_project(template, name, output)
|
97
|
-
if !self.dotnet_projects.any? { |project| project.output == output }
|
98
|
-
project = Makit::V1::DotNetProject.new
|
99
|
-
project.template = template
|
100
|
-
project.name = name
|
101
|
-
project.output = output
|
102
|
-
self.dotnet_projects << project
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def setup
|
107
|
-
setup_dotnet_projects
|
108
|
-
end
|
109
|
-
|
110
|
-
def make
|
111
|
-
setup_dotnet_projects
|
112
|
-
make_dotnet_projects
|
113
|
-
|
114
|
-
# verify the artifacts exist
|
115
|
-
self.artifacts.each do |artifact|
|
116
|
-
raise "artifact does not exist: #{artifact}" if !File.exist?(artifact)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def build
|
121
|
-
build_dotnet_projects
|
122
|
-
end
|
123
|
-
|
124
|
-
def test
|
125
|
-
test_dotnet_projects
|
126
|
-
end
|
127
|
-
|
128
|
-
def setup_dotnet_projects
|
129
|
-
if self.dotnet_projects.any?
|
130
|
-
if (!File.exist?("#{self.name}.sln"))
|
131
|
-
puts " Creating solution file: " + "#{self.name}.sln".colorize(:green)
|
132
|
-
"dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln")
|
133
|
-
else
|
134
|
-
#puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
|
135
|
-
end
|
136
|
-
self.dotnet_projects.each do |project|
|
137
|
-
add_project = true
|
138
|
-
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
139
|
-
add_project = false
|
140
|
-
end
|
141
|
-
if (add_project)
|
142
|
-
Makit::DotNet.new_project(project.template, project.name, project.output)
|
143
|
-
# add any nuget packages to the project
|
144
|
-
project_filename = "#{project.output}/#{project.name}.csproj"
|
145
|
-
project.packages.each { |package|
|
146
|
-
Makit::DotNet::add_package(project_filename, package)
|
147
|
-
}
|
148
|
-
end
|
149
|
-
end
|
150
|
-
#Makit::DotNet.new_solution(self.name)
|
151
|
-
Makit::DotNet.sln_add_projects(self.name)
|
152
|
-
else
|
153
|
-
#puts " no dotnet projects found".colorize(:yellow)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def make_dotnet_projects
|
158
|
-
self.dotnet_projects.each do |project|
|
159
|
-
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
160
|
-
next
|
161
|
-
else
|
162
|
-
project.commands.each do |command|
|
163
|
-
newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
|
164
|
-
#newest_file = Makit::Directory::get_newest_file_or_now(project.output)
|
165
|
-
command_request = Makit::RUNNER::parse_command_request(command)
|
166
|
-
RUNNER.cache_run(command_request, newest_file_timestamp)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def build_dotnet_projects
|
173
|
-
self.dotnet_projects.each do |project|
|
174
|
-
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
175
|
-
next
|
176
|
-
else
|
177
|
-
project.commands.each do |command|
|
178
|
-
newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
|
179
|
-
#newest_file = Makit::Directory::get_newest_file_or_now(project.output)
|
180
|
-
command_request = Makit::RUNNER::parse_command_request(command)
|
181
|
-
RUNNER.cache_run(command_request, newest_file_timestamp)
|
182
|
-
end
|
183
|
-
project.build_args.each do |build_arg|
|
184
|
-
project_path = File.join(project.output, "#{project.name}.csproj")
|
185
|
-
Makit::DotNet.build(project_path, build_arg.configuration, build_arg.output)
|
186
|
-
end
|
187
|
-
project.publish_args.each do |publish_arg|
|
188
|
-
project_path = File.join(project.output, "#{project.name}.csproj")
|
189
|
-
Makit::DotNet.publish(project_path, publish_arg.configuration, publish_arg.output)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_dotnet_projects
|
196
|
-
self.dotnet_projects.each do |project|
|
197
|
-
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
198
|
-
next
|
199
|
-
else
|
200
|
-
project.test_args.each do |test_args|
|
201
|
-
project_path = File.join(project.output, "#{project.name}.csproj")
|
202
|
-
Makit::DotNet.test(project_path, test_args.configuration, test_args.output)
|
203
|
-
end
|
204
|
-
#"dotnet test #{project.output} --configuration Release".run
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end # class Project
|
209
|
-
end # module V1
|
210
|
-
end # module Makit
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "json"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module Makit
|
6
|
+
module V1
|
7
|
+
class Project
|
8
|
+
#def to_yaml
|
9
|
+
# data = JSON.parse(self.to_pretty_json)
|
10
|
+
# data.to_yaml.sub(/^---\n/, "")
|
11
|
+
#end
|
12
|
+
|
13
|
+
def self.create
|
14
|
+
project = Makit::V1::Project.new
|
15
|
+
project.set_default_values
|
16
|
+
project
|
17
|
+
end
|
18
|
+
|
19
|
+
def open(filename)
|
20
|
+
other = Makit::Serializer.open(filename, Makit::V1::Project)
|
21
|
+
#other = Makit::V1::Project::create_from_file(filename)
|
22
|
+
self.name = other.name
|
23
|
+
self.git_remote_url = other.git_remote_url
|
24
|
+
self.dotnet_projects = other.dotnet_projects
|
25
|
+
self.artifacts = other.artifacts
|
26
|
+
end
|
27
|
+
|
28
|
+
#def self.create_from_file(filename)
|
29
|
+
# extension = File.extname(filename)
|
30
|
+
# case extension
|
31
|
+
# when ".yml"
|
32
|
+
# yaml = File.read(filename)
|
33
|
+
# create_from_yaml(yaml)
|
34
|
+
# when ".json"
|
35
|
+
# json = File.read(filename)
|
36
|
+
# create_from_json(json)
|
37
|
+
# else
|
38
|
+
# raise "unsupported file extension: #{extension}"
|
39
|
+
# end
|
40
|
+
#end
|
41
|
+
|
42
|
+
#def self.create_from_yaml(yaml)
|
43
|
+
# json = JSON.pretty_generate(YAML.load(yaml))
|
44
|
+
# project = Makit::V1::Project.decode_json(json)
|
45
|
+
# project
|
46
|
+
#end
|
47
|
+
|
48
|
+
#def self.create_from_json(json)
|
49
|
+
# project = Makit::V1::Project.decode_json(json)
|
50
|
+
# project
|
51
|
+
#end
|
52
|
+
|
53
|
+
def set_default_values
|
54
|
+
#self.language = "csharp"
|
55
|
+
#self.primary_artifact_type = "nuget"
|
56
|
+
if self.git_remote_url.nil? || self.git_remote_url.empty?
|
57
|
+
self.git_remote_url = `git remote get-url origin`.strip
|
58
|
+
end
|
59
|
+
if self.name.nil? || self.name.empty?
|
60
|
+
if (!self.git_remote_url.nil? && !self.git_remote_url.empty?)
|
61
|
+
self.name = get_name(File.basename(self.git_remote_url, ".git")) # get_capitalized_name(File.basename(self.git_remote_url, ".git"))
|
62
|
+
else
|
63
|
+
self.name = get_name(File.basename(Dir.getwd)) # get_capitalized_name(File.basename(Dir.getwd))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_name(name)
|
70
|
+
if !self.git_remote_url.nil? && !self.git_remote_url.empty?
|
71
|
+
is_dotnet = self.git_remote_url.include?("nuget")
|
72
|
+
if is_dotnet
|
73
|
+
get_capitalized_name(name)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
name.downcase
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_capitalized_name(name)
|
80
|
+
name.split(".").map(&:capitalize).join(".")
|
81
|
+
end
|
82
|
+
|
83
|
+
def save_as(filename)
|
84
|
+
Makit::Serializer.save_as(filename, self)
|
85
|
+
#extension = File.extname(filename)
|
86
|
+
#case extension
|
87
|
+
#when ".json"
|
88
|
+
# File.write(filename, self.to_pretty_json)
|
89
|
+
#when ".yml"
|
90
|
+
# File.write(filename, self.to_yaml)
|
91
|
+
#else
|
92
|
+
# raise "unsupported file extension: #{extension}"
|
93
|
+
#end
|
94
|
+
end
|
95
|
+
|
96
|
+
def with_dotnet_project(template, name, output)
|
97
|
+
if !self.dotnet_projects.any? { |project| project.output == output }
|
98
|
+
project = Makit::V1::DotNetProject.new
|
99
|
+
project.template = template
|
100
|
+
project.name = name
|
101
|
+
project.output = output
|
102
|
+
self.dotnet_projects << project
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def setup
|
107
|
+
setup_dotnet_projects
|
108
|
+
end
|
109
|
+
|
110
|
+
def make
|
111
|
+
setup_dotnet_projects
|
112
|
+
make_dotnet_projects
|
113
|
+
|
114
|
+
# verify the artifacts exist
|
115
|
+
self.artifacts.each do |artifact|
|
116
|
+
raise "artifact does not exist: #{artifact}" if !File.exist?(artifact)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def build
|
121
|
+
build_dotnet_projects
|
122
|
+
end
|
123
|
+
|
124
|
+
def test
|
125
|
+
test_dotnet_projects
|
126
|
+
end
|
127
|
+
|
128
|
+
def setup_dotnet_projects
|
129
|
+
if self.dotnet_projects.any?
|
130
|
+
if (!File.exist?("#{self.name}.sln"))
|
131
|
+
puts " Creating solution file: " + "#{self.name}.sln".colorize(:green)
|
132
|
+
"dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln")
|
133
|
+
else
|
134
|
+
#puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
|
135
|
+
end
|
136
|
+
self.dotnet_projects.each do |project|
|
137
|
+
add_project = true
|
138
|
+
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
139
|
+
add_project = false
|
140
|
+
end
|
141
|
+
if (add_project)
|
142
|
+
Makit::DotNet.new_project(project.template, project.name, project.output)
|
143
|
+
# add any nuget packages to the project
|
144
|
+
project_filename = "#{project.output}/#{project.name}.csproj"
|
145
|
+
project.packages.each { |package|
|
146
|
+
Makit::DotNet::add_package(project_filename, package)
|
147
|
+
}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
#Makit::DotNet.new_solution(self.name)
|
151
|
+
Makit::DotNet.sln_add_projects(self.name)
|
152
|
+
else
|
153
|
+
#puts " no dotnet projects found".colorize(:yellow)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def make_dotnet_projects
|
158
|
+
self.dotnet_projects.each do |project|
|
159
|
+
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
160
|
+
next
|
161
|
+
else
|
162
|
+
project.commands.each do |command|
|
163
|
+
newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
|
164
|
+
#newest_file = Makit::Directory::get_newest_file_or_now(project.output)
|
165
|
+
command_request = Makit::RUNNER::parse_command_request(command)
|
166
|
+
RUNNER.cache_run(command_request, newest_file_timestamp)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def build_dotnet_projects
|
173
|
+
self.dotnet_projects.each do |project|
|
174
|
+
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
175
|
+
next
|
176
|
+
else
|
177
|
+
project.commands.each do |command|
|
178
|
+
newest_file_timestamp = Makit::Directory::get_newest_file_timestamp(project.output)
|
179
|
+
#newest_file = Makit::Directory::get_newest_file_or_now(project.output)
|
180
|
+
command_request = Makit::RUNNER::parse_command_request(command)
|
181
|
+
RUNNER.cache_run(command_request, newest_file_timestamp)
|
182
|
+
end
|
183
|
+
project.build_args.each do |build_arg|
|
184
|
+
project_path = File.join(project.output, "#{project.name}.csproj")
|
185
|
+
Makit::DotNet.build(project_path, build_arg.configuration, build_arg.output)
|
186
|
+
end
|
187
|
+
project.publish_args.each do |publish_arg|
|
188
|
+
project_path = File.join(project.output, "#{project.name}.csproj")
|
189
|
+
Makit::DotNet.publish(project_path, publish_arg.configuration, publish_arg.output)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_dotnet_projects
|
196
|
+
self.dotnet_projects.each do |project|
|
197
|
+
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
198
|
+
next
|
199
|
+
else
|
200
|
+
project.test_args.each do |test_args|
|
201
|
+
project_path = File.join(project.output, "#{project.name}.csproj")
|
202
|
+
Makit::DotNet.test(project_path, test_args.configuration, test_args.output)
|
203
|
+
end
|
204
|
+
#"dotnet test #{project.output} --configuration Release".run
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end # class Project
|
209
|
+
end # module V1
|
210
|
+
end # module Makit
|
data/lib/makit/mp/string_mp.rb
CHANGED
@@ -1,117 +1,117 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "json"
|
3
|
-
# monkey patch String class with a run method
|
4
|
-
|
5
|
-
class String
|
6
|
-
def run(args = nil)
|
7
|
-
if args.nil?
|
8
|
-
command = self
|
9
|
-
Makit::RUNNER.run(Makit::RUNNER::parse_command_request(command))
|
10
|
-
else
|
11
|
-
command = self
|
12
|
-
request = Makit::RUNNER.parse_args(command)
|
13
|
-
if args.is_a?(Hash)
|
14
|
-
args.each do |key, value|
|
15
|
-
request.send("#{key}=", value)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
Makit::RUNNER.run(request)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def try(args = nil)
|
23
|
-
if args.nil?
|
24
|
-
command = self
|
25
|
-
Makit::RUNNER.try(command)
|
26
|
-
else
|
27
|
-
command = self
|
28
|
-
request = Makit::RUNNER.parse_args(command)
|
29
|
-
if args.is_a?(Hash)
|
30
|
-
args.each do |key, value|
|
31
|
-
request.send("#{key}=", value)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
Makit::RUNNER.try(request)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def cache_run(timestamp = nil)
|
39
|
-
if timestamp.nil?
|
40
|
-
timestamp = Makit::GIT_FILE_INFOS.first.mtime #GIT_FILE_INFOS. Makit::Directory.get_newest_git_file_timestamp(Makit::Directories::PROJECT_ROOT)
|
41
|
-
#timestamp = Makit::Timestamp.now
|
42
|
-
end
|
43
|
-
|
44
|
-
command = self
|
45
|
-
Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command), timestamp)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Read a value from a JSON file
|
49
|
-
# key is a string with the key to read, e.g. "AzureAd.Authority"
|
50
|
-
def get_json_value(key)
|
51
|
-
json = File.read(self)
|
52
|
-
data = JSON.parse(json)
|
53
|
-
|
54
|
-
# key delimiter is '.' so we can access nested keys
|
55
|
-
key.split(".").each do |k|
|
56
|
-
data = data[k]
|
57
|
-
end
|
58
|
-
data
|
59
|
-
end
|
60
|
-
|
61
|
-
alias_method :retrieve, :get_json_value
|
62
|
-
|
63
|
-
# Set a value in a JSON file
|
64
|
-
# key is a string with the key to set, e.g. "AzureAd.Authority"
|
65
|
-
def set_json_value(key, value)
|
66
|
-
file = File.read(self)
|
67
|
-
data = JSON.parse(file)
|
68
|
-
keys = key.split(".")
|
69
|
-
current = data
|
70
|
-
|
71
|
-
# Traverse and create any missing keys
|
72
|
-
keys[0..-2].each do |k|
|
73
|
-
current[k] ||= {} # Create a new hash if the key doesn't exist
|
74
|
-
current = current[k]
|
75
|
-
end
|
76
|
-
|
77
|
-
# Set the value for the final key
|
78
|
-
current[keys[-1]] = value
|
79
|
-
|
80
|
-
# Write the JSON back to the file
|
81
|
-
File.write(self, JSON.pretty_generate(data))
|
82
|
-
end
|
83
|
-
|
84
|
-
# Alias for set_json_value
|
85
|
-
alias_method :assign, :set_json_value
|
86
|
-
|
87
|
-
def strip_color_codes
|
88
|
-
# Regular expression to remove ANSI color codes
|
89
|
-
cleaned_content = self.gsub(/\e\[[\d;]+m/, "")
|
90
|
-
cleaned_content
|
91
|
-
end
|
92
|
-
|
93
|
-
def to_lines(max_length = 80, indent_length = 5)
|
94
|
-
if (self.length <= max_length)
|
95
|
-
return self
|
96
|
-
else
|
97
|
-
indent = " " * indent_length
|
98
|
-
words = self.split(" ")
|
99
|
-
lines = []
|
100
|
-
line = ""
|
101
|
-
words.each do |word|
|
102
|
-
if ((line + word).length > max_length)
|
103
|
-
lines << line
|
104
|
-
line = indent + word
|
105
|
-
else
|
106
|
-
if (line.length == 0)
|
107
|
-
line = word
|
108
|
-
else
|
109
|
-
line += " " + word
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
lines << line
|
114
|
-
return lines.join("\n")
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "json"
|
3
|
+
# monkey patch String class with a run method
|
4
|
+
|
5
|
+
class String
|
6
|
+
def run(args = nil)
|
7
|
+
if args.nil?
|
8
|
+
command = self
|
9
|
+
Makit::RUNNER.run(Makit::RUNNER::parse_command_request(command))
|
10
|
+
else
|
11
|
+
command = self
|
12
|
+
request = Makit::RUNNER.parse_args(command)
|
13
|
+
if args.is_a?(Hash)
|
14
|
+
args.each do |key, value|
|
15
|
+
request.send("#{key}=", value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
Makit::RUNNER.run(request)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def try(args = nil)
|
23
|
+
if args.nil?
|
24
|
+
command = self
|
25
|
+
Makit::RUNNER.try(command)
|
26
|
+
else
|
27
|
+
command = self
|
28
|
+
request = Makit::RUNNER.parse_args(command)
|
29
|
+
if args.is_a?(Hash)
|
30
|
+
args.each do |key, value|
|
31
|
+
request.send("#{key}=", value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
Makit::RUNNER.try(request)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def cache_run(timestamp = nil)
|
39
|
+
if timestamp.nil?
|
40
|
+
timestamp = Makit::GIT_FILE_INFOS.first.mtime #GIT_FILE_INFOS. Makit::Directory.get_newest_git_file_timestamp(Makit::Directories::PROJECT_ROOT)
|
41
|
+
#timestamp = Makit::Timestamp.now
|
42
|
+
end
|
43
|
+
|
44
|
+
command = self
|
45
|
+
Makit::RUNNER.cache_run(Makit::RUNNER::parse_command_request(command), timestamp)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Read a value from a JSON file
|
49
|
+
# key is a string with the key to read, e.g. "AzureAd.Authority"
|
50
|
+
def get_json_value(key)
|
51
|
+
json = File.read(self)
|
52
|
+
data = JSON.parse(json)
|
53
|
+
|
54
|
+
# key delimiter is '.' so we can access nested keys
|
55
|
+
key.split(".").each do |k|
|
56
|
+
data = data[k]
|
57
|
+
end
|
58
|
+
data
|
59
|
+
end
|
60
|
+
|
61
|
+
alias_method :retrieve, :get_json_value
|
62
|
+
|
63
|
+
# Set a value in a JSON file
|
64
|
+
# key is a string with the key to set, e.g. "AzureAd.Authority"
|
65
|
+
def set_json_value(key, value)
|
66
|
+
file = File.read(self)
|
67
|
+
data = JSON.parse(file)
|
68
|
+
keys = key.split(".")
|
69
|
+
current = data
|
70
|
+
|
71
|
+
# Traverse and create any missing keys
|
72
|
+
keys[0..-2].each do |k|
|
73
|
+
current[k] ||= {} # Create a new hash if the key doesn't exist
|
74
|
+
current = current[k]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Set the value for the final key
|
78
|
+
current[keys[-1]] = value
|
79
|
+
|
80
|
+
# Write the JSON back to the file
|
81
|
+
File.write(self, JSON.pretty_generate(data))
|
82
|
+
end
|
83
|
+
|
84
|
+
# Alias for set_json_value
|
85
|
+
alias_method :assign, :set_json_value
|
86
|
+
|
87
|
+
def strip_color_codes
|
88
|
+
# Regular expression to remove ANSI color codes
|
89
|
+
cleaned_content = self.gsub(/\e\[[\d;]+m/, "")
|
90
|
+
cleaned_content
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_lines(max_length = 80, indent_length = 5)
|
94
|
+
if (self.length <= max_length)
|
95
|
+
return self
|
96
|
+
else
|
97
|
+
indent = " " * indent_length
|
98
|
+
words = self.split(" ")
|
99
|
+
lines = []
|
100
|
+
line = ""
|
101
|
+
words.each do |word|
|
102
|
+
if ((line + word).length > max_length)
|
103
|
+
lines << line
|
104
|
+
line = indent + word
|
105
|
+
else
|
106
|
+
if (line.length == 0)
|
107
|
+
line = word
|
108
|
+
else
|
109
|
+
line += " " + word
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
lines << line
|
114
|
+
return lines.join("\n")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|