22
23
24
25
26
27
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/rdm/packages/compiler_service.rb', line 22
def compile
FileUtils.rm_rf(@compile_path) if Dir.exists?(@compile_path)
FileUtils.mkdir_p(@compile_path)
dependent_packages = Rdm::Handlers::DependenciesHandler.show_packages(
package_name: @package_name,
project_path: @project_path
)
dependent_packages.each do |pkg|
rel_path = Pathname.new(pkg.path).relative_path_from(Pathname.new(@project_path))
new_path = File.dirname(File.join(@compile_path, rel_path))
FileUtils.mkdir_p(new_path)
FileUtils.cp_r(pkg.path, new_path)
end
source_rdm_path = File.join(@project_path, Rdm::SOURCE_FILENAME)
dest_rdm_path = File.join(@compile_path, Rdm::SOURCE_FILENAME)
package_definition_regex = /package\s+['"]([\w\/]+)['"]/i
File.open(dest_rdm_path, "w") do |out_file|
File.foreach(source_rdm_path) do |line|
package_line = package_definition_regex.match(line)
if package_line.nil?
out_file.puts line
else
dependent_package_definition = dependent_packages.detect do |pkg|
package_line[1] == Pathname.new(pkg.path).relative_path_from(Pathname.new(@project_path)).to_s
end
out_file.puts line if dependent_package_definition.present?
end
end
end
FileUtils.cp_r(File.join(@project_path, 'configs'), File.join(@compile_path, 'configs'))
if Dir.exists?(File.join(@project_path, Rdm.settings.env_files_dir))
FileUtils.cp_r(
File.join(@project_path, Rdm.settings.env_files_dir),
File.join(@compile_path, Rdm.settings.env_files_dir)
)
end
Rdm.settings.compile_ignore_files.each do |file|
Dir["#{@compile_path}/**/#{file}"].each do |file_to_remove|
FileUtils.rm_rf(file_to_remove)
end
end
Rdm.settings.compile_add_files.each do |file|
FileUtils.cp(File.join(@project_path, file), File.join(@compile_path, file))
end
return dependent_packages.map(&:name)
end
|