Class: Lono::AppFile::Build
- Inherits:
-
Base
- Object
- Base
- Lono::AppFile::Build
show all
- Defined in:
- lib/lono/app_file/build.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
#bundler_groups, #find_blueprint_root, #require_bundle_gems, #set_blueprint_root
Instance Method Details
#build_all ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/lono/app_file/build.rb', line 14
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
57
58
59
|
# File 'lib/lono/app_file/build.rb', line 57
def clean_output
FileUtils.rm_rf(@output_files_path)
end
|
#copy_to_output ⇒ Object
61
62
63
64
65
66
|
# File 'lib/lono/app_file/build.rb', line 61
def copy_to_output
src = "#{Lono.blueprint_root}/app/files"
dest = @output_files_path
FileUtils.mkdir_p(File.dirname(dest))
FileUtils.cp_r(src, dest)
end
|
#detect_files? ⇒ Boolean
68
69
70
71
72
73
74
75
76
|
# File 'lib/lono/app_file/build.rb', line 68
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
3
4
5
|
# File 'lib/lono/app_file/build.rb', line 3
def initialize_variables
@output_files_path = "#{Lono.config.output_path}/#{@blueprint}/files"
end
|
#run ⇒ Object
7
8
9
10
11
12
|
# File 'lib/lono/app_file/build.rb', line 7
def run
return unless detect_files?
puts "Building app/files for blueprint #{@blueprint}"
build_all
end
|
#zip(command) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/lono/app_file/build.rb', line 47
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
37
38
39
40
41
42
43
44
45
|
# File 'lib/lono/app_file/build.rb', line 37
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
28
29
30
31
32
33
34
35
|
# File 'lib/lono/app_file/build.rb', line 28
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
|