makit 0.0.35 → 0.0.36
Sign up to get free protection for your applications and to get access to all the features.
- 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 +391 -353
- 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 +140 -140
- data/lib/makit/directory.rb +184 -184
- data/lib/makit/dotnet.rb +156 -156
- data/lib/makit/environment.rb +127 -127
- data/lib/makit/fileinfo.rb +16 -16
- data/lib/makit/files.rb +47 -47
- data/lib/makit/git.rb +86 -86
- data/lib/makit/gitlab_runner.rb +60 -60
- data/lib/makit/humanize.rb +112 -112
- data/lib/makit/indexer.rb +56 -0
- 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 +122 -122
- data/lib/makit/nuget.rb +57 -57
- data/lib/makit/protoc.rb +104 -104
- data/lib/makit/serializer.rb +115 -115
- data/lib/makit/show.rb +76 -77
- data/lib/makit/storage.rb +131 -131
- data/lib/makit/symbols.rb +149 -149
- data/lib/makit/tasks.rb +60 -60
- 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 +267 -267
- metadata +4 -5
- data/lib/generated/makit/v1/makit.v1_pb.rb +0 -34
- data/lib/generated/makit/v1/web/link_pb.rb +0 -20
data/lib/makit/dotnet.rb
CHANGED
@@ -1,156 +1,156 @@
|
|
1
|
-
module Makit
|
2
|
-
class DotNet
|
3
|
-
def self.is_installed?
|
4
|
-
File.exist?(Makit::Environment.which("dotnet"))
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.version
|
8
|
-
`dotnet --version`
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.new_project(template, name, output)
|
12
|
-
if Dir.exist? output
|
13
|
-
#puts " #{output}".colorize(:green) + " exists.".colorize(:grey)
|
14
|
-
#puts "Directory #{output} already exists".colorize(:yellow)
|
15
|
-
else
|
16
|
-
"dotnet new #{template} --name #{name} --output #{output}".run
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.find_project(project_hint)
|
21
|
-
matches = []
|
22
|
-
Dir.glob("**/*.csproj").each do |project_path|
|
23
|
-
#project_name = File.basename(project_path, ".csproj")
|
24
|
-
if project_path.include?(project_hint)
|
25
|
-
matches << project_path
|
26
|
-
end
|
27
|
-
end
|
28
|
-
if matches.length == 1
|
29
|
-
return matches.first
|
30
|
-
elsif matches.length > 1
|
31
|
-
raise "Multiple projects found matching #{project_hint}".colorize(:red)
|
32
|
-
end
|
33
|
-
raise "No project found matching #{project_hint}".colorize(:red)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.add_package(project_path, package_name)
|
37
|
-
if(!File.exist?(project_path))
|
38
|
-
actual_project_path = Makit::DotNet::find_project(project_path)
|
39
|
-
if(!File.exist?(actual_project_path))
|
40
|
-
raise "Project #{project_path} does not exist".colorize(:red)
|
41
|
-
else
|
42
|
-
project_path = actual_project_path
|
43
|
-
end
|
44
|
-
end
|
45
|
-
project_content = File.read(project_path)
|
46
|
-
if (!project_content.include?("\"#{package_name}\""))
|
47
|
-
"dotnet add #{project_path} package #{package_name}".run
|
48
|
-
else
|
49
|
-
#puts " package ".colorize(:grey) + "#{package_name}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.add_packages(project_path, packages)
|
54
|
-
packages.each do |package|
|
55
|
-
add_package(project_path, package)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.add_reference(project_path, reference_path)
|
60
|
-
if(!File.exist?(project_path))
|
61
|
-
actual_project_path = Makit::DotNet::find_project(project_path)
|
62
|
-
if(!File.exist?(actual_project_path))
|
63
|
-
raise "Project #{project_path} does not exist".colorize(:red)
|
64
|
-
else
|
65
|
-
project_path = actual_project_path
|
66
|
-
end
|
67
|
-
end
|
68
|
-
if(!File.exist?(reference_path))
|
69
|
-
actual_reference_path = Makit::DotNet::find_project(reference_path)
|
70
|
-
if(!File.exist?(actual_reference_path))
|
71
|
-
raise "Project #{reference_path} does not exist".colorize(:red)
|
72
|
-
else
|
73
|
-
reference_path = actual_reference_path
|
74
|
-
end
|
75
|
-
end
|
76
|
-
project_content = File.read(project_path)
|
77
|
-
if (project_content.include?(File.basename(reference_path)))
|
78
|
-
#puts " reference ".colorize(:grey) + "#{reference_path}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
|
79
|
-
else
|
80
|
-
"dotnet add #{project_path} reference #{reference_path}".run
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.add_references(project_path, references)
|
85
|
-
references.each do |reference|
|
86
|
-
add_reference(project_path, reference)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.new_solution(name)
|
91
|
-
if File.exist? "#{name}.sln"
|
92
|
-
#puts "Solution #{name}.sln already exists".colorize(:yellow)
|
93
|
-
#puts " #{name}.sln".colorize(:green) + " exists".colorize(:grey)
|
94
|
-
else
|
95
|
-
"dotnet new sln --name #{name}".run
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.build(project_path, configuration = "Release", output = "artifacts")
|
100
|
-
project_dir = File.dirname(project_path)
|
101
|
-
newest_file = Makit::Directory::get_newest_file(project_dir)
|
102
|
-
command_request = Makit::RUNNER::parse_command_request("dotnet build #{project_path} --configuration #{configuration} --output #{output}")
|
103
|
-
if newest_file.nil?
|
104
|
-
newest_file_date = Time.now
|
105
|
-
RUNNER.cache_run(command_request, newest_file_date)
|
106
|
-
else
|
107
|
-
newest_file_date = File.mtime(newest_file)
|
108
|
-
RUNNER.cache_run(command_request, newest_file_date)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.publish(project_path, configuration = "Release", output = "artifacts")
|
113
|
-
project_dir = File.dirname(project_path)
|
114
|
-
newest_file = Makit::Directory::get_newest_file(project_dir)
|
115
|
-
command_request = Makit::RUNNER::parse_command_request("dotnet publish #{project_path} --configuration #{configuration} --output #{output}")
|
116
|
-
if newest_file.nil?
|
117
|
-
newest_file_date = Time.now
|
118
|
-
RUNNER.cache_run(command_request, newest_file_date)
|
119
|
-
else
|
120
|
-
newest_file_date = File.mtime(newest_file)
|
121
|
-
RUNNER.cache_run(command_request, newest_file_date)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.test(project_path, configuration = "Release", output = "artifacts")
|
126
|
-
project_dir = File.dirname(project_path)
|
127
|
-
newest_file = Makit::Directory::get_newest_file(project_dir)
|
128
|
-
command_request = Makit::RUNNER::parse_command_request("dotnet test #{project_path} --configuration #{configuration} --output #{output}")
|
129
|
-
if newest_file.nil?
|
130
|
-
newest_file_date = Time.now
|
131
|
-
RUNNER.cache_run(command_request, newest_file_date)
|
132
|
-
else
|
133
|
-
newest_file_date = File.mtime(newest_file)
|
134
|
-
RUNNER.cache_run(command_request, newest_file_date)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def self.sln_add_projects(sln_name)
|
139
|
-
if !File.exist? "#{sln_name}.sln"
|
140
|
-
raise "Solution #{sln_name}.sln does not exist"
|
141
|
-
else
|
142
|
-
sln_path = "#{sln_name}.sln"
|
143
|
-
sln_content = File.read(sln_path)
|
144
|
-
Dir.glob("**/*.csproj").each do |project_path|
|
145
|
-
project_name = File.basename(project_path, ".csproj")
|
146
|
-
if (sln_content.include?("\"#{project_name}\""))
|
147
|
-
#puts " #{project_name}".colorize(:green) + " is in ".colorize(:grey) + "#{sln_path}".colorize(:green)
|
148
|
-
#puts "Project #{project_name} already exists in #{sln_path}".colorize(:yellow)
|
149
|
-
else
|
150
|
-
"dotnet sln #{sln_path} add #{project_path}".run
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end # class DotNet
|
156
|
-
end # module Makit
|
1
|
+
module Makit
|
2
|
+
class DotNet
|
3
|
+
def self.is_installed?
|
4
|
+
File.exist?(Makit::Environment.which("dotnet"))
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.version
|
8
|
+
`dotnet --version`
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.new_project(template, name, output,args = "")
|
12
|
+
if Dir.exist? output
|
13
|
+
#puts " #{output}".colorize(:green) + " exists.".colorize(:grey)
|
14
|
+
#puts "Directory #{output} already exists".colorize(:yellow)
|
15
|
+
else
|
16
|
+
"dotnet new #{template} --name #{name} --output #{output} #{args}".run
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_project(project_hint)
|
21
|
+
matches = []
|
22
|
+
Dir.glob("**/*.csproj").each do |project_path|
|
23
|
+
#project_name = File.basename(project_path, ".csproj")
|
24
|
+
if project_path.include?(project_hint)
|
25
|
+
matches << project_path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
if matches.length == 1
|
29
|
+
return matches.first
|
30
|
+
elsif matches.length > 1
|
31
|
+
raise "Multiple projects found matching #{project_hint}".colorize(:red)
|
32
|
+
end
|
33
|
+
raise "No project found matching #{project_hint}".colorize(:red)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.add_package(project_path, package_name)
|
37
|
+
if (!File.exist?(project_path))
|
38
|
+
actual_project_path = Makit::DotNet::find_project(project_path)
|
39
|
+
if (!File.exist?(actual_project_path))
|
40
|
+
raise "Project #{project_path} does not exist".colorize(:red)
|
41
|
+
else
|
42
|
+
project_path = actual_project_path
|
43
|
+
end
|
44
|
+
end
|
45
|
+
project_content = File.read(project_path)
|
46
|
+
if (!project_content.include?("\"#{package_name}\""))
|
47
|
+
"dotnet add #{project_path} package #{package_name}".run
|
48
|
+
else
|
49
|
+
#puts " package ".colorize(:grey) + "#{package_name}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.add_packages(project_path, packages)
|
54
|
+
packages.each do |package|
|
55
|
+
add_package(project_path, package)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.add_reference(project_path, reference_path)
|
60
|
+
if (!File.exist?(project_path))
|
61
|
+
actual_project_path = Makit::DotNet::find_project(project_path)
|
62
|
+
if (!File.exist?(actual_project_path))
|
63
|
+
raise "Project #{project_path} does not exist".colorize(:red)
|
64
|
+
else
|
65
|
+
project_path = actual_project_path
|
66
|
+
end
|
67
|
+
end
|
68
|
+
if (!File.exist?(reference_path))
|
69
|
+
actual_reference_path = Makit::DotNet::find_project(reference_path)
|
70
|
+
if (!File.exist?(actual_reference_path))
|
71
|
+
raise "Project #{reference_path} does not exist".colorize(:red)
|
72
|
+
else
|
73
|
+
reference_path = actual_reference_path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
project_content = File.read(project_path)
|
77
|
+
if (project_content.include?(File.basename(reference_path)))
|
78
|
+
#puts " reference ".colorize(:grey) + "#{reference_path}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow)
|
79
|
+
else
|
80
|
+
"dotnet add #{project_path} reference #{reference_path}".run
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.add_references(project_path, references)
|
85
|
+
references.each do |reference|
|
86
|
+
add_reference(project_path, reference)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.new_solution(name)
|
91
|
+
if File.exist? "#{name}.sln"
|
92
|
+
#puts "Solution #{name}.sln already exists".colorize(:yellow)
|
93
|
+
#puts " #{name}.sln".colorize(:green) + " exists".colorize(:grey)
|
94
|
+
else
|
95
|
+
"dotnet new sln --name #{name}".run
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.build(project_path, configuration = "Release", output = "artifacts")
|
100
|
+
project_dir = File.dirname(project_path)
|
101
|
+
newest_file = Makit::Directory::get_newest_file(project_dir)
|
102
|
+
command_request = Makit::RUNNER::parse_command_request("dotnet build #{project_path} --configuration #{configuration} --output #{output}")
|
103
|
+
if newest_file.nil?
|
104
|
+
newest_file_date = Time.now
|
105
|
+
RUNNER.cache_run(command_request, newest_file_date)
|
106
|
+
else
|
107
|
+
newest_file_date = File.mtime(newest_file)
|
108
|
+
RUNNER.cache_run(command_request, newest_file_date)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.publish(project_path, configuration = "Release", output = "artifacts")
|
113
|
+
project_dir = File.dirname(project_path)
|
114
|
+
newest_file = Makit::Directory::get_newest_file(project_dir)
|
115
|
+
command_request = Makit::RUNNER::parse_command_request("dotnet publish #{project_path} --configuration #{configuration} --output #{output}")
|
116
|
+
if newest_file.nil?
|
117
|
+
newest_file_date = Time.now
|
118
|
+
RUNNER.cache_run(command_request, newest_file_date)
|
119
|
+
else
|
120
|
+
newest_file_date = File.mtime(newest_file)
|
121
|
+
RUNNER.cache_run(command_request, newest_file_date)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.test(project_path, configuration = "Release", output = "artifacts")
|
126
|
+
project_dir = File.dirname(project_path)
|
127
|
+
newest_file = Makit::Directory::get_newest_file(project_dir)
|
128
|
+
command_request = Makit::RUNNER::parse_command_request("dotnet test #{project_path} --configuration #{configuration} --output #{output}")
|
129
|
+
if newest_file.nil?
|
130
|
+
newest_file_date = Time.now
|
131
|
+
RUNNER.cache_run(command_request, newest_file_date)
|
132
|
+
else
|
133
|
+
newest_file_date = File.mtime(newest_file)
|
134
|
+
RUNNER.cache_run(command_request, newest_file_date)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.sln_add_projects(sln_name)
|
139
|
+
if !File.exist? "#{sln_name}.sln"
|
140
|
+
raise "Solution #{sln_name}.sln does not exist"
|
141
|
+
else
|
142
|
+
sln_path = "#{sln_name}.sln"
|
143
|
+
sln_content = File.read(sln_path)
|
144
|
+
Dir.glob("**/*.csproj").each do |project_path|
|
145
|
+
project_name = File.basename(project_path, ".csproj")
|
146
|
+
if (sln_content.include?("\"#{project_name}\""))
|
147
|
+
#puts " #{project_name}".colorize(:green) + " is in ".colorize(:grey) + "#{sln_path}".colorize(:green)
|
148
|
+
#puts "Project #{project_name} already exists in #{sln_path}".colorize(:yellow)
|
149
|
+
else
|
150
|
+
"dotnet sln #{sln_path} add #{project_path}".run
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end # class DotNet
|
156
|
+
end # module Makit
|
data/lib/makit/environment.rb
CHANGED
@@ -1,127 +1,127 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "sorted_set"
|
4
|
-
require_relative "directory"
|
5
|
-
# This module provides classes for the Makit gem.
|
6
|
-
module Makit
|
7
|
-
# This class provide methods for working with the system Environment.
|
8
|
-
#
|
9
|
-
class Environment
|
10
|
-
def self.which(name)
|
11
|
-
return name if File.exist?(name)
|
12
|
-
|
13
|
-
["", ".exe", ".bat", ".cmd"].each do |ext|
|
14
|
-
aname = name + ext
|
15
|
-
return aname if File.exist?(aname)
|
16
|
-
|
17
|
-
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
18
|
-
apath = "#{path.gsub("\\", "/")}/#{aname}".gsub("//", "/")
|
19
|
-
return apath if File.exist?(apath)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
""
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.constants_hash
|
26
|
-
constants = {}
|
27
|
-
# collect all constants that are all uppercase
|
28
|
-
Object.constants.each { |c| constants[c] = Object.const_get(c) if c == c.upcase } # puts "#{c} = #{Object.const_get(c)}" }
|
29
|
-
#Object.constants.each { |c| constants[c] = Object.const_get(c)}# puts "#{c} = #{Object.const_get(c)}" }
|
30
|
-
constants
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.rake_file_name
|
34
|
-
caller_locations.each do |location|
|
35
|
-
return location.absolute_path if location.absolute_path&.end_with?("Rakefile")
|
36
|
-
end
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.gem_data_directory
|
41
|
-
gem_data_directory = File.join(Dir.home, ".makit")
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.project_root_directory
|
45
|
-
if !Makit::Environment.rake_file_name.nil?
|
46
|
-
File.dirname(Makit::Environment.rake_file_name)
|
47
|
-
else
|
48
|
-
Makit::Directory.find_directory_with_pattern(File.dirname(__FILE__), "Rakefile")
|
49
|
-
# lass Directory
|
50
|
-
# def self.find_directory_with_pattern(starting_directory, pattern)
|
51
|
-
# nil
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.get_relative_directory(url)
|
56
|
-
url = url.gsub("https://", "").gsub("http://", "")
|
57
|
-
url = url.gsub("gitlab.com", "gitlab")
|
58
|
-
url
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.get_code_root
|
62
|
-
# user home directory + "code"
|
63
|
-
code_root = File.join(Dir.home, "code")
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.get_work_directory(url)
|
67
|
-
raise "invalid url" if !url.include? "https://"
|
68
|
-
url = url.gsub("https://", "").gsub("http://", "")
|
69
|
-
#url = url.gsub("gitlab.com","gitlab")
|
70
|
-
url
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.is_windows?
|
74
|
-
RbConfig::CONFIG["host_os"] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.is_mac?
|
78
|
-
RbConfig::CONFIG["host_os"] =~ /darwin/
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.get_os
|
82
|
-
case RbConfig::CONFIG["host_os"]
|
83
|
-
when /linux/
|
84
|
-
"Linux"
|
85
|
-
when /darwin/
|
86
|
-
"macOS"
|
87
|
-
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
88
|
-
"Windows"
|
89
|
-
else
|
90
|
-
"Unknown"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.get_runtime_identifier()
|
95
|
-
os = RbConfig::CONFIG["host_os"]
|
96
|
-
cpu = RbConfig::CONFIG["host_cpu"]
|
97
|
-
|
98
|
-
case os
|
99
|
-
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
100
|
-
os_rid = "win"
|
101
|
-
when /darwin|mac os/
|
102
|
-
os_rid = "osx"
|
103
|
-
when /linux/
|
104
|
-
os_rid = "linux"
|
105
|
-
when /solaris|bsd/
|
106
|
-
os_rid = "unix"
|
107
|
-
else
|
108
|
-
raise "Unknown operating system: host_os=#{os}"
|
109
|
-
end
|
110
|
-
|
111
|
-
case cpu
|
112
|
-
when /x86_64|amd64|x64/
|
113
|
-
arch_rid = "x64"
|
114
|
-
when /i686|i386/
|
115
|
-
arch_rid = "x86"
|
116
|
-
#when /arm/
|
117
|
-
# arch_rid = "arm"
|
118
|
-
when /aarch64|arm64/
|
119
|
-
arch_rid = "arm64"
|
120
|
-
else
|
121
|
-
raise "Unknown architecture: host_cpu=#{cpu}"
|
122
|
-
end
|
123
|
-
|
124
|
-
"#{os_rid}-#{arch_rid}"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sorted_set"
|
4
|
+
require_relative "directory"
|
5
|
+
# This module provides classes for the Makit gem.
|
6
|
+
module Makit
|
7
|
+
# This class provide methods for working with the system Environment.
|
8
|
+
#
|
9
|
+
class Environment
|
10
|
+
def self.which(name)
|
11
|
+
return name if File.exist?(name)
|
12
|
+
|
13
|
+
["", ".exe", ".bat", ".cmd"].each do |ext|
|
14
|
+
aname = name + ext
|
15
|
+
return aname if File.exist?(aname)
|
16
|
+
|
17
|
+
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
18
|
+
apath = "#{path.gsub("\\", "/")}/#{aname}".gsub("//", "/")
|
19
|
+
return apath if File.exist?(apath)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
""
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.constants_hash
|
26
|
+
constants = {}
|
27
|
+
# collect all constants that are all uppercase
|
28
|
+
Object.constants.each { |c| constants[c] = Object.const_get(c) if c == c.upcase } # puts "#{c} = #{Object.const_get(c)}" }
|
29
|
+
#Object.constants.each { |c| constants[c] = Object.const_get(c)}# puts "#{c} = #{Object.const_get(c)}" }
|
30
|
+
constants
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.rake_file_name
|
34
|
+
caller_locations.each do |location|
|
35
|
+
return location.absolute_path if location.absolute_path&.end_with?("Rakefile")
|
36
|
+
end
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.gem_data_directory
|
41
|
+
gem_data_directory = File.join(Dir.home, ".makit")
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.project_root_directory
|
45
|
+
if !Makit::Environment.rake_file_name.nil?
|
46
|
+
File.dirname(Makit::Environment.rake_file_name)
|
47
|
+
else
|
48
|
+
Makit::Directory.find_directory_with_pattern(File.dirname(__FILE__), "Rakefile")
|
49
|
+
# lass Directory
|
50
|
+
# def self.find_directory_with_pattern(starting_directory, pattern)
|
51
|
+
# nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get_relative_directory(url)
|
56
|
+
url = url.gsub("https://", "").gsub("http://", "")
|
57
|
+
url = url.gsub("gitlab.com", "gitlab")
|
58
|
+
url
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.get_code_root
|
62
|
+
# user home directory + "code"
|
63
|
+
code_root = File.join(Dir.home, "code")
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.get_work_directory(url)
|
67
|
+
raise "invalid url" if !url.include? "https://"
|
68
|
+
url = url.gsub("https://", "").gsub("http://", "")
|
69
|
+
#url = url.gsub("gitlab.com","gitlab")
|
70
|
+
url
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.is_windows?
|
74
|
+
RbConfig::CONFIG["host_os"] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.is_mac?
|
78
|
+
RbConfig::CONFIG["host_os"] =~ /darwin/
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.get_os
|
82
|
+
case RbConfig::CONFIG["host_os"]
|
83
|
+
when /linux/
|
84
|
+
"Linux"
|
85
|
+
when /darwin/
|
86
|
+
"macOS"
|
87
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
88
|
+
"Windows"
|
89
|
+
else
|
90
|
+
"Unknown"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.get_runtime_identifier()
|
95
|
+
os = RbConfig::CONFIG["host_os"]
|
96
|
+
cpu = RbConfig::CONFIG["host_cpu"]
|
97
|
+
|
98
|
+
case os
|
99
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
100
|
+
os_rid = "win"
|
101
|
+
when /darwin|mac os/
|
102
|
+
os_rid = "osx"
|
103
|
+
when /linux/
|
104
|
+
os_rid = "linux"
|
105
|
+
when /solaris|bsd/
|
106
|
+
os_rid = "unix"
|
107
|
+
else
|
108
|
+
raise "Unknown operating system: host_os=#{os}"
|
109
|
+
end
|
110
|
+
|
111
|
+
case cpu
|
112
|
+
when /x86_64|amd64|x64/
|
113
|
+
arch_rid = "x64"
|
114
|
+
when /i686|i386/
|
115
|
+
arch_rid = "x86"
|
116
|
+
#when /arm/
|
117
|
+
# arch_rid = "arm"
|
118
|
+
when /aarch64|arm64/
|
119
|
+
arch_rid = "arm64"
|
120
|
+
else
|
121
|
+
raise "Unknown architecture: host_cpu=#{cpu}"
|
122
|
+
end
|
123
|
+
|
124
|
+
"#{os_rid}-#{arch_rid}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/makit/fileinfo.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This module provides classes for the Makit gem.
|
4
|
-
module Makit
|
5
|
-
# This class provide methods for working with the system Environment.
|
6
|
-
#
|
7
|
-
class FileInfo
|
8
|
-
attr_accessor :name, :mtime, :size
|
9
|
-
|
10
|
-
def initialize(name:, mtime:, size:)
|
11
|
-
@name = name
|
12
|
-
@mtime = mtime
|
13
|
-
@size = size
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module provides classes for the Makit gem.
|
4
|
+
module Makit
|
5
|
+
# This class provide methods for working with the system Environment.
|
6
|
+
#
|
7
|
+
class FileInfo
|
8
|
+
attr_accessor :name, :mtime, :size
|
9
|
+
|
10
|
+
def initialize(name:, mtime:, size:)
|
11
|
+
@name = name
|
12
|
+
@mtime = mtime
|
13
|
+
@size = size
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|