-
Notifications
You must be signed in to change notification settings - Fork 816
/
Rakefile
92 lines (79 loc) · 2.87 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
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__)))
$: << File.join(ROOT_PATH, 'janus', 'ruby')
require 'janus'
require 'fileutils'
include Janus
desc "link ViM configuration files."
task :link_vim_conf_files do
%w[ vimrc gvimrc ].each do |file|
dest = expand("~/.#{file}")
unless File.exist?(dest)
require 'rbconfig'
source = expand("../janus/vim/#{file}", __FILE__)
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
require 'open3'
dest.gsub!(?/, ?\\)
source.gsub!(?/, ?\\)
puts "cmd.exe /c mklink #{dest} #{source}"
stdin, stdout, stderr, wait_thr = Open3.popen3('cmd.exe', "/c mklink #{dest} #{source}")
wait_thr.value.exitstatus
else
ln_s(source, dest)
end
end
end
end
namespace :dev do
desc "Update submodules"
task :update_submodules do
sh "git submodule foreach 'git fetch origin && git reset --hard origin/master'"
end
# Taken from RefineryCMD
# https://github.com/resolve/refinerycms/blob/master/core/lib/tasks/refinery.rake
desc 'Removes trailing whitespace across the entire application.'
task :whitespace do
require 'rbconfig'
if RbConfig::CONFIG['host_os'] =~ /linux/
sh %{find . -name '*.*rb' -o -name '*.*vim' -exec sed -i 's/\t/ /g' {} \\; -exec sed -i 's/ *$//g' {} \\; }
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
sh %{find . -name '*.*rb' -o -name '*.*vim' -exec sed -i '' 's/\t/ /g' {} \\; -exec sed -i '' 's/ *$//g' {} \\; }
else
puts "This doesn't work on systems other than OSX or Linux. Please use a custom whitespace tool for your platform '#{RbConfig::CONFIG["host_os"]}'."
end
end
end
desc "Create necessary folders."
task :folders do
Janus::VIM.folders.each do |folder|
mkdir_p folder
end
end
task :update do
is_windows = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
redirect_out = is_windows ? '> NUL' : '> /dev/null'
redirect_out_err = is_windows ? '> NUL 2> NUL' : '&> /dev/null'
puts "Cleaning the janus folder"
`git clean -xdf -- janus #{redirect_out_err}`
`git ls-files --exclude-standard --others -- janus`.split("\n").each do |untracked|
FileUtils.rm_rf File.expand_path(untracked.chomp, File.dirname(__FILE__))
end
puts "Pulling latest changes"
`git pull #{redirect_out}`
puts "Cleaning the janus folder"
`git clean -xdf -- janus #{redirect_out_err}`
`git ls-files --exclude-standard --others -- janus`.split("\n").each do |untracked|
FileUtils.rm_rf File.expand_path(untracked.chomp, File.dirname(__FILE__))
end
puts "Synchronising submodules urls"
`git submodule sync #{redirect_out}`
puts "Updating the submodules"
`git submodule update --init #{redirect_out}`
end
task :install => [:folders, :link_vim_conf_files] do
# Dummy task, real work is done with the hooks.
end
desc "Install or Update Janus."
task :default do
sh "rake update"
sh "rake install"
end