Class: Lono::AppFile::Build
- Inherits:
-
Base
show all
- Defined in:
- lib/lono/app_file/build.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
#initialize, #reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Instance Method Details
#build_all ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/lono/app_file/build.rb', line 15
def build_all
clean_output
copy_to_output
Registry.items.each do |item|
if item.directory?
zip_directory(item)
elsif item.file?
zip_file(item)
else
puts "WARN: #{item.path} does not exist. Double check that the path is correct in the s3_key call.".color(:yellow)
end
end
end
|
#clean_output ⇒ Object
69
70
71
|
# File 'lib/lono/app_file/build.rb', line 69
def clean_output
FileUtils.rm_rf(@output_files_path)
end
|
#copy_to_output ⇒ Object
29
30
31
32
33
|
# File 'lib/lono/app_file/build.rb', line 29
def copy_to_output
override_source_paths("#{Lono.blueprint_root}/app/files")
self.destination_root = @output_files_path
directory(".", verbose: false, context: context.get_binding) end
|
#detect_files? ⇒ Boolean
73
74
75
76
77
78
79
80
81
|
# File 'lib/lono/app_file/build.rb', line 73
def detect_files?
app_files = Dir["#{Lono.blueprint_root}/app/files/*"]
if app_files.empty?
false
else
puts "Detected app/files for blueprint #{@blueprint}"
true
end
end
|
#initialize_variables ⇒ Object
5
6
7
|
# File 'lib/lono/app_file/build.rb', line 5
def initialize_variables
@output_files_path = "#{Lono.config.output_path}/#{@blueprint}/files"
end
|
#run ⇒ Object
9
10
11
12
13
|
# File 'lib/lono/app_file/build.rb', line 9
def run
return unless detect_files?
puts "Building app/files for blueprint #{@blueprint}"
build_all
end
|
#zip(command) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/lono/app_file/build.rb', line 59
def zip(command)
`#{command}`
unless $?.success?
puts "ERROR: Fail to run #{command}".color(:red)
puts "Maybe zip is not installed or path is incorrect?"
exit 1
end
end
|
#zip_directory(item) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/lono/app_file/build.rb', line 49
def zip_directory(item)
path = item.path
zip_file = item.zip_file_name
puts "Zipping folder and generating md5 named file from: #{path}"
command = "cd #{path} && zip --symlinks -rq #{zip_file} ." zip(command)
FileUtils.mv("#{path}/#{zip_file}", "#{File.dirname(path)}/#{zip_file}") end
|
#zip_file(item) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/lono/app_file/build.rb', line 40
def zip_file(item)
path = item.path
zip_file = item.zip_file_name
puts "Zipping file and generating md5 named file from: #{path}"
command = "cd #{File.dirname(path)} && zip -q #{zip_file} #{File.basename(path)}" zip(command)
end
|