-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
138 lines (120 loc) · 3.8 KB
/
Rakefile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require 'rake'
require 'yaml'
def load_plugin_urls
yaml_file = File.open(File.join(File.dirname(__FILE__), 'plugins.yml'))
yaml = YAML.load(yaml_file)
yaml['plugins']
end
def plugin_urls
@plugins ||= load_plugin_urls
end
PLUGINS_WITH_MAKE = {}
PLUGINS_WITH_RAKE = {}
FOLDERS = %w(after autoload colors compiler doc ftdetect ftplugin indent lib macros nerdtree_plugin plugin pythonx rplugin ruby snippets UltiSnips syntax syntax_checkers utils)
PLUGINS_WITHOUT_RAKE = plugin_urls.keys
PLUGINS = PLUGINS_WITHOUT_RAKE + PLUGINS_WITH_RAKE.keys + PLUGINS_WITH_MAKE.keys
if ENV['NEO'] == 'true'
DOTVIM = "#{ENV['HOME']}/.config/nvim"
else
DOTVIM = "#{ENV['HOME']}/.vim"
end
desc "Get latest on all plugins"
task :preinstall do
FileUtils.mkdir_p('plugins')
in_directory('plugins') do
if ENV['PLUGIN'].nil?
PLUGINS.each do |plugin|
get_latest(plugin)
end
else
get_latest(ENV['PLUGIN'])
end
end
end
def get_latest(plugin)
if File.directory?(plugin)
in_directory(plugin) { update_current_dir }
elsif plugin_urls[plugin]
clone_project(plugin, plugin_urls[plugin])
end
end
def clone_project(name, script_url_yaml)
system("git clone #{plugin_urls[name]['git']} #{name} && git submodule update --init --recursive") if script_url_yaml['git']
system("hg clone #{plugin_urls[name]['hg']} #{name}") if script_url_yaml['hg']
system("svn checkout #{plugin_urls[name]['svn']} #{name}") if script_url_yaml['svn']
end
def update_current_dir
system('git pull origin master && git submodule update --init --recursive') if File.directory?('.git')
system('hg pull && hg update') if File.directory?('.hg')
system('svn up') if File.directory?('.svn')
end
def in_directory(directory)
original_dir = Dir.pwd
Dir.chdir directory
yield
Dir.chdir original_dir
end
desc "Install the files into ~/.vim"
task :install do
FileUtils.mkdir_p FOLDERS.map{|f| "#{DOTVIM}/#{f}" }
FileUtils.mkdir_p "#{DOTVIM}/tmp"
in_directory('plugins') do
install_plugins(PLUGINS_WITH_RAKE, 'rake')
install_plugins(PLUGINS_WITH_MAKE, 'make')
end
copy_dot_files
in_directory('plugins') do
PLUGINS_WITHOUT_RAKE.each do |plugin|
if !File.directory?(plugin)
puts "#{plugin} doesn't exist. Please run 'rake preinstall'"
else
if File.directory?("#{plugin}/.svn")
in_directory(plugin) { system("svn export . --force #{DOTVIM}") }
else
puts "installing #{plugin}"
directory = plugin_urls[plugin]['directory'] || '.'
FOLDERS.each do |f|
in_directory("#{plugin}/#{directory}") { FileUtils.cp_r Dir["#{f}/*"], "#{DOTVIM}/#{f}" }
end
end
end
system(plugin_urls[plugin]['post_install']) if plugin_urls[plugin] && plugin_urls[plugin]['post_install']
end
end
end
def install_plugins(plugins, command)
plugins.each do |plugin, task|
if !File.directory?(plugin)
puts "#{plugin} doesn't exist. Please run 'rake preinstall'"
else
puts "making #{plugin}"
in_directory(plugin) { system "#{command} #{task}" }
end
end
end
def copy_dot_files
link_if_it_doesnt_exist('vimrc')
link_if_it_doesnt_exist('gvimrc')
end
def link_if_it_doesnt_exist(file, condition = 'f')
system(<<-EOSCRIPT
if [ ! -#{condition} $HOME/.#{file} ]; then
ln -s $PWD/#{file} $HOME/.#{file}
echo "Linking .#{file}"
else
echo "Skipping .#{file}, it already exists"
fi
EOSCRIPT
)
end
task :default => :install
desc "Remove everything in ~/.vim"
task :uninstall do
FileUtils.rm_rf DOTVIM
end
desc "Blow everything out and try again."
task :reinstall => [:uninstall, :preinstall, :install]
desc "Get latest on all plugins"
task :update => [:preinstall, :install]
desc "Get latest on all plugins and reinstall from scratch"
task :clean_update => [:preinstall, :reinstall]