raykit 0.0.501 → 0.0.503

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +25 -20
  4. data/bin/raykit +6 -6
  5. data/lib/raykit/auto_setup.rb +69 -69
  6. data/lib/raykit/command.rb +373 -373
  7. data/lib/raykit/conan/buildinfo.rb +69 -69
  8. data/lib/raykit/conanpackage.rb +49 -49
  9. data/lib/raykit/configuration.rb +53 -50
  10. data/lib/raykit/console.rb +314 -308
  11. data/lib/raykit/default_content.rb +227 -227
  12. data/lib/raykit/dir.rb +49 -49
  13. data/lib/raykit/dotnet.rb +174 -174
  14. data/lib/raykit/environment.rb +114 -114
  15. data/lib/raykit/filesystem.rb +34 -34
  16. data/lib/raykit/git/commit.rb +16 -16
  17. data/lib/raykit/git/directory.rb +216 -216
  18. data/lib/raykit/git/files.rb +46 -46
  19. data/lib/raykit/git/repositories.rb +89 -89
  20. data/lib/raykit/git/repository.rb +376 -376
  21. data/lib/raykit/installer.rb +17 -17
  22. data/lib/raykit/log.rb +80 -80
  23. data/lib/raykit/logevent.rb +49 -49
  24. data/lib/raykit/logging.rb +57 -57
  25. data/lib/raykit/markdown.rb +21 -21
  26. data/lib/raykit/msbuild.rb +54 -54
  27. data/lib/raykit/nugetpackage.rb +54 -54
  28. data/lib/raykit/nunit.rb +13 -13
  29. data/lib/raykit/project.rb +343 -343
  30. data/lib/raykit/rake.rb +39 -39
  31. data/lib/raykit/runner.rb +42 -42
  32. data/lib/raykit/secrets.rb +38 -38
  33. data/lib/raykit/sourceImport.rb +76 -76
  34. data/lib/raykit/sourceImports.rb +43 -43
  35. data/lib/raykit/string.rb +18 -18
  36. data/lib/raykit/symbols.rb +16 -16
  37. data/lib/raykit/tasks.rb +99 -99
  38. data/lib/raykit/text.rb +32 -32
  39. data/lib/raykit/timer.rb +31 -31
  40. data/lib/raykit/version.rb +103 -103
  41. data/lib/raykit/vstest.rb +24 -24
  42. data/lib/raykit/wt.rb +28 -28
  43. data/lib/raykit/zip.rb +73 -73
  44. data/lib/raykit.rb +125 -125
  45. metadata +1 -1
data/lib/raykit/dotnet.rb CHANGED
@@ -1,174 +1,174 @@
1
- # frozen_string_literal: true
2
-
3
- module Raykit
4
- class DotNet
5
- def self.init_new(name, template)
6
- if (!File.exist?("#{name}/#{name}.csproj"))
7
- puts " #{name}.csproj not found, creating..."
8
- run("dotnet new #{template} --name #{name} --output #{name} --language C# ")
9
- else
10
- puts " #{name}.csproj already exists"
11
- end
12
- end
13
-
14
- # initialize an F# library
15
- def self.initialize_fsharp_lib(name)
16
- puts `dotnet new sln --name #{name}` unless File.exist?("#{name}.sln")
17
- unless Dir.exist?(name)
18
- FileUtils.mkdir(name)
19
- Dir.chdir(name) do
20
- puts `dotnet new classlib -lang F#`
21
- end
22
- # puts `dotnet new sln`
23
- puts `dotnet sln #{name}.sln add #{name}/#{name}.fsproj`
24
-
25
- FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
26
- Dir.chdir("#{name}.Test") do
27
- puts `dotnet new nunit -lang F#`
28
- puts `dotnet add reference ../#{name}/#{name}.fsproj`
29
- end
30
-
31
- puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.fsproj`
32
- end
33
- end
34
-
35
- # initialize a C# console application
36
- def self.initialize_csharp_console(name)
37
- unless Dir.exist?(name)
38
- FileUtils.mkdir(name)
39
- Dir.chdir(name) do
40
- puts `dotnet new console -lang C#`
41
- end
42
- puts `dotnet new sln`
43
- puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
44
-
45
- FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
46
- Dir.chdir("#{name}.Test") do
47
- puts `dotnet new nunit -lang C#`
48
- puts `dotnet add reference ../#{name}/#{name}.csproj`
49
- end
50
-
51
- puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.csproj`
52
- end
53
- end
54
-
55
- # initialize a C# wpf application
56
- def self.initialize_csharp_wpf_application(name)
57
- puts `dotnet new sln --name #{name}`
58
- unless Dir.exist?(name)
59
- FileUtils.mkdir(name)
60
- Dir.chdir(name) do
61
- puts `dotnet new wpf -lang C#`
62
- end
63
- end
64
- puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
65
- initialize_csharp_lib("#{name}.Library")
66
- puts `dotnet sln #{name}.sln add #{name}.Library/#{name}.Library.csproj`
67
- puts `dotnet sln #{name}.sln add #{name}.Library.Test/#{name}.Library.Test.csproj`
68
- end
69
-
70
- # initialize a C# worker service
71
- def self.initialize_csharp_service(name)
72
- unless Dir.exist?(name)
73
- FileUtils.mkdir(name)
74
- Dir.chdir(name) do
75
- puts `dotnet new worker -lang C#`
76
- end
77
- puts `dotnet new sln`
78
- puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
79
- end
80
- end
81
-
82
- def self.initialize_csharp_project(template_name, dir, name, folders)
83
- puts " creating #{dir}/#{name}/#{name}.csproj" unless File.exist?("#{dir}/#{name}/#{name}.csproj")
84
- PROJECT.run("dotnet new #{template_name} -lang C# --name #{name} --output #{dir}/#{name}") unless File.exist?("#{dir}/#{name}/#{name}.csproj")
85
- folders.each do |folder|
86
- FileUtils.mkdir_p("#{dir}/#{name}/#{folder}") unless Dir.exist?("#{dir}/#{name}/#{folder}")
87
- end
88
- end
89
-
90
- # initialize a C# library
91
- def self.initialize_csharp_lib(name)
92
- # create the library
93
- puts " creating src/#{name}/#{name}.csproj" unless File.exist?("src/#{name}/#{name}.csproj")
94
- PROJECT.run("dotnet new classlib -lang C# --name #{name} --output src/#{name}") unless File.exist?("src/#{name}/#{name}.csproj")
95
- # create the test
96
- puts " creating test/#{name}.Test/#{name}.Test.csproj" unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
97
- PROJECT.run("dotnet new nunit -lang C# --name #{name}.Test --output test/#{name}.Test") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
98
- PROJECT.run("dotnet add test/#{name}.Test/#{name}.Test.csproj reference src/#{name}/#{name}.csproj") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
99
- # generate project folders
100
- ["Interfaces", "Extensions", "Models"].each do |folder|
101
- FileUtils.mkdir_p("src/#{name}/#{folder}") unless Dir.exist?("src/#{name}/#{folder}")
102
- FileUtils.mkdir_p("test/#{name}.Test/#{folder}") unless Dir.exist?("test/#{name}.Test/#{folder}")
103
- end
104
- end
105
-
106
- # initialize a C# razor class library
107
- def self.initialize_csharp_razorclasslib(name)
108
- # create the library
109
- puts " creating src/#{name}/#{name}.csproj" unless File.exist?("src/#{name}/#{name}.csproj")
110
- PROJECT.run("dotnet new razorclasslib -lang C# --name #{name} --output src/#{name}") unless File.exist?("src/#{name}/#{name}.csproj")
111
- # create the test
112
- puts " creating test/#{name}.Test/#{name}.Test.csproj" unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
113
- PROJECT.run("dotnet new nunit -lang C# --name #{name}.Test --output test/#{name}.Test") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
114
- PROJECT.run("dotnet add test/#{name}.Test/#{name}.Test.csproj reference src/#{name}/#{name}.csproj") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
115
- # generate project folders
116
- ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
117
- FileUtils.mkdir_p("src/#{name}/#{folder}") unless Dir.exist?("src/#{name}/#{folder}")
118
- FileUtils.mkdir_p("test/#{name}.Test/#{folder}") unless Dir.exist?("test/#{name}.Test/#{folder}")
119
- end
120
- end
121
-
122
- # initialize a C# blazor server application
123
- def self.initialize_csharp_blazorserver(name)
124
- # create the blazor server application
125
- puts " creating src/#{name}/#{name}.csproj" unless File.exist?("src/#{name}/#{name}.csproj")
126
- PROJECT.run("dotnet new blazorserver -lang C# --name #{name} --output src/#{name}") unless File.exist?("src/#{name}/#{name}.csproj")
127
- # generate project folders
128
- ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
129
- FileUtils.mkdir_p("src/#{name}/#{folder}") unless Dir.exist?("src/#{name}/#{folder}")
130
- end
131
- end
132
-
133
- # initialize a C# blazor server example application
134
- def self.initialize_csharp_blazorserver_example(name)
135
- # create the blazor server application
136
- puts " creating examples/#{name}/#{name}.csproj" unless File.exist?("examples/#{name}/#{name}.csproj")
137
- PROJECT.run("dotnet new blazorserver -lang C# --name #{name} --output examples/#{name}") unless File.exist?("examples/#{name}/#{name}.csproj")
138
- # generate project folders
139
- ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
140
- FileUtils.mkdir_p("examples/#{name}/#{folder}") unless Dir.exist?("examples/#{name}/#{folder}")
141
- end
142
- end
143
-
144
- def self.initialize_csharp_wpf_example(name)
145
- # create the wpf application
146
- puts " creating examples/#{name}/#{name}.csproj" unless File.exist?("examples/#{name}/#{name}.csproj")
147
- PROJECT.run("dotnet new wpf -lang C# --name #{name} --output examples/#{name}") unless File.exist?("examples/#{name}/#{name}.csproj")
148
- # generate project folders
149
- ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
150
- FileUtils.mkdir_p("examples/#{name}/#{folder}") unless Dir.exist?("examples/#{name}/#{folder}")
151
- end
152
- end
153
-
154
- # create a solution of the specified name and add all projects in the current directory
155
- def self.create_solution(name)
156
- PROJECT.run("dotnet new sln --name #{name}") unless File.exist?("#{name}.sln")
157
- Dir.glob("**/*.csproj").each do |project|
158
- PROJECT.run("dotnet sln #{name}.sln add #{project}")
159
- end
160
- end
161
-
162
- def self.get_package_names(filename)
163
- package_names = []
164
- if File.exist?(filename) && filename.include?(".csproj")
165
- regex = /<PackageReference Include="([\w.-]+)"/
166
- text = IO.read(filename)
167
- text.scan(regex).each do |m|
168
- package_names << m.first.to_s
169
- end
170
- end
171
- package_names
172
- end
173
- end
174
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Raykit
4
+ class DotNet
5
+ def self.init_new(name, template)
6
+ if (!File.exist?("#{name}/#{name}.csproj"))
7
+ puts " #{name}.csproj not found, creating..."
8
+ run("dotnet new #{template} --name #{name} --output #{name} --language C# ")
9
+ else
10
+ puts " #{name}.csproj already exists"
11
+ end
12
+ end
13
+
14
+ # initialize an F# library
15
+ def self.initialize_fsharp_lib(name)
16
+ puts `dotnet new sln --name #{name}` unless File.exist?("#{name}.sln")
17
+ unless Dir.exist?(name)
18
+ FileUtils.mkdir(name)
19
+ Dir.chdir(name) do
20
+ puts `dotnet new classlib -lang F#`
21
+ end
22
+ # puts `dotnet new sln`
23
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.fsproj`
24
+
25
+ FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
26
+ Dir.chdir("#{name}.Test") do
27
+ puts `dotnet new nunit -lang F#`
28
+ puts `dotnet add reference ../#{name}/#{name}.fsproj`
29
+ end
30
+
31
+ puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.fsproj`
32
+ end
33
+ end
34
+
35
+ # initialize a C# console application
36
+ def self.initialize_csharp_console(name)
37
+ unless Dir.exist?(name)
38
+ FileUtils.mkdir(name)
39
+ Dir.chdir(name) do
40
+ puts `dotnet new console -lang C#`
41
+ end
42
+ puts `dotnet new sln`
43
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
44
+
45
+ FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
46
+ Dir.chdir("#{name}.Test") do
47
+ puts `dotnet new nunit -lang C#`
48
+ puts `dotnet add reference ../#{name}/#{name}.csproj`
49
+ end
50
+
51
+ puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.csproj`
52
+ end
53
+ end
54
+
55
+ # initialize a C# wpf application
56
+ def self.initialize_csharp_wpf_application(name)
57
+ puts `dotnet new sln --name #{name}`
58
+ unless Dir.exist?(name)
59
+ FileUtils.mkdir(name)
60
+ Dir.chdir(name) do
61
+ puts `dotnet new wpf -lang C#`
62
+ end
63
+ end
64
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
65
+ initialize_csharp_lib("#{name}.Library")
66
+ puts `dotnet sln #{name}.sln add #{name}.Library/#{name}.Library.csproj`
67
+ puts `dotnet sln #{name}.sln add #{name}.Library.Test/#{name}.Library.Test.csproj`
68
+ end
69
+
70
+ # initialize a C# worker service
71
+ def self.initialize_csharp_service(name)
72
+ unless Dir.exist?(name)
73
+ FileUtils.mkdir(name)
74
+ Dir.chdir(name) do
75
+ puts `dotnet new worker -lang C#`
76
+ end
77
+ puts `dotnet new sln`
78
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
79
+ end
80
+ end
81
+
82
+ def self.initialize_csharp_project(template_name, dir, name, folders)
83
+ puts " creating #{dir}/#{name}/#{name}.csproj" unless File.exist?("#{dir}/#{name}/#{name}.csproj")
84
+ PROJECT.run("dotnet new #{template_name} -lang C# --name #{name} --output #{dir}/#{name}") unless File.exist?("#{dir}/#{name}/#{name}.csproj")
85
+ folders.each do |folder|
86
+ FileUtils.mkdir_p("#{dir}/#{name}/#{folder}") unless Dir.exist?("#{dir}/#{name}/#{folder}")
87
+ end
88
+ end
89
+
90
+ # initialize a C# library
91
+ def self.initialize_csharp_lib(name)
92
+ # create the library
93
+ puts " creating src/#{name}/#{name}.csproj" unless File.exist?("src/#{name}/#{name}.csproj")
94
+ PROJECT.run("dotnet new classlib -lang C# --name #{name} --output src/#{name}") unless File.exist?("src/#{name}/#{name}.csproj")
95
+ # create the test
96
+ puts " creating test/#{name}.Test/#{name}.Test.csproj" unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
97
+ PROJECT.run("dotnet new nunit -lang C# --name #{name}.Test --output test/#{name}.Test") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
98
+ PROJECT.run("dotnet add test/#{name}.Test/#{name}.Test.csproj reference src/#{name}/#{name}.csproj") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
99
+ # generate project folders
100
+ ["Interfaces", "Extensions", "Models"].each do |folder|
101
+ FileUtils.mkdir_p("src/#{name}/#{folder}") unless Dir.exist?("src/#{name}/#{folder}")
102
+ FileUtils.mkdir_p("test/#{name}.Test/#{folder}") unless Dir.exist?("test/#{name}.Test/#{folder}")
103
+ end
104
+ end
105
+
106
+ # initialize a C# razor class library
107
+ def self.initialize_csharp_razorclasslib(name)
108
+ # create the library
109
+ puts " creating src/#{name}/#{name}.csproj" unless File.exist?("src/#{name}/#{name}.csproj")
110
+ PROJECT.run("dotnet new razorclasslib -lang C# --name #{name} --output src/#{name}") unless File.exist?("src/#{name}/#{name}.csproj")
111
+ # create the test
112
+ puts " creating test/#{name}.Test/#{name}.Test.csproj" unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
113
+ PROJECT.run("dotnet new nunit -lang C# --name #{name}.Test --output test/#{name}.Test") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
114
+ PROJECT.run("dotnet add test/#{name}.Test/#{name}.Test.csproj reference src/#{name}/#{name}.csproj") unless File.exist?("test/#{name}.Test/#{name}.Test.csproj")
115
+ # generate project folders
116
+ ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
117
+ FileUtils.mkdir_p("src/#{name}/#{folder}") unless Dir.exist?("src/#{name}/#{folder}")
118
+ FileUtils.mkdir_p("test/#{name}.Test/#{folder}") unless Dir.exist?("test/#{name}.Test/#{folder}")
119
+ end
120
+ end
121
+
122
+ # initialize a C# blazor server application
123
+ def self.initialize_csharp_blazorserver(name)
124
+ # create the blazor server application
125
+ puts " creating src/#{name}/#{name}.csproj" unless File.exist?("src/#{name}/#{name}.csproj")
126
+ PROJECT.run("dotnet new blazorserver -lang C# --name #{name} --output src/#{name}") unless File.exist?("src/#{name}/#{name}.csproj")
127
+ # generate project folders
128
+ ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
129
+ FileUtils.mkdir_p("src/#{name}/#{folder}") unless Dir.exist?("src/#{name}/#{folder}")
130
+ end
131
+ end
132
+
133
+ # initialize a C# blazor server example application
134
+ def self.initialize_csharp_blazorserver_example(name)
135
+ # create the blazor server application
136
+ puts " creating examples/#{name}/#{name}.csproj" unless File.exist?("examples/#{name}/#{name}.csproj")
137
+ PROJECT.run("dotnet new blazorserver -lang C# --name #{name} --output examples/#{name}") unless File.exist?("examples/#{name}/#{name}.csproj")
138
+ # generate project folders
139
+ ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
140
+ FileUtils.mkdir_p("examples/#{name}/#{folder}") unless Dir.exist?("examples/#{name}/#{folder}")
141
+ end
142
+ end
143
+
144
+ def self.initialize_csharp_wpf_example(name)
145
+ # create the wpf application
146
+ puts " creating examples/#{name}/#{name}.csproj" unless File.exist?("examples/#{name}/#{name}.csproj")
147
+ PROJECT.run("dotnet new wpf -lang C# --name #{name} --output examples/#{name}") unless File.exist?("examples/#{name}/#{name}.csproj")
148
+ # generate project folders
149
+ ["Interfaces", "Extensions", "Models", "Components", "Controllers"].each do |folder|
150
+ FileUtils.mkdir_p("examples/#{name}/#{folder}") unless Dir.exist?("examples/#{name}/#{folder}")
151
+ end
152
+ end
153
+
154
+ # create a solution of the specified name and add all projects in the current directory
155
+ def self.create_solution(name)
156
+ PROJECT.run("dotnet new sln --name #{name}") unless File.exist?("#{name}.sln")
157
+ Dir.glob("**/*.csproj").each do |project|
158
+ PROJECT.run("dotnet sln #{name}.sln add #{project}")
159
+ end
160
+ end
161
+
162
+ def self.get_package_names(filename)
163
+ package_names = []
164
+ if File.exist?(filename) && filename.include?(".csproj")
165
+ regex = /<PackageReference Include="([\w.-]+)"/
166
+ text = IO.read(filename)
167
+ text.scan(regex).each do |m|
168
+ package_names << m.first.to_s
169
+ end
170
+ end
171
+ package_names
172
+ end
173
+ end
174
+ end
@@ -1,114 +1,114 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
-
5
- module Raykit
6
- # Provides functionality related to the development environment
7
- class Environment
8
- # Normalize a directory or filename to use forward slashes
9
- def self.normalize_path(name)
10
- if (windows?)
11
- normalize_windows(name)
12
- else
13
- normalize_unix(name)
14
- end
15
- end
16
-
17
- def self.normalize_unix(name)
18
- name.gsub('\\', "/")
19
- end
20
-
21
- def self.normalize_windows(name)
22
- name.gsub("/", '\\')
23
- end
24
-
25
- def self.windows?
26
- Gem.win_platform?
27
- end
28
-
29
- # The root directory for the development environment.
30
- # May be set using the environment variable DEV_ROOT,
31
- # otherwise defaults to the user home directory
32
- def self.root_dir
33
- if ENV["DEV_ROOT"].nil?
34
- config = Raykit::Configuration.new
35
- if (config.root_dir.nil? || config.root_dir.empty?)
36
- root = Environment.home_dir
37
- else
38
- root = Environment.home_dir + File::SEPARATOR + config.root_dir
39
- end
40
- else
41
- root = ENV["DEV_ROOT"].gsub("\\", "/").chomp("/")
42
- normalize_path(root)
43
- end
44
- end
45
-
46
- # The user home directory
47
- def self.home_dir
48
- return normalize_path(ENV["USERPROFILE"]) if ENV.include?("USERPROFILE")
49
- normalize_path(ENV["HOME"])
50
- end
51
-
52
- def self.log_dir
53
- get_dev_dir("log")
54
- end
55
-
56
- # Get, and create if it does not exist, a specific development directory
57
- def self.get_dev_dir(name)
58
- dir = Pathname.new("#{Environment.root_dir}/#{name}")
59
- dir.mkpath
60
- if (dir.to_s.include?("https:") || dir.to_s.include?("http:"))
61
- normalize_path(dir.to_s.gsub("https://", ".").gsub("http://", ".").gsub("//", "/"))
62
- else
63
- normalize_path(dir.to_s)
64
- end
65
- end
66
-
67
- def self.get_work_dir(url)
68
- "#{Raykit::Environment.get_dev_dir("work")}/#{url.gsub(".git", "").gsub("://", ".")}"
69
- end
70
-
71
- # Get the size of a directory and its contents
72
- def self.get_dir_size(dir)
73
- Dir.glob(File.join(dir, "**", "*"))
74
- .map { |f| File.size(f) }
75
- .inject(:+)
76
- end
77
-
78
- def self.machine
79
- return ENV["COMPUTERNAME"] unless ENV["COMPUTERNAME"].nil?
80
-
81
- machine = `hostname`
82
- machine = machine.split(".")[0] if machine.include?(".")
83
- machine.strip
84
- end
85
-
86
- def self.user
87
- ENV["USERNAME"]
88
- end
89
-
90
- def self.local_application_data
91
- "#{ENV["USERPROFILE"]}/AppData/Local".gsub('\\', "/")
92
- end
93
-
94
- def self.admin?
95
- rights = `whoami /priv`
96
- rights.include?("SeCreateGlobalPrivilege")
97
- end
98
-
99
- def self.which(name)
100
- return name if File.exist?(name)
101
-
102
- ["", ".exe", ".bat", ".cmd"].each do |ext|
103
- aname = name + ext
104
- return aname if File.exist?(aname)
105
-
106
- ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
107
- apath = "#{path.gsub('\\', "/")}/#{aname}".gsub("//", "/")
108
- return apath if File.exist?(apath)
109
- end
110
- end
111
- ""
112
- end
113
- end
114
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module Raykit
6
+ # Provides functionality related to the development environment
7
+ class Environment
8
+ # Normalize a directory or filename to use forward slashes
9
+ def self.normalize_path(name)
10
+ if (windows?)
11
+ normalize_windows(name)
12
+ else
13
+ normalize_unix(name)
14
+ end
15
+ end
16
+
17
+ def self.normalize_unix(name)
18
+ name.gsub('\\', "/")
19
+ end
20
+
21
+ def self.normalize_windows(name)
22
+ name.gsub("/", '\\')
23
+ end
24
+
25
+ def self.windows?
26
+ Gem.win_platform?
27
+ end
28
+
29
+ # The root directory for the development environment.
30
+ # May be set using the environment variable DEV_ROOT,
31
+ # otherwise defaults to the user home directory
32
+ def self.root_dir
33
+ if ENV["DEV_ROOT"].nil?
34
+ config = Raykit::Configuration.new
35
+ if (config.root_dir.nil? || config.root_dir.empty?)
36
+ root = Environment.home_dir
37
+ else
38
+ root = Environment.home_dir + File::SEPARATOR + config.root_dir
39
+ end
40
+ else
41
+ root = ENV["DEV_ROOT"].gsub("\\", "/").chomp("/")
42
+ normalize_path(root)
43
+ end
44
+ end
45
+
46
+ # The user home directory
47
+ def self.home_dir
48
+ return normalize_path(ENV["USERPROFILE"]) if ENV.include?("USERPROFILE")
49
+ normalize_path(ENV["HOME"])
50
+ end
51
+
52
+ def self.log_dir
53
+ get_dev_dir("log")
54
+ end
55
+
56
+ # Get, and create if it does not exist, a specific development directory
57
+ def self.get_dev_dir(name)
58
+ dir = Pathname.new("#{Environment.root_dir}/#{name}")
59
+ dir.mkpath
60
+ if (dir.to_s.include?("https:") || dir.to_s.include?("http:"))
61
+ normalize_path(dir.to_s.gsub("https://", ".").gsub("http://", ".").gsub("//", "/"))
62
+ else
63
+ normalize_path(dir.to_s)
64
+ end
65
+ end
66
+
67
+ def self.get_work_dir(url)
68
+ "#{Raykit::Environment.get_dev_dir("work")}/#{url.gsub(".git", "").gsub("://", ".")}"
69
+ end
70
+
71
+ # Get the size of a directory and its contents
72
+ def self.get_dir_size(dir)
73
+ Dir.glob(File.join(dir, "**", "*"))
74
+ .map { |f| File.size(f) }
75
+ .inject(:+)
76
+ end
77
+
78
+ def self.machine
79
+ return ENV["COMPUTERNAME"] unless ENV["COMPUTERNAME"].nil?
80
+
81
+ machine = `hostname`
82
+ machine = machine.split(".")[0] if machine.include?(".")
83
+ machine.strip
84
+ end
85
+
86
+ def self.user
87
+ ENV["USERNAME"]
88
+ end
89
+
90
+ def self.local_application_data
91
+ "#{ENV["USERPROFILE"]}/AppData/Local".gsub('\\', "/")
92
+ end
93
+
94
+ def self.admin?
95
+ rights = `whoami /priv`
96
+ rights.include?("SeCreateGlobalPrivilege")
97
+ end
98
+
99
+ def self.which(name)
100
+ return name if File.exist?(name)
101
+
102
+ ["", ".exe", ".bat", ".cmd"].each do |ext|
103
+ aname = name + ext
104
+ return aname if File.exist?(aname)
105
+
106
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
107
+ apath = "#{path.gsub('\\', "/")}/#{aname}".gsub("//", "/")
108
+ return apath if File.exist?(apath)
109
+ end
110
+ end
111
+ ""
112
+ end
113
+ end
114
+ end
@@ -1,34 +1,34 @@
1
- module Raykit
2
- class FileSystem
3
- def self.copy_files(source_dir, target_dir, glob_pattern)
4
- FileUtils.mkdir_p(target_dir) if !Dir.exist?(target_dir)
5
- #Dir.chdir(source_dir) do
6
- file_count = 0
7
- Dir.glob("#{source_dir}/#{glob_pattern}").each { |f|
8
- rel = f.gsub("#{source_dir}/", "")
9
- dest = "#{target_dir}/#{rel}"
10
- FileUtils.mkdir_p(File.dirname(dest)) if (!Dir.exist?(File.dirname(dest)))
11
- #puts " copying #{rel} to #{dest}"
12
- FileUtils.cp(f, dest)
13
- file_count = file_count + 1
14
- }
15
- #end
16
- puts " copied " + file_count.to_s + " file(s) from #{source_dir} to #{target_dir}"
17
- end
18
-
19
- def self.copy_file_to_dir(file, dir)
20
- dest = "#{dir}/#{File.basename(file)}"
21
- if (File.exist?(dest))
22
- return "#{dest} already exists"
23
- else
24
- FileUtils.cp(file, dest)
25
- return "#{dest} now exists"
26
- end
27
- end
28
-
29
- def self.replace_invalid_chars(str)
30
- #[\\/:"*?<>|]
31
- str.gsub('\\', "_").gsub("/", "_").gsub(":", "_").gsub("*", "_").gsub("?", "_")
32
- end
33
- end
34
- end
1
+ module Raykit
2
+ class FileSystem
3
+ def self.copy_files(source_dir, target_dir, glob_pattern)
4
+ FileUtils.mkdir_p(target_dir) if !Dir.exist?(target_dir)
5
+ #Dir.chdir(source_dir) do
6
+ file_count = 0
7
+ Dir.glob("#{source_dir}/#{glob_pattern}").each { |f|
8
+ rel = f.gsub("#{source_dir}/", "")
9
+ dest = "#{target_dir}/#{rel}"
10
+ FileUtils.mkdir_p(File.dirname(dest)) if (!Dir.exist?(File.dirname(dest)))
11
+ #puts " copying #{rel} to #{dest}"
12
+ FileUtils.cp(f, dest)
13
+ file_count = file_count + 1
14
+ }
15
+ #end
16
+ puts " copied " + file_count.to_s + " file(s) from #{source_dir} to #{target_dir}"
17
+ end
18
+
19
+ def self.copy_file_to_dir(file, dir)
20
+ dest = "#{dir}/#{File.basename(file)}"
21
+ if (File.exist?(dest))
22
+ return "#{dest} already exists"
23
+ else
24
+ FileUtils.cp(file, dest)
25
+ return "#{dest} now exists"
26
+ end
27
+ end
28
+
29
+ def self.replace_invalid_chars(str)
30
+ #[\\/:"*?<>|]
31
+ str.gsub('\\', "_").gsub("/", "_").gsub(":", "_").gsub("*", "_").gsub("?", "_")
32
+ end
33
+ end
34
+ end