|
| 1 | +# written by travis jeffery <[email protected]> |
| 2 | +# contributions by scrooloose <github:scrooloose> |
| 3 | + |
| 4 | +require 'rake' |
| 5 | +require 'find' |
| 6 | +require 'pathname' |
| 7 | + |
| 8 | +IGNORE = [/\.gitignore$/, /Rakefile$/] |
| 9 | + |
| 10 | +files = `git ls-files`.split("\n") |
| 11 | +files.reject! { |f| IGNORE.any? { |re| f.match(re) } } |
| 12 | + |
| 13 | +desc 'Zip up the project files' |
| 14 | +task :zip do |
| 15 | + zip_name = File.basename(File.dirname(__FILE__)) |
| 16 | + zip_name.gsub!(/ /, '_') |
| 17 | + zip_name = "#{zip_name}.zip" |
| 18 | + |
| 19 | + if File.exist?(zip_name) |
| 20 | + abort("Zip file #{zip_name} already exists. Remove it first.") |
| 21 | + end |
| 22 | + |
| 23 | + puts "Creating zip file: #{zip_name}" |
| 24 | + system("zip #{zip_name} #{files.join(" ")}") |
| 25 | +end |
| 26 | + |
| 27 | +desc 'Install plugin and documentation' |
| 28 | +task :install do |
| 29 | + vimfiles = if ENV['VIMFILES'] |
| 30 | + ENV['VIMFILES'] |
| 31 | + elsif RUBY_PLATFORM =~ /(win|w)32$/ |
| 32 | + File.expand_path("~/vimfiles") |
| 33 | + else |
| 34 | + File.expand_path("~/.vim") |
| 35 | + end |
| 36 | + files.each do |file| |
| 37 | + target_file = File.join(vimfiles, file) |
| 38 | + FileUtils.mkdir_p File.dirname(target_file) |
| 39 | + FileUtils.cp file, target_file |
| 40 | + |
| 41 | + puts "Installed #{file} to #{target_file}" |
| 42 | + end |
| 43 | + |
| 44 | +end |
| 45 | + |
| 46 | +desc 'Pulls from origin' |
| 47 | +task :pull do |
| 48 | + puts "Updating local repo..." |
| 49 | + system("cd " << Dir.new(File.dirname(__FILE__)).path << " && git pull") |
| 50 | +end |
| 51 | + |
| 52 | +desc 'Calls pull task and then install task' |
| 53 | +task :update => ['pull', 'install'] do |
| 54 | + puts "Update of vim script complete." |
| 55 | +end |
| 56 | + |
| 57 | +desc 'Uninstall plugin and documentation' |
| 58 | +task :uninstall do |
| 59 | + vimfiles = if ENV['VIMFILES'] |
| 60 | + ENV['VIMFILES'] |
| 61 | + elsif RUBY_PLATFORM =~ /(win|w)32$/ |
| 62 | + File.expand_path("~/vimfiles") |
| 63 | + else |
| 64 | + File.expand_path("~/.vim") |
| 65 | + end |
| 66 | + files.each do |file| |
| 67 | + target_file = File.join(vimfiles, file) |
| 68 | + FileUtils.rm target_file |
| 69 | + |
| 70 | + puts "Uninstalled #{target_file}" |
| 71 | + end |
| 72 | + |
| 73 | +end |
| 74 | + |
| 75 | +task :default => ['update'] |
0 commit comments