-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
40 lines (33 loc) · 1.06 KB
/
install.rb
1
2
3
4
5
6
7
8
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
#!/usr/bin/env ruby
aRequirePatterns = [/^\s*require\s+['"](\S+?)['"];\s*#\s*(gem\s+install\s+.*)?/];
# check the necessary gems to install
hInstalls = {};
puts("> Reading scripts ...");
Dir.glob('./backend/**/*.rb') { |sScriptPath|
puts(" - #{sScriptPath}");
sScriptText = File.read(sScriptPath);
aRequirePatterns.each { |reRequirePattern|
sScriptText.scan(reRequirePattern) {
sGem = $1;
sInstall = $2; # gem install command
# include it in the hash of gems to install
hInstalls[sInstall] = [] unless hInstalls[sInstall];
hInstalls[sInstall] << sGem.downcase;
}
}
}
puts("\n> List of required gems:");
hInstalls.each { |sInstall, aGems|
puts("- #{sInstall}, for gem: '#{aGems.uniq.join(',')}'");
}
print("\nInstall gems? [y/n]: ");
sAnswer = STDIN.gets.strip.downcase;
if (sAnswer == 'y')
hInstalls.each_key { |sInstall|
puts('-' * 100);
puts("> Executing: #{sInstall}");
puts(%x(#{sInstall}));
puts('=' * 100);
}
end
puts("* Done!");