9
10
11
12
13
14
15
16
17
18
19
20
21
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
|
# File 'lib/digipolitan-framework-swift-template-cli/init.rb', line 9
def self.init(target_path = nil)
zip_path = ".template.zip"
unzip_destination_path = ".template"
Digipolitan::UI.success "*** DIGIPOLITAN TEMPLATE FRAMEWORK WIZARD ***";
absolute_target_path = Dir.pwd
if target_path != nil && target_path != "."
absolute_target_path = File.join(absolute_target_path, target_path)
end
if Digipolitan::UI.confirm "Are you sure to install the Digipolitan template in the directory '#{absolute_target_path}'"
Digipolitan::UI.message "Preparing...";
Digipolitan::FileUtils.mkdir_p(absolute_target_path)
pattern = File.join(absolute_target_path, "*.xcodeproj")
projects = Dir[pattern]
if projects.length > 0
Digipolitan::UI.crash "The target directory contains an xcodeproj, please select another one or clear the directory."
end
Digipolitan::UI.message "Downloading Digipolitan framework...";
buffer = open('https://github.com/Digipolitan/framework-swift-template/archive/master.zip').read
Digipolitan::FileUtils.write_to_file(zip_path, buffer)
Digipolitan::UI.message "Unziping Digipolitan framework...";
template_path = nil
Digipolitan::FileUtils.remove_dir(unzip_destination_path)
Zip::InputStream.open(zip_path) { |zip_file|
while (entry = zip_file.get_next_entry)
f_path = File.join(unzip_destination_path, entry.name)
if template_path == nil
template_path = f_path
end
if entry.name_is_directory?
Digipolitan::FileUtils.mkdir_p(f_path)
else
Digipolitan::FileUtils.mkdir_p(File.dirname(f_path))
entry.(f_path)
end
end
}
Digipolitan::UI.message "Moving..."
entries = Dir.entries(template_path)
entries.each do |entry|
if entry != "." && entry != ".."
File.rename(File.join(template_path, entry), File.join(absolute_target_path, entry))
end
end
Digipolitan::FileUtils.remove_dir(zip_path)
Digipolitan::FileUtils.remove_dir(unzip_destination_path)
Digipolitan::UI.success "Successfully download Digipolitan framework template"
if Digipolitan::UI.confirm "Would you like to install the template ?"
gemfile = File.join(absolute_target_path, "Gemfile")
Dir.chdir(absolute_target_path) {
system("bundle install --gemfile '#{gemfile}'")
system("BUNDLE_GEMFILE='#{gemfile}' bundle exec ruby install.rb")
}
end
end
end
|