makit 0.0.5 → 0.0.6
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 +321 -318
- 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 +153 -153
- data/lib/makit/dotnet.rb +83 -83
- data/lib/makit/environment.rb +123 -123
- data/lib/makit/files.rb +47 -47
- data/lib/makit/git.rb +66 -66
- data/lib/makit/gitlab_runner.rb +60 -60
- data/lib/makit/humanize.rb +89 -89
- 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/project_mp.rb +160 -156
- data/lib/makit/mp/string_mp.rb +107 -107
- data/lib/makit/nuget.rb +57 -57
- data/lib/makit/protoc.rb +61 -61
- data/lib/makit/serializer.rb +115 -115
- data/lib/makit/storage.rb +131 -131
- data/lib/makit/symbols.rb +149 -149
- data/lib/makit/tasks.rb +67 -67
- data/lib/makit/tree.rb +37 -37
- data/lib/makit/v1/makit.v1_pb.rb +4 -3
- 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 +243 -243
- metadata +3 -3
data/lib/makit/mp/project_mp.rb
CHANGED
@@ -1,156 +1,160 @@
|
|
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::V1::Project::create_from_file(filename)
|
21
|
-
self.name = other.name
|
22
|
-
self.git_remote_url = other.git_remote_url
|
23
|
-
self.dotnet_projects = other.dotnet_projects
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.create_from_file(filename)
|
27
|
-
extension = File.extname(filename)
|
28
|
-
case extension
|
29
|
-
when ".yml"
|
30
|
-
yaml = File.read(filename)
|
31
|
-
create_from_yaml(yaml)
|
32
|
-
when ".json"
|
33
|
-
json = File.read(filename)
|
34
|
-
create_from_json(json)
|
35
|
-
else
|
36
|
-
raise "unsupported file extension: #{extension}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.create_from_yaml(yaml)
|
41
|
-
json = JSON.pretty_generate(YAML.load(yaml))
|
42
|
-
project = Makit::V1::Project.decode_json(json)
|
43
|
-
project
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.create_from_json(json)
|
47
|
-
project = Makit::V1::Project.decode_json(json)
|
48
|
-
project
|
49
|
-
end
|
50
|
-
|
51
|
-
def set_default_values
|
52
|
-
#self.language = "csharp"
|
53
|
-
#self.primary_artifact_type = "nuget"
|
54
|
-
if self.git_remote_url.nil? || self.git_remote_url.empty?
|
55
|
-
self.git_remote_url = `git remote get-url origin`.strip
|
56
|
-
end
|
57
|
-
if self.name.nil? || self.name.empty?
|
58
|
-
if (!self.git_remote_url.nil? && !self.git_remote_url.empty?)
|
59
|
-
self.name = get_name(File.basename(self.git_remote_url, ".git")) # get_capitalized_name(File.basename(self.git_remote_url, ".git"))
|
60
|
-
else
|
61
|
-
self.name = get_name(File.basename(Dir.getwd)) # get_capitalized_name(File.basename(Dir.getwd))
|
62
|
-
end
|
63
|
-
end
|
64
|
-
self
|
65
|
-
end
|
66
|
-
|
67
|
-
def get_name(name)
|
68
|
-
if !self.git_remote_url.nil? && !self.git_remote_url.empty?
|
69
|
-
is_dotnet = self.git_remote_url.include?("nuget")
|
70
|
-
if is_dotnet
|
71
|
-
get_capitalized_name(name)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
name.downcase
|
75
|
-
end
|
76
|
-
|
77
|
-
def get_capitalized_name(name)
|
78
|
-
name.split(".").map(&:capitalize).join(".")
|
79
|
-
end
|
80
|
-
|
81
|
-
def save_as(filename)
|
82
|
-
extension = File.extname(filename)
|
83
|
-
case extension
|
84
|
-
when ".json"
|
85
|
-
File.write(filename, self.to_pretty_json)
|
86
|
-
when ".yml"
|
87
|
-
File.write(filename, self.to_yaml)
|
88
|
-
else
|
89
|
-
raise "unsupported file extension: #{extension}"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def with_dotnet_project(template, name, output)
|
94
|
-
if !self.dotnet_projects.any? { |project| project.output == output }
|
95
|
-
project = Makit::V1::DotNetProject.new
|
96
|
-
project.template = template
|
97
|
-
project.name = name
|
98
|
-
project.output = output
|
99
|
-
self.dotnet_projects << project
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def setup
|
104
|
-
setup_dotnet_projects
|
105
|
-
end
|
106
|
-
|
107
|
-
def build
|
108
|
-
build_dotnet_projects
|
109
|
-
end
|
110
|
-
|
111
|
-
def setup_dotnet_projects
|
112
|
-
if self.dotnet_projects.any?
|
113
|
-
if (!File.exist?("#{self.name}.sln"))
|
114
|
-
puts " Creating solution file: " + "#{self.name}.sln".colorize(:green)
|
115
|
-
"dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln")
|
116
|
-
else
|
117
|
-
#puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
|
118
|
-
end
|
119
|
-
self.dotnet_projects.each do |project|
|
120
|
-
add_project = true
|
121
|
-
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
122
|
-
add_project = false
|
123
|
-
end
|
124
|
-
if (add_project)
|
125
|
-
Makit::DotNet.new_project(project.template, project.name, project.output)
|
126
|
-
# add any nuget packages to the project
|
127
|
-
project_filename = "#{project.output}/#{project.name}.csproj"
|
128
|
-
project.packages.each { |package|
|
129
|
-
Makit::DotNet::add_package(project_filename, package)
|
130
|
-
}
|
131
|
-
end
|
132
|
-
end
|
133
|
-
Makit::DotNet.new_solution(self.name)
|
134
|
-
Makit::DotNet.sln_add_projects(self.name)
|
135
|
-
else
|
136
|
-
puts " no dotnet projects found".colorize(:yellow)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def build_dotnet_projects
|
141
|
-
self.dotnet_projects.each do |project|
|
142
|
-
project.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
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::V1::Project::create_from_file(filename)
|
21
|
+
self.name = other.name
|
22
|
+
self.git_remote_url = other.git_remote_url
|
23
|
+
self.dotnet_projects = other.dotnet_projects
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.create_from_file(filename)
|
27
|
+
extension = File.extname(filename)
|
28
|
+
case extension
|
29
|
+
when ".yml"
|
30
|
+
yaml = File.read(filename)
|
31
|
+
create_from_yaml(yaml)
|
32
|
+
when ".json"
|
33
|
+
json = File.read(filename)
|
34
|
+
create_from_json(json)
|
35
|
+
else
|
36
|
+
raise "unsupported file extension: #{extension}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.create_from_yaml(yaml)
|
41
|
+
json = JSON.pretty_generate(YAML.load(yaml))
|
42
|
+
project = Makit::V1::Project.decode_json(json)
|
43
|
+
project
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.create_from_json(json)
|
47
|
+
project = Makit::V1::Project.decode_json(json)
|
48
|
+
project
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_default_values
|
52
|
+
#self.language = "csharp"
|
53
|
+
#self.primary_artifact_type = "nuget"
|
54
|
+
if self.git_remote_url.nil? || self.git_remote_url.empty?
|
55
|
+
self.git_remote_url = `git remote get-url origin`.strip
|
56
|
+
end
|
57
|
+
if self.name.nil? || self.name.empty?
|
58
|
+
if (!self.git_remote_url.nil? && !self.git_remote_url.empty?)
|
59
|
+
self.name = get_name(File.basename(self.git_remote_url, ".git")) # get_capitalized_name(File.basename(self.git_remote_url, ".git"))
|
60
|
+
else
|
61
|
+
self.name = get_name(File.basename(Dir.getwd)) # get_capitalized_name(File.basename(Dir.getwd))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_name(name)
|
68
|
+
if !self.git_remote_url.nil? && !self.git_remote_url.empty?
|
69
|
+
is_dotnet = self.git_remote_url.include?("nuget")
|
70
|
+
if is_dotnet
|
71
|
+
get_capitalized_name(name)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
name.downcase
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_capitalized_name(name)
|
78
|
+
name.split(".").map(&:capitalize).join(".")
|
79
|
+
end
|
80
|
+
|
81
|
+
def save_as(filename)
|
82
|
+
extension = File.extname(filename)
|
83
|
+
case extension
|
84
|
+
when ".json"
|
85
|
+
File.write(filename, self.to_pretty_json)
|
86
|
+
when ".yml"
|
87
|
+
File.write(filename, self.to_yaml)
|
88
|
+
else
|
89
|
+
raise "unsupported file extension: #{extension}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def with_dotnet_project(template, name, output)
|
94
|
+
if !self.dotnet_projects.any? { |project| project.output == output }
|
95
|
+
project = Makit::V1::DotNetProject.new
|
96
|
+
project.template = template
|
97
|
+
project.name = name
|
98
|
+
project.output = output
|
99
|
+
self.dotnet_projects << project
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def setup
|
104
|
+
setup_dotnet_projects
|
105
|
+
end
|
106
|
+
|
107
|
+
def build
|
108
|
+
build_dotnet_projects
|
109
|
+
end
|
110
|
+
|
111
|
+
def setup_dotnet_projects
|
112
|
+
if self.dotnet_projects.any?
|
113
|
+
if (!File.exist?("#{self.name}.sln"))
|
114
|
+
puts " Creating solution file: " + "#{self.name}.sln".colorize(:green)
|
115
|
+
"dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln")
|
116
|
+
else
|
117
|
+
#puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow)
|
118
|
+
end
|
119
|
+
self.dotnet_projects.each do |project|
|
120
|
+
add_project = true
|
121
|
+
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
122
|
+
add_project = false
|
123
|
+
end
|
124
|
+
if (add_project)
|
125
|
+
Makit::DotNet.new_project(project.template, project.name, project.output)
|
126
|
+
# add any nuget packages to the project
|
127
|
+
project_filename = "#{project.output}/#{project.name}.csproj"
|
128
|
+
project.packages.each { |package|
|
129
|
+
Makit::DotNet::add_package(project_filename, package)
|
130
|
+
}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
Makit::DotNet.new_solution(self.name)
|
134
|
+
Makit::DotNet.sln_add_projects(self.name)
|
135
|
+
else
|
136
|
+
puts " no dotnet projects found".colorize(:yellow)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def build_dotnet_projects
|
141
|
+
self.dotnet_projects.each do |project|
|
142
|
+
if (project.os == "windows" && !Makit::Environment.is_windows?)
|
143
|
+
next
|
144
|
+
else
|
145
|
+
project.build_args.each do |build_arg|
|
146
|
+
project_path = File.join(project.output, "#{project.name}.csproj")
|
147
|
+
Makit::DotNet.build(project_path, build_arg.configuration, build_arg.output)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_dotnet_projects
|
154
|
+
self.dotnet_projects.each do |project|
|
155
|
+
"dotnet test #{project.output} --configuration Release".run
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end # class Project
|
159
|
+
end # module V1
|
160
|
+
end # module Makit
|
data/lib/makit/mp/string_mp.rb
CHANGED
@@ -1,107 +1,107 @@
|
|
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
|
-
# Read a value from a JSON file
|
39
|
-
# key is a string with the key to read, e.g. "AzureAd.Authority"
|
40
|
-
def get_json_value(key)
|
41
|
-
json = File.read(self)
|
42
|
-
data = JSON.parse(json)
|
43
|
-
|
44
|
-
# key delimiter is '.' so we can access nested keys
|
45
|
-
key.split(".").each do |k|
|
46
|
-
data = data[k]
|
47
|
-
end
|
48
|
-
data
|
49
|
-
end
|
50
|
-
|
51
|
-
alias_method :retrieve, :get_json_value
|
52
|
-
|
53
|
-
# Set a value in a JSON file
|
54
|
-
# key is a string with the key to set, e.g. "AzureAd.Authority"
|
55
|
-
def set_json_value(key, value)
|
56
|
-
file = File.read(self)
|
57
|
-
data = JSON.parse(file)
|
58
|
-
keys = key.split(".")
|
59
|
-
current = data
|
60
|
-
|
61
|
-
# Traverse and create any missing keys
|
62
|
-
keys[0..-2].each do |k|
|
63
|
-
current[k] ||= {} # Create a new hash if the key doesn't exist
|
64
|
-
current = current[k]
|
65
|
-
end
|
66
|
-
|
67
|
-
# Set the value for the final key
|
68
|
-
current[keys[-1]] = value
|
69
|
-
|
70
|
-
# Write the JSON back to the file
|
71
|
-
File.write(self, JSON.pretty_generate(data))
|
72
|
-
end
|
73
|
-
|
74
|
-
# Alias for set_json_value
|
75
|
-
alias_method :assign, :set_json_value
|
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
|
-
|
83
|
-
def to_lines(max_length = 80, indent_length = 5)
|
84
|
-
if (self.length <= max_length)
|
85
|
-
return self
|
86
|
-
else
|
87
|
-
indent = " " * indent_length
|
88
|
-
words = self.split(" ")
|
89
|
-
lines = []
|
90
|
-
line = ""
|
91
|
-
words.each do |word|
|
92
|
-
if ((line + word).length > max_length)
|
93
|
-
lines << line
|
94
|
-
line = indent + word
|
95
|
-
else
|
96
|
-
if (line.length == 0)
|
97
|
-
line = word
|
98
|
-
else
|
99
|
-
line += " " + word
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
lines << line
|
104
|
-
return lines.join("\n")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
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
|
+
# Read a value from a JSON file
|
39
|
+
# key is a string with the key to read, e.g. "AzureAd.Authority"
|
40
|
+
def get_json_value(key)
|
41
|
+
json = File.read(self)
|
42
|
+
data = JSON.parse(json)
|
43
|
+
|
44
|
+
# key delimiter is '.' so we can access nested keys
|
45
|
+
key.split(".").each do |k|
|
46
|
+
data = data[k]
|
47
|
+
end
|
48
|
+
data
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :retrieve, :get_json_value
|
52
|
+
|
53
|
+
# Set a value in a JSON file
|
54
|
+
# key is a string with the key to set, e.g. "AzureAd.Authority"
|
55
|
+
def set_json_value(key, value)
|
56
|
+
file = File.read(self)
|
57
|
+
data = JSON.parse(file)
|
58
|
+
keys = key.split(".")
|
59
|
+
current = data
|
60
|
+
|
61
|
+
# Traverse and create any missing keys
|
62
|
+
keys[0..-2].each do |k|
|
63
|
+
current[k] ||= {} # Create a new hash if the key doesn't exist
|
64
|
+
current = current[k]
|
65
|
+
end
|
66
|
+
|
67
|
+
# Set the value for the final key
|
68
|
+
current[keys[-1]] = value
|
69
|
+
|
70
|
+
# Write the JSON back to the file
|
71
|
+
File.write(self, JSON.pretty_generate(data))
|
72
|
+
end
|
73
|
+
|
74
|
+
# Alias for set_json_value
|
75
|
+
alias_method :assign, :set_json_value
|
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
|
+
|
83
|
+
def to_lines(max_length = 80, indent_length = 5)
|
84
|
+
if (self.length <= max_length)
|
85
|
+
return self
|
86
|
+
else
|
87
|
+
indent = " " * indent_length
|
88
|
+
words = self.split(" ")
|
89
|
+
lines = []
|
90
|
+
line = ""
|
91
|
+
words.each do |word|
|
92
|
+
if ((line + word).length > max_length)
|
93
|
+
lines << line
|
94
|
+
line = indent + word
|
95
|
+
else
|
96
|
+
if (line.length == 0)
|
97
|
+
line = word
|
98
|
+
else
|
99
|
+
line += " " + word
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
lines << line
|
104
|
+
return lines.join("\n")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/makit/nuget.rb
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
require "tmpdir"
|
2
|
-
# This module provides classes for the Makit gem.
|
3
|
-
module Makit
|
4
|
-
# This class provide methods for working with the Nuget package cache
|
5
|
-
#
|
6
|
-
# Example:
|
7
|
-
#
|
8
|
-
# Makit::Directory.cache("Google.Protobuf", "3.27.2")
|
9
|
-
#
|
10
|
-
# dotnet nuget locals all --list
|
11
|
-
# dotnet nuget locals all --clear
|
12
|
-
#
|
13
|
-
class NuGet
|
14
|
-
def self.get_cache_dir(package, version)
|
15
|
-
File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package, version)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.cache(package, version)
|
19
|
-
# if the package is already cached, there is nothing to do
|
20
|
-
if (!Dir.exist?(get_cache_dir(package, version)))
|
21
|
-
Dir.mktmpdir do |dir|
|
22
|
-
# Use the temp directory here
|
23
|
-
Dir.chdir(dir) do
|
24
|
-
system("dotnet new classlib -n ClassLib")
|
25
|
-
Dir.chdir("ClassLib") do
|
26
|
-
|
27
|
-
# display a list of directories in the current directory
|
28
|
-
puts Dir.entries(Dir.pwd)
|
29
|
-
# display a list of files in the current directory
|
30
|
-
puts Dir.entries(Dir.pwd)
|
31
|
-
puts "dotnet add ClassLib.csproj package #{package} --version #{version}"
|
32
|
-
system("dotnet add ClassLib.csproj package #{package} --version #{version}")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
# The directory and its contents will be removed automatically after the block
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.clear_cache(package, version)
|
41
|
-
if (Dir.exist?(get_cache_dir(package, version)))
|
42
|
-
FileUtils.rm_rf(get_cache_dir(package, version))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# get the latest version of the package
|
47
|
-
def self.get_latest_version(package)
|
48
|
-
dir = File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package)
|
49
|
-
if (Dir.exist?(dir))
|
50
|
-
versions = Dir.entries(dir).select { |entry| File.directory?(File.join(dir, entry)) && !(entry == "." || entry == "..") }
|
51
|
-
highest_version = Makit::Version::get_highest_version(versions)
|
52
|
-
return highest_version
|
53
|
-
end
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
1
|
+
require "tmpdir"
|
2
|
+
# This module provides classes for the Makit gem.
|
3
|
+
module Makit
|
4
|
+
# This class provide methods for working with the Nuget package cache
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# Makit::Directory.cache("Google.Protobuf", "3.27.2")
|
9
|
+
#
|
10
|
+
# dotnet nuget locals all --list
|
11
|
+
# dotnet nuget locals all --clear
|
12
|
+
#
|
13
|
+
class NuGet
|
14
|
+
def self.get_cache_dir(package, version)
|
15
|
+
File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package, version)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.cache(package, version)
|
19
|
+
# if the package is already cached, there is nothing to do
|
20
|
+
if (!Dir.exist?(get_cache_dir(package, version)))
|
21
|
+
Dir.mktmpdir do |dir|
|
22
|
+
# Use the temp directory here
|
23
|
+
Dir.chdir(dir) do
|
24
|
+
system("dotnet new classlib -n ClassLib")
|
25
|
+
Dir.chdir("ClassLib") do
|
26
|
+
|
27
|
+
# display a list of directories in the current directory
|
28
|
+
puts Dir.entries(Dir.pwd)
|
29
|
+
# display a list of files in the current directory
|
30
|
+
puts Dir.entries(Dir.pwd)
|
31
|
+
puts "dotnet add ClassLib.csproj package #{package} --version #{version}"
|
32
|
+
system("dotnet add ClassLib.csproj package #{package} --version #{version}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
# The directory and its contents will be removed automatically after the block
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.clear_cache(package, version)
|
41
|
+
if (Dir.exist?(get_cache_dir(package, version)))
|
42
|
+
FileUtils.rm_rf(get_cache_dir(package, version))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# get the latest version of the package
|
47
|
+
def self.get_latest_version(package)
|
48
|
+
dir = File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package)
|
49
|
+
if (Dir.exist?(dir))
|
50
|
+
versions = Dir.entries(dir).select { |entry| File.directory?(File.join(dir, entry)) && !(entry == "." || entry == "..") }
|
51
|
+
highest_version = Makit::Version::get_highest_version(versions)
|
52
|
+
return highest_version
|
53
|
+
end
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|