-
Notifications
You must be signed in to change notification settings - Fork 79
/
upgrade-extension.rb
57 lines (43 loc) · 1.15 KB
/
upgrade-extension.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'fileutils'
extension_name = %w{
bootstrap-sass
compass-960-plugin
compass-h5bp
compass-normalize
html5-boilerplate
susy
}
tmp_dir = 'tmp_ext'
ext_lib_dir = 'lib/ruby/compass_extensions'
puts "fetch gems..."
`gem install -i #{tmp_dir} #{extension_name.join(" ")}`
def parse_ext_version(dir, ext_name)
`ls #{dir}`.split("\n").reduce({}) do |hash, g|
ext_name.each do |ext|
if g =~ /#{ext}/
hash[ext] = g.split("-")[-1]
end
end
hash
end
end
lastest_versions = parse_ext_version("#{tmp_dir}/gems", extension_name)
local_versions = parse_ext_version("#{ext_lib_dir}", extension_name)
commits = []
lastest_versions.keys.each do |g|
local = local_versions[g] || "0"
lastest = lastest_versions[g]
if lastest > local
puts "upgrade #{g} from #{local} to #{lastest}"
commits << "#{g} #{local} -> #{lastest}"
FileUtils.rm_rf( "#{ext_lib_dir}/#{g}-#{local}")
FileUtils.cp_r( "#{tmp_dir}/gems/#{g}-#{lastest}", "#{ext_lib_dir}" )
end
end
FileUtils.rm_rf( "#{tmp_dir}" )
if commits.length == 0
puts "\nAll extensions are the lastest version."
else
puts "\nCommmit:"
puts commits.join(", ")
end