raykit 0.0.527 → 0.0.530

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +25 -25
  4. data/bin/raykit +6 -6
  5. data/lib/raykit/auto_setup.rb +69 -69
  6. data/lib/raykit/command.rb +374 -374
  7. data/lib/raykit/conan/buildinfo.rb +69 -69
  8. data/lib/raykit/conanpackage.rb +49 -49
  9. data/lib/raykit/configuration.rb +53 -53
  10. data/lib/raykit/console.rb +310 -310
  11. data/lib/raykit/default_content.rb +227 -227
  12. data/lib/raykit/dir.rb +96 -96
  13. data/lib/raykit/dotnet.rb +174 -174
  14. data/lib/raykit/environment.rb +115 -115
  15. data/lib/raykit/filesystem.rb +34 -34
  16. data/lib/raykit/git/commit.rb +16 -16
  17. data/lib/raykit/git/directory.rb +258 -220
  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 +362 -362
  21. data/lib/raykit/installer.rb +17 -17
  22. data/lib/raykit/log.rb +80 -80
  23. data/lib/raykit/logevent.rb +29 -29
  24. data/lib/raykit/logger.rb +100 -100
  25. data/lib/raykit/logging.rb +57 -57
  26. data/lib/raykit/markdown.rb +21 -21
  27. data/lib/raykit/msbuild.rb +54 -54
  28. data/lib/raykit/nugetpackage.rb +54 -54
  29. data/lib/raykit/nunit.rb +13 -13
  30. data/lib/raykit/project.rb +343 -343
  31. data/lib/raykit/rake.rb +39 -39
  32. data/lib/raykit/runner.rb +42 -42
  33. data/lib/raykit/secrets.rb +38 -38
  34. data/lib/raykit/sourceImport.rb +76 -76
  35. data/lib/raykit/sourceImports.rb +43 -43
  36. data/lib/raykit/string.rb +18 -18
  37. data/lib/raykit/symbols.rb +115 -115
  38. data/lib/raykit/tasks.rb +91 -91
  39. data/lib/raykit/text.rb +32 -32
  40. data/lib/raykit/timer.rb +31 -31
  41. data/lib/raykit/version.rb +95 -95
  42. data/lib/raykit/vstest.rb +24 -24
  43. data/lib/raykit/wix.rb +61 -61
  44. data/lib/raykit/wt.rb +28 -28
  45. data/lib/raykit/zip.rb +73 -73
  46. data/lib/raykit.rb +135 -132
  47. metadata +3 -3
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,115 +1,115 @@
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 + File::SEPARATOR + "code"
37
- else
38
- root = Environment.home_dir + File::SEPARATOR + config.root_dir
39
- end
40
- normalize_path(root)
41
- else
42
- root = ENV["DEV_ROOT"].gsub("\\", "/").chomp("/")
43
- normalize_path(root)
44
- end
45
- end
46
-
47
- # The user home directory
48
- def self.home_dir
49
- return normalize_path(ENV["USERPROFILE"]) if ENV.include?("USERPROFILE")
50
- normalize_path(ENV["HOME"])
51
- end
52
-
53
- def self.log_dir
54
- get_dev_dir("log")
55
- end
56
-
57
- # Get, and create if it does not exist, a specific development directory
58
- def self.get_dev_dir(name)
59
- dir = Pathname.new("#{Environment.root_dir}/#{name}")
60
- dir.mkpath
61
- if (dir.to_s.include?("https:") || dir.to_s.include?("http:"))
62
- normalize_path(dir.to_s.gsub("https://", ".").gsub("http://", ".").gsub("//", "/"))
63
- else
64
- normalize_path(dir.to_s)
65
- end
66
- end
67
-
68
- def self.get_work_dir(url)
69
- "#{Raykit::Environment.get_dev_dir("work")}/#{url.gsub(".git", "").gsub("://", ".")}"
70
- end
71
-
72
- # Get the size of a directory and its contents
73
- def self.get_dir_size(dir)
74
- Dir.glob(File.join(dir, "**", "*"))
75
- .map { |f| File.size(f) }
76
- .inject(:+)
77
- end
78
-
79
- def self.machine
80
- return ENV["COMPUTERNAME"] unless ENV["COMPUTERNAME"].nil?
81
-
82
- machine = `hostname`
83
- machine = machine.split(".")[0] if machine.include?(".")
84
- machine.strip
85
- end
86
-
87
- def self.user
88
- ENV["USERNAME"]
89
- end
90
-
91
- def self.local_application_data
92
- "#{ENV["USERPROFILE"]}/AppData/Local".gsub('\\', "/")
93
- end
94
-
95
- def self.admin?
96
- rights = `whoami /priv`
97
- rights.include?("SeCreateGlobalPrivilege")
98
- end
99
-
100
- def self.which(name)
101
- return name if File.exist?(name)
102
-
103
- ["", ".exe", ".bat", ".cmd"].each do |ext|
104
- aname = name + ext
105
- return aname if File.exist?(aname)
106
-
107
- ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
108
- apath = "#{path.gsub('\\', "/")}/#{aname}".gsub("//", "/")
109
- return apath if File.exist?(apath)
110
- end
111
- end
112
- ""
113
- end
114
- end
115
- 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 + File::SEPARATOR + "code"
37
+ else
38
+ root = Environment.home_dir + File::SEPARATOR + config.root_dir
39
+ end
40
+ normalize_path(root)
41
+ else
42
+ root = ENV["DEV_ROOT"].gsub("\\", "/").chomp("/")
43
+ normalize_path(root)
44
+ end
45
+ end
46
+
47
+ # The user home directory
48
+ def self.home_dir
49
+ return normalize_path(ENV["USERPROFILE"]) if ENV.include?("USERPROFILE")
50
+ normalize_path(ENV["HOME"])
51
+ end
52
+
53
+ def self.log_dir
54
+ get_dev_dir("log")
55
+ end
56
+
57
+ # Get, and create if it does not exist, a specific development directory
58
+ def self.get_dev_dir(name)
59
+ dir = Pathname.new("#{Environment.root_dir}/#{name}")
60
+ dir.mkpath
61
+ if (dir.to_s.include?("https:") || dir.to_s.include?("http:"))
62
+ normalize_path(dir.to_s.gsub("https://", ".").gsub("http://", ".").gsub("//", "/"))
63
+ else
64
+ normalize_path(dir.to_s)
65
+ end
66
+ end
67
+
68
+ def self.get_work_dir(url)
69
+ "#{Raykit::Environment.get_dev_dir("work")}/#{url.gsub(".git", "").gsub("://", ".")}"
70
+ end
71
+
72
+ # Get the size of a directory and its contents
73
+ def self.get_dir_size(dir)
74
+ Dir.glob(File.join(dir, "**", "*"))
75
+ .map { |f| File.size(f) }
76
+ .inject(:+)
77
+ end
78
+
79
+ def self.machine
80
+ return ENV["COMPUTERNAME"] unless ENV["COMPUTERNAME"].nil?
81
+
82
+ machine = `hostname`
83
+ machine = machine.split(".")[0] if machine.include?(".")
84
+ machine.strip
85
+ end
86
+
87
+ def self.user
88
+ ENV["USERNAME"]
89
+ end
90
+
91
+ def self.local_application_data
92
+ "#{ENV["USERPROFILE"]}/AppData/Local".gsub('\\', "/")
93
+ end
94
+
95
+ def self.admin?
96
+ rights = `whoami /priv`
97
+ rights.include?("SeCreateGlobalPrivilege")
98
+ end
99
+
100
+ def self.which(name)
101
+ return name if File.exist?(name)
102
+
103
+ ["", ".exe", ".bat", ".cmd"].each do |ext|
104
+ aname = name + ext
105
+ return aname if File.exist?(aname)
106
+
107
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
108
+ apath = "#{path.gsub('\\', "/")}/#{aname}".gsub("//", "/")
109
+ return apath if File.exist?(apath)
110
+ end
111
+ end
112
+ ""
113
+ end
114
+ end
115
+ 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