vimpack 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/.autotest +13 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE +21 -0
  7. data/README.md +47 -0
  8. data/Rakefile +5 -0
  9. data/autotest/discover.rb +2 -0
  10. data/bin/vimpack +103 -0
  11. data/cucumber.yml +13 -0
  12. data/features/commands/environments.feature +26 -0
  13. data/features/commands/git.feature +77 -0
  14. data/features/commands/info.feature +28 -0
  15. data/features/commands/init.feature +47 -0
  16. data/features/commands/install.feature +50 -0
  17. data/features/commands/list.feature +18 -0
  18. data/features/commands/search.feature +137 -0
  19. data/features/commands/uninstall.feature +46 -0
  20. data/features/step_definitions/environment_steps.rb +3 -0
  21. data/features/step_definitions/file_utils_steps.rb +36 -0
  22. data/features/step_definitions/initialize_steps.rb +14 -0
  23. data/features/step_definitions/output_steps.rb +12 -0
  24. data/features/step_definitions/vimpack_git_steps.rb +91 -0
  25. data/features/support/env.rb +11 -0
  26. data/features/support/executable_paths.rb +15 -0
  27. data/lib/vimpack/commands/command.rb +46 -0
  28. data/lib/vimpack/commands/git.rb +32 -0
  29. data/lib/vimpack/commands/info.rb +26 -0
  30. data/lib/vimpack/commands/init.rb +23 -0
  31. data/lib/vimpack/commands/install.rb +35 -0
  32. data/lib/vimpack/commands/list.rb +14 -0
  33. data/lib/vimpack/commands/search.rb +37 -0
  34. data/lib/vimpack/commands/uninstall.rb +27 -0
  35. data/lib/vimpack/commands.rb +8 -0
  36. data/lib/vimpack/models/apibase.rb +7 -0
  37. data/lib/vimpack/models/base.rb +29 -0
  38. data/lib/vimpack/models/repo.rb +117 -0
  39. data/lib/vimpack/models/script.rb +110 -0
  40. data/lib/vimpack/models.rb +8 -0
  41. data/lib/vimpack/utils/api.rb +39 -0
  42. data/lib/vimpack/utils/file.rb +66 -0
  43. data/lib/vimpack/utils/file_path.rb +25 -0
  44. data/lib/vimpack/utils/git.rb +103 -0
  45. data/lib/vimpack/utils/github.rb +41 -0
  46. data/lib/vimpack/utils/io.rb +26 -0
  47. data/lib/vimpack/utils/process.rb +61 -0
  48. data/lib/vimpack/utils/vimscripts.rb +64 -0
  49. data/lib/vimpack/version.rb +4 -0
  50. data/lib/vimpack.rb +46 -0
  51. data/simplecov_setup.rb +5 -0
  52. data/spec/spec_helper.rb +32 -0
  53. data/spec/vimpack/models/repo_spec.rb +150 -0
  54. data/spec/vimpack/models/script_spec.rb +230 -0
  55. data/spec/vimpack/utils/github_spec.rb +39 -0
  56. data/spec/vimpack/utils/vimscripts_spec.rb +38 -0
  57. data/tasks/cucumber.rake +8 -0
  58. data/tasks/default.rake +2 -0
  59. data/tasks/rspec.rake +5 -0
  60. data/templates/vimrc.erb +6 -0
  61. data/vimpack.gemspec +42 -0
  62. metadata +333 -0
@@ -0,0 +1,3 @@
1
+ Given /^"([^"]*)" is my home directory$/ do |dir_name|
2
+ set_env "HOME", File.expand_path(File.join(current_dir, dir_name))
3
+ end
@@ -0,0 +1,36 @@
1
+ def check_git_repo(path)
2
+ prep_for_fs_check do
3
+ res = %x{ cd #{path} ; git status ; cd - }
4
+ res.should_not match(/Not a git repo/)
5
+ end
6
+ end
7
+
8
+ def check_git_submodule(submodule, repo)
9
+ name = submodule.split('/')[-1]
10
+ prep_for_fs_check do
11
+ res = %x{ cd #{repo} ; git submodule ; cd - }
12
+ res.should match(/#{name}/)
13
+ end
14
+ end
15
+
16
+ Then /^a directory named "([^"]*)" should exist and be a git repo$/ do |directory|
17
+ check_directory_presence([directory], true)
18
+ check_git_repo(directory)
19
+ end
20
+
21
+ Then /^a symlink named "([^"]*)" should exist and link to "([^"]*)"$/ do |link, target|
22
+ File.should exist(File.join(@dirs, link))
23
+ require 'pathname'
24
+ Pathname.new(File.join(@dirs, link)).realpath.to_s.gsub('/private', '').should == File.join(@dirs, target)
25
+ end
26
+
27
+ Then /^a symlink named "([^"]*)" should not exist$/ do |link|
28
+ File.exists?(File.join(@dirs, link)).should be_false
29
+ end
30
+
31
+ Then /^a directory named "([^"]*)" should exist and be a git submodule of "([^"]*)"$/ do |submodule, repo|
32
+ check_directory_presence([repo], true)
33
+ check_directory_presence([submodule], true)
34
+ check_git_submodule(submodule, repo)
35
+ end
36
+
@@ -0,0 +1,14 @@
1
+ Given /^an initialized vimpack in "([^"]*)"$/ do |homedir|
2
+ steps %Q{
3
+ Given a directory named "#{homedir}/.vim"
4
+ And an empty file named "#{homedir}/.vimrc"
5
+ And "#{homedir}" is my home directory
6
+ When I run `vimpack -e development init`
7
+ Then the output should contain "vimpack initialized!"
8
+ }
9
+ end
10
+
11
+ Given /^"([^"]*)" is already installed$/ do |script_name|
12
+ steps %Q{ Given I run `vimpack -e development install #{script_name}` }
13
+ end
14
+
@@ -0,0 +1,12 @@
1
+ Then /^show me the output$/ do
2
+ puts all_output
3
+ end
4
+
5
+ Then /^show me the stdout$/ do
6
+ puts all_stdout
7
+ end
8
+
9
+ Then /^show me the stderr$/ do
10
+ puts all_stderr
11
+ end
12
+
@@ -0,0 +1,91 @@
1
+ def check_vimpack_remote(remote_name, url)
2
+ prep_for_fs_check do
3
+ res = %x{ cd test_vimpack/.vimpack ; git config -l ; cd - }
4
+ res.should match(/remote.#{Regexp.escape(remote_name)}.url=#{Regexp.escape(url)}/)
5
+ end
6
+ end
7
+
8
+ def check_vimpack_last_commit_log(message)
9
+ prep_for_fs_check do
10
+ res = %x{ cd test_vimpack/.vimpack ; git log -1 ; cd - }
11
+ res.should match(/#{Regexp.escape(message)}/)
12
+ end
13
+ end
14
+
15
+ def check_vimpack_status
16
+ prep_for_fs_check do
17
+ res = %x{ cd test_vimpack/.vimpack ; git status ; cd - }
18
+ res.should match(/#{Regexp.escape('nothing to commit')}/)
19
+ end
20
+ end
21
+
22
+ def initialize_git_repo(path)
23
+ prep_for_fs_check do
24
+ @full_path = File.join(File.expand_path(FileUtils.pwd), @path)
25
+ end
26
+ FileUtils.rmtree(@full_path).should be_true if File::directory?(@full_path)
27
+ FileUtils.mkdir(@full_path).should be_true
28
+ res = %x( git init --bare #{@full_path} )
29
+ $?.should eq(0)
30
+ end
31
+
32
+
33
+ Then /^the vimpack git remote "([^"]*)" should be "([^"]*)"$/ do |remote_name, url|
34
+ check_vimpack_remote(remote_name, url)
35
+ end
36
+
37
+ Then /^the vimpack git commit logs last message should be "([^"]*)"$/ do |message|
38
+ check_vimpack_last_commit_log(message)
39
+ end
40
+
41
+ Then /^the vimpack git status should be empty$/ do
42
+ check_vimpack_status
43
+ end
44
+
45
+ Given /^an initialized git repo in "([^"]*)"$/ do |path|
46
+ @path = path
47
+ @full_path = nil
48
+ initialize_git_repo(@path)
49
+ end
50
+
51
+ Given /^an existing git repo in "([^"]*)"$/ do |path|
52
+ steps %Q{
53
+ Given an initialized git repo in "#{path}"
54
+ And I run `vimpack -e development git remote add origin /tmp/aruba/#{path}`
55
+ When I run `vimpack -e development git publish -m '[TEST] testing vimpack'`
56
+ Then the exit status should be 0
57
+ And the output should contain:
58
+ """
59
+ * publishing vimpack repo
60
+ vimpack repo published!
61
+ """
62
+ And the vimpack git remote "origin" should be "/tmp/aruba/#{path}"
63
+ }
64
+ end
65
+
66
+ Given /^an initialized vimpack in "([^"]*)" from remote "([^"]*)"$/ do |homedir, remote_path|
67
+ steps %Q{
68
+ Given a directory named "#{homedir}/.vim"
69
+ And an empty file named "#{homedir}/.vimrc"
70
+ And "#{homedir}" is my home directory
71
+ When I run `vimpack -e development init /tmp/aruba/#{remote_path}`
72
+ Then the exit status should be 0
73
+ And the output should contain "vimpack initialized!"
74
+ And the vimpack git remote "origin" should be "/tmp/aruba/#{remote_path}"
75
+ }
76
+ end
77
+
78
+ Given /^an initialized vimpack in "([^"]*)" that is out of sync with its remote$/ do |path|
79
+ steps %Q{
80
+ Given an initialized vimpack in "#{path}"
81
+ And "rails.vim" is already installed
82
+ And an existing git repo in "vimpack-repo"
83
+ And an initialized vimpack in "test_vimpack_remoted" from remote "vimpack-repo"
84
+ And "#{path}" is my home directory
85
+ And "cucumber.zip" is already installed
86
+ And I run `vimpack -e development git publish -m '[CUKE] added cucumber.zip'`
87
+ And "test_vimpack_remoted" is my home directory
88
+ And "haml.zip" is already installed
89
+ }
90
+ end
91
+
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__), '..', '..', 'lib')
2
+ require 'vimpack'
3
+ require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
4
+ require 'aruba/cucumber'
5
+
6
+ Before do
7
+ FileUtils.rmtree('/tmp/aruba')
8
+ @dirs = ["/tmp/aruba"]
9
+ @aruba_timeout_seconds = 60
10
+ end
11
+
@@ -0,0 +1,15 @@
1
+ #module ArubaOverrides
2
+ # def detect_ruby_script(cmd)
3
+ # puts "CMD IS: #{cmd}"
4
+ # if cmd =~ /^vimpack /
5
+ # lib_path = File.join(File.dirname(__FILE__), '..', '..', 'lib')
6
+ # cmd_path = File.join(File.dirname(__FILE__), '..', '..', 'bin', cmd)
7
+ # puts "RUNNING VIMPACK!"
8
+ # "ruby -I#{lib_path} -S #{cmd_path}"
9
+ # else
10
+ # super(cmd)
11
+ # end
12
+ # end
13
+ #end
14
+ #
15
+ #World(ArubaOverrides)
@@ -0,0 +1,46 @@
1
+ module Vimpack
2
+ module Commands
3
+ class Command
4
+ include ::Vimpack::Utils::File
5
+ include ::Vimpack::Utils::Io
6
+ include ::Vimpack::Utils::Git
7
+ include ::Vimpack::Utils::Process
8
+
9
+ def initialize(options, global_options)
10
+ @options = options
11
+ @global_options = global_options
12
+ @commands = ARGV
13
+ setup_paths(@options[:home_directory] || ENV['HOME'])
14
+ initialize_environment
15
+ initialize_global_options
16
+ initialize_options
17
+ initialize_commands
18
+ end
19
+
20
+ def initialize_environment
21
+ Vimpack.environment = @global_options[:environment].to_sym
22
+ unless Vimpack.env?('production')
23
+ say(" * using environment #{Vimpack.environment.inspect}")
24
+ end
25
+ end
26
+
27
+ def initialize_global_options
28
+ end
29
+
30
+ def initialize_options
31
+ end
32
+
33
+ def initialize_commands
34
+ end
35
+
36
+ def run
37
+ raise NotImplemented
38
+ end
39
+
40
+ def self.run(options = Hash.new, commands = Hash.new)
41
+ new(options, commands).run
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,32 @@
1
+ module Vimpack
2
+ module Commands
3
+ class Git < Command
4
+ SUB_COMMANDS = %w{ publish }
5
+
6
+ def initialize_commands
7
+ die!("git requires at least one argument") if @commands.size < 1
8
+ @subcommand = @commands.shift
9
+ end
10
+
11
+ def run
12
+ return git_exec unless SUB_COMMANDS.include?(@subcommand)
13
+ send("git_#{@subcommand}".to_sym)
14
+ end
15
+
16
+ def git_publish
17
+ say(" * publishing vimpack repo")
18
+ Vimpack::Models::Repo.publish!(@options[:message])
19
+ say("vimpack repo published!")
20
+ end
21
+
22
+ def git_exec
23
+ say(" * running git #{@subcommand} #{@commands.join(' ')}")
24
+ command = Vimpack::Models::Repo.git_exec(@subcommand, @commands)
25
+ say("command complete!")
26
+ say(command.message, :default)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,26 @@
1
+ module Vimpack
2
+ module Commands
3
+ class Info < Command
4
+
5
+ def initialize_commands
6
+ die!("info requires a single argument") unless @commands.size == 1
7
+ @script_name = @commands[0]
8
+ end
9
+
10
+ def run
11
+ begin
12
+ script = Vimpack::Models::Script.info(@script_name)
13
+ rescue Vimpack::Models::Script::ScriptNotFound
14
+ return exit_with_error!('Script not found!')
15
+ end
16
+ say("Name: #{script.name}")
17
+ say("Author: #{script.author}")
18
+ say("Version: #{script.version} (#{script.version_date})")
19
+ say("Type: #{script.type}")
20
+ say("Description: #{script.description}")
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,23 @@
1
+ module Vimpack
2
+ module Commands
3
+ class Init < Command
4
+ def initialize_commands
5
+ die!("init takes a single optional argument") if @commands.size > 1
6
+ @repo_url = @commands.size == 1 ? @commands[0] : nil
7
+ end
8
+
9
+ def run
10
+ say(start_message)
11
+ Vimpack::Models::Repo.initialize!(@repo_url)
12
+ say('vimpack initialized!')
13
+ end
14
+
15
+ private
16
+
17
+ def start_message
18
+ " * initializing vimpack repo#{@repo_url.nil? ? '' : " from #{@repo_url}"}"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ module Vimpack
2
+ module Commands
3
+ class Install < Command
4
+
5
+ def initialize_commands
6
+ die!("install requires at least one script name argument") unless @commands.size >= 0
7
+ @script_names = @commands
8
+ end
9
+
10
+ def run
11
+ @script_names.each do |script_name|
12
+ begin
13
+ script = Vimpack::Models::Script.get(script_name)
14
+ rescue Vimpack::Models::Script::ScriptNotFound
15
+ exit_with_did_you_mean!(script_name)
16
+ end
17
+ say(" * installing #{script.name}")
18
+ script.install!
19
+ say("#{script.name} (#{script.version}) installed!")
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def exit_with_did_you_mean!(script_name)
26
+ possible = Vimpack::Models::Script.search(script_name).first rescue nil
27
+ return possible.nil? ?
28
+ exit_with_error!('Script not found!') :
29
+ exit_with_error!("Script not found! Did you mean #{possible.name}?")
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,14 @@
1
+ module Vimpack
2
+ module Commands
3
+ class List < Command
4
+
5
+ def run
6
+ Vimpack::Models::Repo.installed_scripts.each do |script|
7
+ say(script.name)
8
+ end
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,37 @@
1
+ module Vimpack
2
+ module Commands
3
+ class Search < Command
4
+
5
+ def initialize_options
6
+ @conditions = Vimpack::Models::Script::SCRIPT_TYPES.map.inject([]) do |conditions, script_type|
7
+ conditions << script_type if @options[script_type.gsub(' ', '_').to_sym]
8
+ conditions
9
+ end
10
+ end
11
+
12
+ def initialize_commands
13
+ die!("search requires a single argument") unless (@commands.size == 1 || !@conditions.empty?)
14
+ @pattern = @commands[0] if @commands.size >= 1
15
+ end
16
+
17
+ def run
18
+ scripts = Vimpack::Models::Script.search(@pattern, @conditions)
19
+ return exit_with_error!('No scripts found!', 0) if scripts.empty?
20
+ say_justified_script_names(scripts)
21
+ end
22
+
23
+ private
24
+
25
+ def say_justified_script_names(scripts)
26
+ linesize = scripts.sort do |a,b|
27
+ a.name.size <=> b.name.size
28
+ end.reverse.first.name.size + 1
29
+ scripts.each do |script|
30
+ say("#{script.name.ljust(linesize)} #{script.type}")
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,27 @@
1
+ module Vimpack
2
+ module Commands
3
+ class Uninstall < Command
4
+
5
+ def initialize_commands
6
+ die!("uninstall requires at least one script name argument") unless @commands.size >= 0
7
+ @script_names = @commands
8
+ end
9
+
10
+ def run
11
+ @script_names.each do |script_name|
12
+ begin
13
+ script = ::Vimpack::Models::Script.get(script_name)
14
+ return exit_with_error!('Script not found!') unless file_exists?(script.install_path)
15
+ rescue ::Vimpack::Models::Script::ScriptNotFound
16
+ return exit_with_error!('Script not found!')
17
+ end
18
+ say(" * uninstalling #{script.name}")
19
+ script.uninstall!
20
+ say("#{script.name} uninstalled!")
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,8 @@
1
+ require 'vimpack/commands/command'
2
+ require 'vimpack/commands/init'
3
+ require 'vimpack/commands/search'
4
+ require 'vimpack/commands/install'
5
+ require 'vimpack/commands/uninstall'
6
+ require 'vimpack/commands/list'
7
+ require 'vimpack/commands/info'
8
+ require 'vimpack/commands/git'
@@ -0,0 +1,7 @@
1
+ module Vimpack
2
+ module Models
3
+ class ApiBase < Base
4
+ include ::Vimpack::Utils::Api
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ module Vimpack
2
+ module Models
3
+
4
+ class Base
5
+ class << self
6
+
7
+ include ::Vimpack::Utils::File
8
+ include ::Vimpack::Utils::Git
9
+
10
+ attr_reader :attributes
11
+ def attributes(*attribute_names)
12
+ return @attributes if attribute_names.empty?
13
+ attribute_names = attribute_names.map(&:to_sym)
14
+ @attributes = attribute_names
15
+ attr_accessor *attribute_names
16
+ end
17
+
18
+ end
19
+ setup_paths(ENV['HOME'])
20
+
21
+ def initialize(attributes = Hash.new)
22
+ attributes.each do |name, value|
23
+ send("#{name}=".to_sym, value)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,117 @@
1
+ module Vimpack
2
+ module Models
3
+
4
+ class Repo < Base
5
+ class AlreadyInitialized < StandardError ; end
6
+ class NotInitialized < StandardError ; end
7
+ class OriginRemoteUnset < StandardError ; end
8
+
9
+ class << self
10
+ include ::Vimpack::Utils::File
11
+ include ::Vimpack::Utils::Git
12
+
13
+ def initialize!(repo_url=nil)
14
+ raise_if_initialized!
15
+ @repo_url = repo_url
16
+ backup_existing_vim_environment
17
+ @repo_url.nil? ? initialize_vimpack_repo : initialize_vimpack_remote_repo
18
+ end
19
+
20
+ def initialized?
21
+ directory_exists?(pack_path.to_s)
22
+ end
23
+
24
+ def raise_if_initialized!
25
+ raise AlreadyInitialized if initialized?
26
+ end
27
+
28
+ def raise_unless_initialized!
29
+ raise NotInitialized unless initialized?
30
+ end
31
+
32
+ def publish!(message)
33
+ raise OriginRemoteUnset unless origin_set?
34
+ repo_add_dot
35
+ repo_commit(message)
36
+ repo_push
37
+ true
38
+ end
39
+
40
+ def git_exec(subcommand, commands)
41
+ repo_exec(subcommand, commands)
42
+ end
43
+
44
+ def installed_script_names
45
+ Dir.glob(script_directories).each.inject([]) do |scripts, script_dir|
46
+ script_name = ::File.split(script_dir)[-1]
47
+ scripts << script_name unless script_name == 'pathogen.vim'
48
+ scripts
49
+ end
50
+ end
51
+
52
+ def installed_scripts
53
+ installed_script_names.each.inject([]) do |scripts, script_name|
54
+ scripts << Script.info(script_name)
55
+ end
56
+ end
57
+
58
+ private
59
+ def script_directories
60
+ Script::SCRIPT_TYPES.map do |script_type|
61
+ script_path.join(script_type.gsub(' ', '_'), '*')
62
+ end
63
+ end
64
+
65
+ def origin_set?
66
+ repo_remote?('origin')
67
+ end
68
+
69
+ def initialize_vimpack_remote_repo
70
+ repo_clone(@repo_url, self.pack_path.to_s)
71
+ init_submodule
72
+ update_submodule
73
+ link_dot_vim
74
+ initialize_vimrc
75
+ end
76
+
77
+ def backup_existing_vim_environment
78
+ move_path(home_path.join('.vim'), home_path.join('.vim.before_vimpack'))
79
+ move_path(home_path.join('.vimrc'), home_path.join('.vimrc.before_vimpack'))
80
+ end
81
+
82
+ def initialize_vimpack_repo
83
+ %w{ autoload bundle }.each do |directory|
84
+ make_dir(vim_path.join(directory))
85
+ ::FileUtils.touch(vim_path.join(directory, '.gitkeep'))
86
+ end
87
+ make_dir(script_path.to_s)
88
+ create_vimpack_repo
89
+ initialize_pathogen_submodule
90
+ link_dot_vim
91
+ initialize_vimrc
92
+ end
93
+
94
+ def link_dot_vim
95
+ create_link(self.vim_path.to_s, self.home_path.join('.vim'))
96
+ end
97
+
98
+ def initialize_pathogen_submodule
99
+ Script.get('pathogen.vim').install!(false)
100
+ create_link(script_path.join('utility', 'pathogen.vim', 'plugin', 'pathogen.vim'),
101
+ vim_path.join('autoload', 'pathogen.vim'))
102
+ end
103
+
104
+ def create_vimpack_repo
105
+ init_repo(pack_path)
106
+ end
107
+
108
+ def initialize_vimrc
109
+ template('vimrc', self.pack_path.join('vimrc')) unless ::File.exists?(self.pack_path.join('vimrc'))
110
+ create_link(self.pack_path.join('vimrc'), self.home_path.join('.vimrc'))
111
+ end
112
+
113
+ end
114
+ setup_paths(ENV['HOME'])
115
+ end
116
+ end
117
+ end