raykit 0.0.467 → 0.0.468

Sign up to get free protection for your applications and to get access to all the features.
data/lib/raykit/dotnet.rb CHANGED
@@ -1,115 +1,115 @@
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 a C# library
15
- def self.initialize_csharp_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 C#`
21
- end
22
- # puts `dotnet new sln`
23
- puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
24
-
25
- FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
26
- Dir.chdir("#{name}.Test") do
27
- puts `dotnet new nunit -lang C#`
28
- puts `dotnet add reference ../#{name}/#{name}.csproj`
29
- end
30
-
31
- puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.csproj`
32
- end
33
- end
34
-
35
- # initialize an F# library
36
- def self.initialize_fsharp_lib(name)
37
- puts `dotnet new sln --name #{name}` unless File.exist?("#{name}.sln")
38
- unless Dir.exist?(name)
39
- FileUtils.mkdir(name)
40
- Dir.chdir(name) do
41
- puts `dotnet new classlib -lang F#`
42
- end
43
- # puts `dotnet new sln`
44
- puts `dotnet sln #{name}.sln add #{name}/#{name}.fsproj`
45
-
46
- FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
47
- Dir.chdir("#{name}.Test") do
48
- puts `dotnet new nunit -lang F#`
49
- puts `dotnet add reference ../#{name}/#{name}.fsproj`
50
- end
51
-
52
- puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.fsproj`
53
- end
54
- end
55
-
56
- # initialize a C# console application
57
- def self.initialize_csharp_console(name)
58
- unless Dir.exist?(name)
59
- FileUtils.mkdir(name)
60
- Dir.chdir(name) do
61
- puts `dotnet new console -lang C#`
62
- end
63
- puts `dotnet new sln`
64
- puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
65
-
66
- FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
67
- Dir.chdir("#{name}.Test") do
68
- puts `dotnet new nunit -lang C#`
69
- puts `dotnet add reference ../#{name}/#{name}.csproj`
70
- end
71
-
72
- puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.csproj`
73
- end
74
- end
75
-
76
- # initialize a C# wpf application
77
- def self.initialize_csharp_wpf_application(name)
78
- puts `dotnet new sln --name #{name}`
79
- unless Dir.exist?(name)
80
- FileUtils.mkdir(name)
81
- Dir.chdir(name) do
82
- puts `dotnet new wpf -lang C#`
83
- end
84
- end
85
- puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
86
- initialize_csharp_lib("#{name}.Library")
87
- puts `dotnet sln #{name}.sln add #{name}.Library/#{name}.Library.csproj`
88
- puts `dotnet sln #{name}.sln add #{name}.Library.Test/#{name}.Library.Test.csproj`
89
- end
90
-
91
- # initialize a C# worker service
92
- def self.initialize_csharp_service(name)
93
- unless Dir.exist?(name)
94
- FileUtils.mkdir(name)
95
- Dir.chdir(name) do
96
- puts `dotnet new worker -lang C#`
97
- end
98
- puts `dotnet new sln`
99
- puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
100
- end
101
- end
102
-
103
- def self.get_package_names(filename)
104
- package_names = []
105
- if File.exist?(filename) && filename.include?(".csproj")
106
- regex = /<PackageReference Include="([\w.-]+)"/
107
- text = IO.read(filename)
108
- text.scan(regex).each do |m|
109
- package_names << m.first.to_s
110
- end
111
- end
112
- package_names
113
- end
114
- end
115
- 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 a C# library
15
+ def self.initialize_csharp_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 C#`
21
+ end
22
+ # puts `dotnet new sln`
23
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
24
+
25
+ FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
26
+ Dir.chdir("#{name}.Test") do
27
+ puts `dotnet new nunit -lang C#`
28
+ puts `dotnet add reference ../#{name}/#{name}.csproj`
29
+ end
30
+
31
+ puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.csproj`
32
+ end
33
+ end
34
+
35
+ # initialize an F# library
36
+ def self.initialize_fsharp_lib(name)
37
+ puts `dotnet new sln --name #{name}` unless File.exist?("#{name}.sln")
38
+ unless Dir.exist?(name)
39
+ FileUtils.mkdir(name)
40
+ Dir.chdir(name) do
41
+ puts `dotnet new classlib -lang F#`
42
+ end
43
+ # puts `dotnet new sln`
44
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.fsproj`
45
+
46
+ FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
47
+ Dir.chdir("#{name}.Test") do
48
+ puts `dotnet new nunit -lang F#`
49
+ puts `dotnet add reference ../#{name}/#{name}.fsproj`
50
+ end
51
+
52
+ puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.fsproj`
53
+ end
54
+ end
55
+
56
+ # initialize a C# console application
57
+ def self.initialize_csharp_console(name)
58
+ unless Dir.exist?(name)
59
+ FileUtils.mkdir(name)
60
+ Dir.chdir(name) do
61
+ puts `dotnet new console -lang C#`
62
+ end
63
+ puts `dotnet new sln`
64
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
65
+
66
+ FileUtils.mkdir("#{name}.Test") unless Dir.exist?("#{name}.Test")
67
+ Dir.chdir("#{name}.Test") do
68
+ puts `dotnet new nunit -lang C#`
69
+ puts `dotnet add reference ../#{name}/#{name}.csproj`
70
+ end
71
+
72
+ puts `dotnet sln #{name}.sln add #{name}.Test/#{name}.Test.csproj`
73
+ end
74
+ end
75
+
76
+ # initialize a C# wpf application
77
+ def self.initialize_csharp_wpf_application(name)
78
+ puts `dotnet new sln --name #{name}`
79
+ unless Dir.exist?(name)
80
+ FileUtils.mkdir(name)
81
+ Dir.chdir(name) do
82
+ puts `dotnet new wpf -lang C#`
83
+ end
84
+ end
85
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
86
+ initialize_csharp_lib("#{name}.Library")
87
+ puts `dotnet sln #{name}.sln add #{name}.Library/#{name}.Library.csproj`
88
+ puts `dotnet sln #{name}.sln add #{name}.Library.Test/#{name}.Library.Test.csproj`
89
+ end
90
+
91
+ # initialize a C# worker service
92
+ def self.initialize_csharp_service(name)
93
+ unless Dir.exist?(name)
94
+ FileUtils.mkdir(name)
95
+ Dir.chdir(name) do
96
+ puts `dotnet new worker -lang C#`
97
+ end
98
+ puts `dotnet new sln`
99
+ puts `dotnet sln #{name}.sln add #{name}/#{name}.csproj`
100
+ end
101
+ end
102
+
103
+ def self.get_package_names(filename)
104
+ package_names = []
105
+ if File.exist?(filename) && filename.include?(".csproj")
106
+ regex = /<PackageReference Include="([\w.-]+)"/
107
+ text = IO.read(filename)
108
+ text.scan(regex).each do |m|
109
+ package_names << m.first.to_s
110
+ end
111
+ end
112
+ package_names
113
+ end
114
+ end
115
+ end
@@ -1,109 +1,109 @@
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
- Environment.home_dir
35
- else
36
- root = ENV["DEV_ROOT"].gsub("\\", "/").chomp("/")
37
- normalize_path(root)
38
- end
39
- end
40
-
41
- # The user home directory
42
- def self.home_dir
43
- return normalize_path(ENV["USERPROFILE"]) if ENV.include?("USERPROFILE")
44
- normalize_path(ENV["HOME"])
45
- end
46
-
47
- def self.log_dir
48
- get_dev_dir("log")
49
- end
50
-
51
- # Get, and create if it does not exist, a specific development directory
52
- def self.get_dev_dir(name)
53
- dir = Pathname.new("#{Environment.root_dir}/#{name}")
54
- dir.mkpath
55
- if (dir.to_s.include?("https:") || dir.to_s.include?("http:"))
56
- normalize_path(dir.to_s.gsub("https://", ".").gsub("http://", ".").gsub("//", "/"))
57
- else
58
- normalize_path(dir.to_s)
59
- end
60
- end
61
-
62
- def self.get_work_dir(url)
63
- "#{Raykit::Environment.get_dev_dir("work")}/#{url.gsub(".git", "").gsub("://", ".")}"
64
- end
65
-
66
- # Get the size of a directory and its contents
67
- def self.get_dir_size(dir)
68
- Dir.glob(File.join(dir, "**", "*"))
69
- .map { |f| File.size(f) }
70
- .inject(:+)
71
- end
72
-
73
- def self.machine
74
- return ENV["COMPUTERNAME"] unless ENV["COMPUTERNAME"].nil?
75
-
76
- machine = `hostname`
77
- machine = machine.split(".")[0] if machine.include?(".")
78
- machine.strip
79
- end
80
-
81
- def self.user
82
- ENV["USERNAME"]
83
- end
84
-
85
- def self.local_application_data
86
- "#{ENV["USERPROFILE"]}/AppData/Local".gsub('\\', "/")
87
- end
88
-
89
- def self.admin?
90
- rights = `whoami /priv`
91
- rights.include?("SeCreateGlobalPrivilege")
92
- end
93
-
94
- def self.which(name)
95
- return name if File.exist?(name)
96
-
97
- ["", ".exe", ".bat", ".cmd"].each do |ext|
98
- aname = name + ext
99
- return aname if File.exist?(aname)
100
-
101
- ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
102
- apath = "#{path.gsub('\\', "/")}/#{aname}".gsub("//", "/")
103
- return apath if File.exist?(apath)
104
- end
105
- end
106
- ""
107
- end
108
- end
109
- 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
+ Environment.home_dir
35
+ else
36
+ root = ENV["DEV_ROOT"].gsub("\\", "/").chomp("/")
37
+ normalize_path(root)
38
+ end
39
+ end
40
+
41
+ # The user home directory
42
+ def self.home_dir
43
+ return normalize_path(ENV["USERPROFILE"]) if ENV.include?("USERPROFILE")
44
+ normalize_path(ENV["HOME"])
45
+ end
46
+
47
+ def self.log_dir
48
+ get_dev_dir("log")
49
+ end
50
+
51
+ # Get, and create if it does not exist, a specific development directory
52
+ def self.get_dev_dir(name)
53
+ dir = Pathname.new("#{Environment.root_dir}/#{name}")
54
+ dir.mkpath
55
+ if (dir.to_s.include?("https:") || dir.to_s.include?("http:"))
56
+ normalize_path(dir.to_s.gsub("https://", ".").gsub("http://", ".").gsub("//", "/"))
57
+ else
58
+ normalize_path(dir.to_s)
59
+ end
60
+ end
61
+
62
+ def self.get_work_dir(url)
63
+ "#{Raykit::Environment.get_dev_dir("work")}/#{url.gsub(".git", "").gsub("://", ".")}"
64
+ end
65
+
66
+ # Get the size of a directory and its contents
67
+ def self.get_dir_size(dir)
68
+ Dir.glob(File.join(dir, "**", "*"))
69
+ .map { |f| File.size(f) }
70
+ .inject(:+)
71
+ end
72
+
73
+ def self.machine
74
+ return ENV["COMPUTERNAME"] unless ENV["COMPUTERNAME"].nil?
75
+
76
+ machine = `hostname`
77
+ machine = machine.split(".")[0] if machine.include?(".")
78
+ machine.strip
79
+ end
80
+
81
+ def self.user
82
+ ENV["USERNAME"]
83
+ end
84
+
85
+ def self.local_application_data
86
+ "#{ENV["USERPROFILE"]}/AppData/Local".gsub('\\', "/")
87
+ end
88
+
89
+ def self.admin?
90
+ rights = `whoami /priv`
91
+ rights.include?("SeCreateGlobalPrivilege")
92
+ end
93
+
94
+ def self.which(name)
95
+ return name if File.exist?(name)
96
+
97
+ ["", ".exe", ".bat", ".cmd"].each do |ext|
98
+ aname = name + ext
99
+ return aname if File.exist?(aname)
100
+
101
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
102
+ apath = "#{path.gsub('\\', "/")}/#{aname}".gsub("//", "/")
103
+ return apath if File.exist?(apath)
104
+ end
105
+ end
106
+ ""
107
+ end
108
+ end
109
+ 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
@@ -1,16 +1,16 @@
1
- # frozen_string_literal: true
2
-
3
- module Raykit
4
- module Git
5
- # Functionality to manage a git commit
6
- class Commit
7
- attr_accessor :url, :branch, :commit_id
8
-
9
- def initialize(url, branch, commit_id)
10
- @url = url
11
- @branch = branch
12
- @commit_id = commit_id
13
- end
14
- end
15
- end
16
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Raykit
4
+ module Git
5
+ # Functionality to manage a git commit
6
+ class Commit
7
+ attr_accessor :url, :branch, :commit_id
8
+
9
+ def initialize(url, branch, commit_id)
10
+ @url = url
11
+ @branch = branch
12
+ @commit_id = commit_id
13
+ end
14
+ end
15
+ end
16
+ end