raykit 0.0.543 → 0.0.544
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +25 -25
- data/bin/raykit +6 -6
- data/lib/raykit/auto_setup.rb +69 -69
- data/lib/raykit/command.rb +374 -374
- data/lib/raykit/conan/buildinfo.rb +69 -69
- data/lib/raykit/conanpackage.rb +49 -49
- data/lib/raykit/configuration.rb +53 -53
- data/lib/raykit/console.rb +310 -310
- data/lib/raykit/default_content.rb +8 -8
- data/lib/raykit/default_content.txt +219 -219
- data/lib/raykit/dir.rb +127 -127
- data/lib/raykit/dotnet.rb +174 -174
- data/lib/raykit/environment.rb +115 -115
- data/lib/raykit/filesystem.rb +34 -34
- data/lib/raykit/git/commit.rb +16 -16
- data/lib/raykit/git/directory.rb +279 -279
- data/lib/raykit/git/files.rb +46 -46
- data/lib/raykit/git/repositories.rb +89 -89
- data/lib/raykit/git/repository.rb +362 -362
- data/lib/raykit/installer.rb +17 -17
- data/lib/raykit/log.rb +80 -80
- data/lib/raykit/logevent.rb +29 -29
- data/lib/raykit/logger.rb +100 -100
- data/lib/raykit/logging.rb +57 -57
- data/lib/raykit/markdown.rb +21 -21
- data/lib/raykit/msbuild.rb +54 -54
- data/lib/raykit/nugetpackage.rb +54 -54
- data/lib/raykit/nunit.rb +13 -13
- data/lib/raykit/project.rb +343 -343
- data/lib/raykit/rake.rb +39 -39
- data/lib/raykit/runner.rb +42 -42
- data/lib/raykit/secrets.rb +38 -38
- data/lib/raykit/sourceImport.rb +76 -76
- data/lib/raykit/sourceImports.rb +43 -43
- data/lib/raykit/string.rb +18 -18
- data/lib/raykit/symbols.rb +115 -115
- data/lib/raykit/tasks.rb +91 -91
- data/lib/raykit/text.rb +32 -32
- data/lib/raykit/timer.rb +31 -31
- data/lib/raykit/version.rb +97 -95
- data/lib/raykit/vstest.rb +24 -24
- data/lib/raykit/wix.rb +61 -61
- data/lib/raykit/wt.rb +28 -28
- data/lib/raykit/zip.rb +73 -73
- data/lib/raykit.rb +143 -140
- metadata +3 -3
data/lib/raykit/version.rb
CHANGED
@@ -1,95 +1,97 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# warn "[DEPRECATION] Raykit::VersionHelper is deprecated. Use bump gem for better transparency."
|
4
|
-
|
5
|
-
module Raykit
|
6
|
-
# Version functionality
|
7
|
-
class Version
|
8
|
-
attr_accessor :start_time
|
9
|
-
|
10
|
-
# detect a version number based on the NAME variable, if defined
|
11
|
-
def self.detect(name)
|
12
|
-
version = detect_from_file("#{name}/#{name}.csproj", /<Version>([-\w\d.]+)</)
|
13
|
-
return version if version.length.positive?
|
14
|
-
|
15
|
-
version
|
16
|
-
|
17
|
-
|
18
|
-
version
|
19
|
-
|
20
|
-
|
21
|
-
version
|
22
|
-
|
23
|
-
|
24
|
-
version
|
25
|
-
|
26
|
-
|
27
|
-
version
|
28
|
-
|
29
|
-
""
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
new_text = text
|
54
|
-
new_text = text.gsub(
|
55
|
-
new_text = text.gsub(
|
56
|
-
|
57
|
-
new_text = text.gsub(/
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# new_text=
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
version_ints.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# warn "[DEPRECATION] Raykit::VersionHelper is deprecated. Use bump gem for better transparency."
|
4
|
+
|
5
|
+
module Raykit
|
6
|
+
# Version functionality
|
7
|
+
class Version
|
8
|
+
attr_accessor :start_time
|
9
|
+
|
10
|
+
# detect a version number based on the NAME variable, if defined
|
11
|
+
def self.detect(name)
|
12
|
+
version = detect_from_file("#{name}/#{name}.csproj", /<Version>([-\w\d.]+)</)
|
13
|
+
return version if version.length.positive?
|
14
|
+
version = detect_from_file("src/#{name}/#{name}.csproj", /<Version>([-\w\d.]+)</)
|
15
|
+
return version if version.length.positive?
|
16
|
+
|
17
|
+
version = detect_from_file("#{name}/Properties/AssemblyInfo.cs", /^\[assembly: AssemblyVersion\("([.\w]+)/)
|
18
|
+
return version if version.length.positive?
|
19
|
+
|
20
|
+
version = detect_from_file("Cargo.toml", /version\s+=\s+['"]([\w.]+)['"]/)
|
21
|
+
return version if version.length.positive?
|
22
|
+
|
23
|
+
version = detect_from_file("#{name}.gemspec", /version\s+=\s+['"]([\w.]+)['"]/)
|
24
|
+
return version if version.length.positive?
|
25
|
+
|
26
|
+
version = detect_from_file("#{name}.gemspec", /version\s?=\s?['|"]([.\d]+)['|"]/)
|
27
|
+
return version if version.length.positive?
|
28
|
+
|
29
|
+
version = detect_from_file("#{name}.nuspec", /<[Vv]ersion>([\d.]+)</)
|
30
|
+
return version if version.length.positive?
|
31
|
+
""
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.detect_from_file(filename, regex)
|
35
|
+
version = ""
|
36
|
+
if File.exist?(filename)
|
37
|
+
match = IO.read(filename).match(regex)
|
38
|
+
version = match.captures[0] if !match.nil? && match.captures.length.positive?
|
39
|
+
else
|
40
|
+
return ""
|
41
|
+
end
|
42
|
+
version
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.set_version_in_glob(glob_pattern, version)
|
46
|
+
Dir.glob(glob_pattern).each { |f|
|
47
|
+
Raykit::Version::set_version_in_file(f, version)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.set_version_in_file(filename, version)
|
52
|
+
text = IO.read(filename)
|
53
|
+
new_text = text
|
54
|
+
new_text = text.gsub(/version\s?=\s?['|"]([.\d]+)['|"]/, "version='#{version}'") if filename.include?(".gemspec")
|
55
|
+
new_text = text.gsub(/<Version>([-\w\d.]+)</, "<Version>#{version}<") if filename.include?(".csproj")
|
56
|
+
new_text = text.gsub(/<version>([-\w\d.]+)</, "<version>#{version}<") if filename.include?(".nuspec")
|
57
|
+
new_text = text.gsub(/ Version="([\d\.]+)"/, " Version=\"#{version}\"") if filename.include?(".wxs")
|
58
|
+
|
59
|
+
new_text = text.gsub(/version\s+=\s+['"]([\w.]+)['"]/, "version=\"#{version}\"") if filename.include?(".toml")
|
60
|
+
|
61
|
+
# new_text=text.gsub(/<Version>([-\w\d.]+)</,"<Version>#{version}<")
|
62
|
+
# new_text=new_text.gsub(/version[\s]+=\s?['|"]([.\d]+)['|"]/,"version='#{version}'")
|
63
|
+
# new_text=new_text.gsub(/Version="([.\d]+)"/,"Version=\"#{version}\"")
|
64
|
+
File.open(filename, "w") { |f| f.write(new_text) } if new_text != text
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.sync_file_versions(source_filename, destination_filename)
|
68
|
+
version = Version.detect_from_file(source_filename, /<Version>([-\w\d.]+)</, false)
|
69
|
+
Version.set_version_in_file(destination_filename, version)
|
70
|
+
end
|
71
|
+
|
72
|
+
# increment to last digit of a version string
|
73
|
+
def self.bump(version)
|
74
|
+
# major.minor[.build[.revision]] (example: 1.2.12.102)
|
75
|
+
version_ints = version.split(".").map(&:to_i)
|
76
|
+
version_ints[-1] = version_ints.last + 1
|
77
|
+
version_ints.map(&:to_s).join(".")
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.bump_file(filename)
|
81
|
+
warn "Raykit::Version.bump_file filename '#{filename}' does not exist." unless File.exist?(filename)
|
82
|
+
|
83
|
+
old_version = ""
|
84
|
+
if filename.include?(".gemspec")
|
85
|
+
old_version = detect_from_file(filename, /version\s?=\s?['|"]([.\d]+)['|"]/)
|
86
|
+
end
|
87
|
+
old_version = detect_from_file(filename, /<Version>([-\w\d.]+)</) if filename.include?(".csproj")
|
88
|
+
|
89
|
+
if old_version.length.positive?
|
90
|
+
new_version = bump(old_version)
|
91
|
+
set_version_in_file(filename, new_version)
|
92
|
+
end
|
93
|
+
|
94
|
+
new_version
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/raykit/vstest.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Raykit
|
4
|
-
class VsTest
|
5
|
-
def self.vstest_path
|
6
|
-
["2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow",
|
7
|
-
"2022/Professional/Common7/IDE/CommonExtensions/Microsoft/TestWindow",
|
8
|
-
"2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TestWindow",
|
9
|
-
"2019/Community/Common7/IDE/CommonExtensions/Microsoft",
|
10
|
-
"2019/Professional/Common7/IDE/Extensions/TestPlatform",
|
11
|
-
"2019/Community/Common7/IDE/Extensions",
|
12
|
-
"2019/Community/Common7/IDE/Extensions/TestPlatform",
|
13
|
-
"2022/Preview/Common7/IDE/Extensions/TestPlatform"].each do |relative_path|
|
14
|
-
["C:/Program Files (x86)/Microsoft Visual Studio/",
|
15
|
-
"C:/Program Files/Microsoft Visual Studio/"].each do |root_path|
|
16
|
-
path = root_path + relative_path
|
17
|
-
exe_path = "#{path}/vstest.console.exe"
|
18
|
-
return path if Dir.exist?(path) && File.exist?(exe_path)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
"vstest_path not found"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raykit
|
4
|
+
class VsTest
|
5
|
+
def self.vstest_path
|
6
|
+
["2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow",
|
7
|
+
"2022/Professional/Common7/IDE/CommonExtensions/Microsoft/TestWindow",
|
8
|
+
"2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TestWindow",
|
9
|
+
"2019/Community/Common7/IDE/CommonExtensions/Microsoft",
|
10
|
+
"2019/Professional/Common7/IDE/Extensions/TestPlatform",
|
11
|
+
"2019/Community/Common7/IDE/Extensions",
|
12
|
+
"2019/Community/Common7/IDE/Extensions/TestPlatform",
|
13
|
+
"2022/Preview/Common7/IDE/Extensions/TestPlatform"].each do |relative_path|
|
14
|
+
["C:/Program Files (x86)/Microsoft Visual Studio/",
|
15
|
+
"C:/Program Files/Microsoft Visual Studio/"].each do |root_path|
|
16
|
+
path = root_path + relative_path
|
17
|
+
exe_path = "#{path}/vstest.console.exe"
|
18
|
+
return path if Dir.exist?(path) && File.exist?(exe_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
"vstest_path not found"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/raykit/wix.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Raykit
|
4
|
-
class Wix
|
5
|
-
def self.harvest_directory_elements(directory)
|
6
|
-
get_nested_directory_element("", directory)
|
7
|
-
end
|
8
|
-
def self.get_nested_directory_element(id_prefix, directory)
|
9
|
-
Dir.chdir(directory) do
|
10
|
-
results = Array::new
|
11
|
-
Dir.glob("*").reject { |f| !File.directory? f }.each { |d|
|
12
|
-
directoryId = "#{d.upcase.gsub("/", "_").gsub("-", "_")}DIR"
|
13
|
-
directoryId = "#{id_prefix}#{directoryId}"
|
14
|
-
child_elements = get_nested_directory_element("#{directoryId[0...-3]}_", d)
|
15
|
-
if (child_elements.length > 0)
|
16
|
-
results.push("<Directory Id=\"#{directoryId}\" Name=\"#{d}\">")
|
17
|
-
child_elements.each { |child_element|
|
18
|
-
results.push("\t#{child_element}")
|
19
|
-
}
|
20
|
-
results.push("</Directory>")
|
21
|
-
else
|
22
|
-
results.push("<Directory Id=\"#{directoryId}\" Name=\"#{d}\"/>")
|
23
|
-
end
|
24
|
-
}
|
25
|
-
results
|
26
|
-
end
|
27
|
-
end
|
28
|
-
# given a directory, return an array of string the represent wix components for each file in the directory
|
29
|
-
# each string should look like this:
|
30
|
-
# <Component Id="IndexHtmlComponent" Directory="WWWDIR" Guid="*">
|
31
|
-
# <File Id="IndexHtmlFile" Source="path\to\index.html" KeyPath="yes"/>
|
32
|
-
# </Component>
|
33
|
-
def self.harvest_file_components(directory)
|
34
|
-
components = Array::new
|
35
|
-
Dir.chdir(directory) do
|
36
|
-
index = 0
|
37
|
-
Dir.glob("**/*").reject { |f| File.directory? f }.each { |f|
|
38
|
-
index += 1
|
39
|
-
component = get_indexed_file_component(f, index)
|
40
|
-
components.push(component)
|
41
|
-
}
|
42
|
-
components
|
43
|
-
end
|
44
|
-
end
|
45
|
-
# given a file and an index, return a string that represents a wix component
|
46
|
-
def self.get_indexed_file_component(file, index)
|
47
|
-
componentId = "c#{index}"
|
48
|
-
guid = SecureRandom.uuid
|
49
|
-
fileId = "f#{index}"
|
50
|
-
directory = File.dirname(file)
|
51
|
-
directory = directory.split(/[\/\\]/).last if File.dirname(file).include?("\\") || File.dirname(file).include?("/")
|
52
|
-
directory = "" if directory == "."
|
53
|
-
directoryId = "#{File.dirname(file).upcase.gsub("/", "_").gsub("-", "_")}DIR"
|
54
|
-
component = "<Component Id=\"#{componentId}\" Guid=\"#{guid}\"><File Id=\"#{fileId}\" Source=\"#{file}\" /></Component>"
|
55
|
-
if (directory.length > 0)
|
56
|
-
component = "<Component Id=\"#{componentId}\" Guid=\"#{guid}\" Directory=\"#{directoryId}\"><File Id=\"#{fileId}\" Source=\"#{file}\" /></Component>"
|
57
|
-
end
|
58
|
-
component
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raykit
|
4
|
+
class Wix
|
5
|
+
def self.harvest_directory_elements(directory)
|
6
|
+
get_nested_directory_element("", directory)
|
7
|
+
end
|
8
|
+
def self.get_nested_directory_element(id_prefix, directory)
|
9
|
+
Dir.chdir(directory) do
|
10
|
+
results = Array::new
|
11
|
+
Dir.glob("*").reject { |f| !File.directory? f }.each { |d|
|
12
|
+
directoryId = "#{d.upcase.gsub("/", "_").gsub("-", "_")}DIR"
|
13
|
+
directoryId = "#{id_prefix}#{directoryId}"
|
14
|
+
child_elements = get_nested_directory_element("#{directoryId[0...-3]}_", d)
|
15
|
+
if (child_elements.length > 0)
|
16
|
+
results.push("<Directory Id=\"#{directoryId}\" Name=\"#{d}\">")
|
17
|
+
child_elements.each { |child_element|
|
18
|
+
results.push("\t#{child_element}")
|
19
|
+
}
|
20
|
+
results.push("</Directory>")
|
21
|
+
else
|
22
|
+
results.push("<Directory Id=\"#{directoryId}\" Name=\"#{d}\"/>")
|
23
|
+
end
|
24
|
+
}
|
25
|
+
results
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# given a directory, return an array of string the represent wix components for each file in the directory
|
29
|
+
# each string should look like this:
|
30
|
+
# <Component Id="IndexHtmlComponent" Directory="WWWDIR" Guid="*">
|
31
|
+
# <File Id="IndexHtmlFile" Source="path\to\index.html" KeyPath="yes"/>
|
32
|
+
# </Component>
|
33
|
+
def self.harvest_file_components(directory)
|
34
|
+
components = Array::new
|
35
|
+
Dir.chdir(directory) do
|
36
|
+
index = 0
|
37
|
+
Dir.glob("**/*").reject { |f| File.directory? f }.each { |f|
|
38
|
+
index += 1
|
39
|
+
component = get_indexed_file_component(f, index)
|
40
|
+
components.push(component)
|
41
|
+
}
|
42
|
+
components
|
43
|
+
end
|
44
|
+
end
|
45
|
+
# given a file and an index, return a string that represents a wix component
|
46
|
+
def self.get_indexed_file_component(file, index)
|
47
|
+
componentId = "c#{index}"
|
48
|
+
guid = SecureRandom.uuid
|
49
|
+
fileId = "f#{index}"
|
50
|
+
directory = File.dirname(file)
|
51
|
+
directory = directory.split(/[\/\\]/).last if File.dirname(file).include?("\\") || File.dirname(file).include?("/")
|
52
|
+
directory = "" if directory == "."
|
53
|
+
directoryId = "#{File.dirname(file).upcase.gsub("/", "_").gsub("-", "_")}DIR"
|
54
|
+
component = "<Component Id=\"#{componentId}\" Guid=\"#{guid}\"><File Id=\"#{fileId}\" Source=\"#{file}\" /></Component>"
|
55
|
+
if (directory.length > 0)
|
56
|
+
component = "<Component Id=\"#{componentId}\" Guid=\"#{guid}\" Directory=\"#{directoryId}\"><File Id=\"#{fileId}\" Source=\"#{file}\" /></Component>"
|
57
|
+
end
|
58
|
+
component
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/raykit/wt.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
module Raykit
|
2
|
-
class Wt
|
3
|
-
def self.open(names)
|
4
|
-
if names.is_a? String
|
5
|
-
cmd = Raykit::Command.new("wt --maximized #{get_tab_arg(names)}").run
|
6
|
-
end
|
7
|
-
if names.is_a?(Array)
|
8
|
-
cmd = "wt --maximized "
|
9
|
-
index = 0
|
10
|
-
names.each { |url|
|
11
|
-
if index <= 0
|
12
|
-
cmd += get_tab_arg(url)
|
13
|
-
else
|
14
|
-
cmd += ";new-tab " + get_tab_arg(url)
|
15
|
-
end
|
16
|
-
index = index + 1
|
17
|
-
}
|
18
|
-
Raykit::Command.new(cmd).run
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.get_tab_arg(url)
|
23
|
-
dir = Raykit::Git::Repository.new(url).get_dev_dir("work")
|
24
|
-
name = File.basename(dir)
|
25
|
-
"-d #{dir} --title #{name}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module Raykit
|
2
|
+
class Wt
|
3
|
+
def self.open(names)
|
4
|
+
if names.is_a? String
|
5
|
+
cmd = Raykit::Command.new("wt --maximized #{get_tab_arg(names)}").run
|
6
|
+
end
|
7
|
+
if names.is_a?(Array)
|
8
|
+
cmd = "wt --maximized "
|
9
|
+
index = 0
|
10
|
+
names.each { |url|
|
11
|
+
if index <= 0
|
12
|
+
cmd += get_tab_arg(url)
|
13
|
+
else
|
14
|
+
cmd += ";new-tab " + get_tab_arg(url)
|
15
|
+
end
|
16
|
+
index = index + 1
|
17
|
+
}
|
18
|
+
Raykit::Command.new(cmd).run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_tab_arg(url)
|
23
|
+
dir = Raykit::Git::Repository.new(url).get_dev_dir("work")
|
24
|
+
name = File.basename(dir)
|
25
|
+
"-d #{dir} --title #{name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/raykit/zip.rb
CHANGED
@@ -1,73 +1,73 @@
|
|
1
|
-
require "zip"
|
2
|
-
|
3
|
-
module Raykit
|
4
|
-
class Zip
|
5
|
-
@filename
|
6
|
-
@source_dir
|
7
|
-
@include_globs
|
8
|
-
@exclude_globs
|
9
|
-
|
10
|
-
def initialize(filename)
|
11
|
-
@filename = filename
|
12
|
-
@source_dir = Dir.pwd
|
13
|
-
@include_globs = []
|
14
|
-
@exclude_globs = []
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def source_dir(dir)
|
19
|
-
@source_dir = dir
|
20
|
-
self
|
21
|
-
end
|
22
|
-
|
23
|
-
def include_glob(glob)
|
24
|
-
@include_globs << glob
|
25
|
-
self
|
26
|
-
end
|
27
|
-
|
28
|
-
def exclude_glob(glob)
|
29
|
-
@exclude_globs << glob
|
30
|
-
self
|
31
|
-
end
|
32
|
-
|
33
|
-
def zip
|
34
|
-
path = File.dirname(@filename)
|
35
|
-
FileUtils.mkdir_p(path) unless Dir.exist?(path)
|
36
|
-
|
37
|
-
files_to_archive = Array::new()
|
38
|
-
Dir.chdir(@source_dir) do
|
39
|
-
#include_files = []
|
40
|
-
@include_globs.each do |include_glob|
|
41
|
-
Dir.glob(include_glob) { |f|
|
42
|
-
#puts "\n" + f
|
43
|
-
files_to_archive << f if File.file?(f)
|
44
|
-
}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
::Zip::File::open(@filename, ::Zip::File::CREATE) { |zipfile|
|
49
|
-
count = 0
|
50
|
-
files_to_archive.each do |file|
|
51
|
-
zipfile.get_output_stream(file) { |f|
|
52
|
-
fr = ::File.open("#{@source_dir}/#{file}", "rb")
|
53
|
-
f.puts(fr.read)
|
54
|
-
fr.close()
|
55
|
-
f.close()
|
56
|
-
count = count + 1
|
57
|
-
}
|
58
|
-
end
|
59
|
-
zipfile.close
|
60
|
-
puts " added " << count.to_s << " files to " << @filename
|
61
|
-
}
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.zip_directory(directory, zipfile_name, overwrite = true)
|
65
|
-
File.delete(zipfile_name) if File.exist?(zipfile_name) && overwrite
|
66
|
-
::Zip::File.open(zipfile_name, ::Zip::File::CREATE) do |zipfile|
|
67
|
-
Dir[File.join(directory, "**", "**")].each do |file|
|
68
|
-
zipfile.add(file.sub(directory + "/", ""), file)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
1
|
+
require "zip"
|
2
|
+
|
3
|
+
module Raykit
|
4
|
+
class Zip
|
5
|
+
@filename
|
6
|
+
@source_dir
|
7
|
+
@include_globs
|
8
|
+
@exclude_globs
|
9
|
+
|
10
|
+
def initialize(filename)
|
11
|
+
@filename = filename
|
12
|
+
@source_dir = Dir.pwd
|
13
|
+
@include_globs = []
|
14
|
+
@exclude_globs = []
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def source_dir(dir)
|
19
|
+
@source_dir = dir
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def include_glob(glob)
|
24
|
+
@include_globs << glob
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def exclude_glob(glob)
|
29
|
+
@exclude_globs << glob
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def zip
|
34
|
+
path = File.dirname(@filename)
|
35
|
+
FileUtils.mkdir_p(path) unless Dir.exist?(path)
|
36
|
+
|
37
|
+
files_to_archive = Array::new()
|
38
|
+
Dir.chdir(@source_dir) do
|
39
|
+
#include_files = []
|
40
|
+
@include_globs.each do |include_glob|
|
41
|
+
Dir.glob(include_glob) { |f|
|
42
|
+
#puts "\n" + f
|
43
|
+
files_to_archive << f if File.file?(f)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
::Zip::File::open(@filename, ::Zip::File::CREATE) { |zipfile|
|
49
|
+
count = 0
|
50
|
+
files_to_archive.each do |file|
|
51
|
+
zipfile.get_output_stream(file) { |f|
|
52
|
+
fr = ::File.open("#{@source_dir}/#{file}", "rb")
|
53
|
+
f.puts(fr.read)
|
54
|
+
fr.close()
|
55
|
+
f.close()
|
56
|
+
count = count + 1
|
57
|
+
}
|
58
|
+
end
|
59
|
+
zipfile.close
|
60
|
+
puts " added " << count.to_s << " files to " << @filename
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.zip_directory(directory, zipfile_name, overwrite = true)
|
65
|
+
File.delete(zipfile_name) if File.exist?(zipfile_name) && overwrite
|
66
|
+
::Zip::File.open(zipfile_name, ::Zip::File::CREATE) do |zipfile|
|
67
|
+
Dir[File.join(directory, "**", "**")].each do |file|
|
68
|
+
zipfile.add(file.sub(directory + "/", ""), file)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|