nvvm 0.1.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.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.document +5 -0
- data/.rspec +4 -0
- data/.rubocop.yml +27 -0
- data/.travis.yml +12 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +123 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +66 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/bin/nvvm +13 -0
- data/etc/login +18 -0
- data/lib/nvvm.rb +10 -0
- data/lib/nvvm/accessor.rb +29 -0
- data/lib/nvvm/cli.rb +74 -0
- data/lib/nvvm/constants.rb +3 -0
- data/lib/nvvm/ext/mkmf.rb +8 -0
- data/lib/nvvm/installer.rb +77 -0
- data/lib/nvvm/switcher.rb +18 -0
- data/lib/nvvm/uninstaller.rb +23 -0
- data/lib/nvvm/validator.rb +64 -0
- data/lib/nvvm/version.rb +44 -0
- data/nvvm.gemspec +91 -0
- data/spec/accessor_spec.rb +32 -0
- data/spec/installer_spec.rb +136 -0
- data/spec/spec_helper.rb +77 -0
- data/spec/switcher_spec.rb +42 -0
- data/spec/uninstaller_spec.rb +33 -0
- data/spec/validator_spec.rb +292 -0
- data/spec/version_spec.rb +93 -0
- metadata +175 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Nvvm
|
4
|
+
class Installer
|
5
|
+
def initialize(version, conf, silent = false)
|
6
|
+
nvvmopt = ENV['NVVMOPT']
|
7
|
+
@silent = silent ? '> /dev/null 2>&1' : ''
|
8
|
+
@version = version
|
9
|
+
@conf = conf.flatten.empty? && nvvmopt ? nvvmopt.split(' ') : conf
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fetch
|
13
|
+
system("git clone --quiet #{VIM_URI} #{repo_dir}") unless File.exist?(repo_dir)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.pull
|
17
|
+
fetch unless File.exist?(repo_dir)
|
18
|
+
Dir.chdir(repo_dir) do
|
19
|
+
system('git pull --rebase --quiet')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def checkout
|
24
|
+
src = src_dir(@version)
|
25
|
+
return if File.exist?(src)
|
26
|
+
FileUtils.mkdir_p(src)
|
27
|
+
archive = "git archive --format=tar #{@version}"
|
28
|
+
expand = "(cd #{src} && tar xf -)"
|
29
|
+
Dir.chdir repo_dir do
|
30
|
+
system("#{archive} | #{expand} #{@silent}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def make_clean
|
35
|
+
src = src_dir(@version)
|
36
|
+
src_build = File.join(src, 'build')
|
37
|
+
FileUtils.rm_rf(src_build) if File.exist?(src_build)
|
38
|
+
Dir.chdir src do
|
39
|
+
system("make clean #{@silent}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def make_install
|
44
|
+
src = src_dir(@version)
|
45
|
+
Dir.chdir src do
|
46
|
+
system("make CMAKE_BUILD_TYPE=Release #{@silent}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.cp_etc
|
51
|
+
current_login = login_file
|
52
|
+
path = File.join(File.dirname(__FILE__), '..', '..', 'etc', 'login')
|
53
|
+
login = File.expand_path(path)
|
54
|
+
if !File.exist?(current_login)
|
55
|
+
etc = etc_dir
|
56
|
+
FileUtils.mkdir_p(etc)
|
57
|
+
FileUtils.cp(login, etc)
|
58
|
+
elsif !FileUtils.compare_file(login, current_login)
|
59
|
+
FileUtils.cp(login, etc_dir)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def message
|
64
|
+
return if !$?.success? || !@silent.empty?
|
65
|
+
print "\e[32m"
|
66
|
+
puts <<-MESSAGE
|
67
|
+
|
68
|
+
Neovim is successfully installed. For daily use,
|
69
|
+
please add the following line into your ~/.bash_login etc:
|
70
|
+
|
71
|
+
test -f ~/.nvvm/etc/login && source ~/.nvvm/etc/login
|
72
|
+
|
73
|
+
MESSAGE
|
74
|
+
print "\e[0m"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Nvvm
|
4
|
+
class Switcher
|
5
|
+
def initialize(version)
|
6
|
+
@version = version
|
7
|
+
end
|
8
|
+
|
9
|
+
def use
|
10
|
+
current = current_dir
|
11
|
+
FileUtils.rm(current) if File.exist?(current)
|
12
|
+
return if @version == 'system'
|
13
|
+
src = src_dir(@version)
|
14
|
+
abort "#{@version} is not installed." unless File.exist?(src)
|
15
|
+
FileUtils.ln_s(src, current)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Nvvm
|
4
|
+
class Uninstaller
|
5
|
+
def initialize(version)
|
6
|
+
@version = version
|
7
|
+
end
|
8
|
+
|
9
|
+
def uninstall
|
10
|
+
abort "#{@version} can not be uninstalled; It is currently used." if used?
|
11
|
+
src = src_dir(@version)
|
12
|
+
FileUtils.rm_rf(src) if File.exist?(src)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def used?
|
18
|
+
current = current_dir
|
19
|
+
return false unless File.exist?(current)
|
20
|
+
File.readlink(current) == src_dir(@version)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
module Nvvm
|
4
|
+
module Validator
|
5
|
+
METHOD_MAP = {
|
6
|
+
install: %w[version? git? new_version?],
|
7
|
+
update: %w[git?],
|
8
|
+
reinstall: %w[git? installed_version?],
|
9
|
+
rebuild: %w[version? git? installed_version?],
|
10
|
+
use: %w[version? installed_version?],
|
11
|
+
list: %w[git?],
|
12
|
+
uninstall: %w[version? installed_version?]
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def validate_before_invoke(command)
|
18
|
+
return unless validations = METHOD_MAP[command.to_sym]
|
19
|
+
validations.each { |v| send(v) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def git?
|
23
|
+
abort 'git is required to install.' unless find_executable('git')
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def version?
|
28
|
+
abort 'undefined Neovim version. please run [ nvvm list ].' if find_version.nil?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def new_version?(ver = nil)
|
33
|
+
Installer.pull
|
34
|
+
ver = version if ver.nil?
|
35
|
+
abort "#{ver} is already installed." if version_include?(ver)
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def installed_version?(ver = version)
|
40
|
+
abort "#{ver} is not installed." unless version_include?(ver)
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def find_version
|
47
|
+
version_regex = /\Av\d\..+\z|\A(\d\.\d(a|b){0,1}(\.\d+){0,1})\z/
|
48
|
+
regex = /(\Asystem\z|\Alatest\z|#{version_regex})/
|
49
|
+
$*.find { |v| v =~ regex }
|
50
|
+
end
|
51
|
+
|
52
|
+
def version
|
53
|
+
Version.format(find_version)
|
54
|
+
end
|
55
|
+
|
56
|
+
def version_include?(ver)
|
57
|
+
Version.versions.include?(ver) || use_system?(ver)
|
58
|
+
end
|
59
|
+
|
60
|
+
def use_system?(ver)
|
61
|
+
ver == 'system' && $*.include?('use')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/nvvm/version.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Nvvm
|
2
|
+
class Version
|
3
|
+
def self.list
|
4
|
+
abort "#{repo_dir} not found." unless File.exist?(repo_dir)
|
5
|
+
Dir.chdir(repo_dir) do
|
6
|
+
return `git tag`.split
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.versions
|
11
|
+
output = []
|
12
|
+
src = src_dir
|
13
|
+
return output unless File.exist?(src)
|
14
|
+
Dir.glob(File.join(src, '*')).sort.each do |d|
|
15
|
+
next if File.basename(d) == 'current'
|
16
|
+
output << File.basename(d)
|
17
|
+
end
|
18
|
+
output
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.latest
|
22
|
+
list.select { |v| v =~ /\Av\d\..+\z/ }.last
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.current
|
26
|
+
d = current_dir
|
27
|
+
File.exist?(d) ? File.basename(File.readlink(d)) : 'system'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.convert(version)
|
31
|
+
"v#{version}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.format(version)
|
35
|
+
case version
|
36
|
+
when /\Alatest\z/
|
37
|
+
version = latest
|
38
|
+
when /\A(\d\.\d(a|b){0,1}(\.\d+){0,1})\z/
|
39
|
+
version = convert(version)
|
40
|
+
end
|
41
|
+
version
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/nvvm.gemspec
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: nvvm 0.1.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "nvvm"
|
9
|
+
s.version = "0.1.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["YuuShigetani"]
|
14
|
+
s.date = "2017-12-24"
|
15
|
+
s.description = "Neovim version manager."
|
16
|
+
s.email = "s2g4t1n2@gmail.com"
|
17
|
+
s.executables = ["nvvm"]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".coveralls.yml",
|
24
|
+
".document",
|
25
|
+
".rspec",
|
26
|
+
".rubocop.yml",
|
27
|
+
".travis.yml",
|
28
|
+
"Gemfile",
|
29
|
+
"Gemfile.lock",
|
30
|
+
"LICENSE.txt",
|
31
|
+
"README.rdoc",
|
32
|
+
"Rakefile",
|
33
|
+
"VERSION",
|
34
|
+
"bin/nvvm",
|
35
|
+
"etc/login",
|
36
|
+
"lib/nvvm.rb",
|
37
|
+
"lib/nvvm/accessor.rb",
|
38
|
+
"lib/nvvm/cli.rb",
|
39
|
+
"lib/nvvm/constants.rb",
|
40
|
+
"lib/nvvm/ext/mkmf.rb",
|
41
|
+
"lib/nvvm/installer.rb",
|
42
|
+
"lib/nvvm/switcher.rb",
|
43
|
+
"lib/nvvm/uninstaller.rb",
|
44
|
+
"lib/nvvm/validator.rb",
|
45
|
+
"lib/nvvm/version.rb",
|
46
|
+
"nvvm.gemspec",
|
47
|
+
"spec/accessor_spec.rb",
|
48
|
+
"spec/installer_spec.rb",
|
49
|
+
"spec/spec_helper.rb",
|
50
|
+
"spec/switcher_spec.rb",
|
51
|
+
"spec/uninstaller_spec.rb",
|
52
|
+
"spec/validator_spec.rb",
|
53
|
+
"spec/version_spec.rb"
|
54
|
+
]
|
55
|
+
s.homepage = "http://github.com/calorie/nvvm"
|
56
|
+
s.licenses = ["MIT"]
|
57
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
58
|
+
s.rubygems_version = "2.5.1"
|
59
|
+
s.summary = "Neovim version manager"
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
s.specification_version = 4
|
63
|
+
|
64
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
65
|
+
s.add_runtime_dependency(%q<thor>, ["~> 0.20.0"])
|
66
|
+
s.add_development_dependency(%q<coveralls>, ["~> 0.7.1"])
|
67
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
68
|
+
s.add_development_dependency(%q<rdoc>, ["~> 6.0"])
|
69
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.0"])
|
70
|
+
s.add_development_dependency(%q<rubocop>, ["~> 0.52.0"])
|
71
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0.15.1"])
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<thor>, ["~> 0.20.0"])
|
74
|
+
s.add_dependency(%q<coveralls>, ["~> 0.7.1"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
76
|
+
s.add_dependency(%q<rdoc>, ["~> 6.0"])
|
77
|
+
s.add_dependency(%q<rspec>, ["~> 3.0"])
|
78
|
+
s.add_dependency(%q<rubocop>, ["~> 0.52.0"])
|
79
|
+
s.add_dependency(%q<simplecov>, ["~> 0.15.1"])
|
80
|
+
end
|
81
|
+
else
|
82
|
+
s.add_dependency(%q<thor>, ["~> 0.20.0"])
|
83
|
+
s.add_dependency(%q<coveralls>, ["~> 0.7.1"])
|
84
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
85
|
+
s.add_dependency(%q<rdoc>, ["~> 6.0"])
|
86
|
+
s.add_dependency(%q<rspec>, ["~> 3.0"])
|
87
|
+
s.add_dependency(%q<rubocop>, ["~> 0.52.0"])
|
88
|
+
s.add_dependency(%q<simplecov>, ["~> 0.15.1"])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Accessor' do
|
4
|
+
it 'can access nvvm home directory' do
|
5
|
+
expect(File.exist?(dot_dir)).to be_truthy
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'can access etc directory' do
|
9
|
+
expect(File.exist?(etc_dir)).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can access repo directory' do
|
13
|
+
expect(File.exist?(repo_dir)).to be_truthy
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can access src directory' do
|
17
|
+
expect(File.exist?(src_dir)).to be_truthy
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can access login file' do
|
21
|
+
expect(File.exist?(login_file)).to be_truthy
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'of current directory' do
|
25
|
+
before { Nvvm::Switcher.new(VERSION1).use }
|
26
|
+
after { Nvvm::Switcher.new('system').use }
|
27
|
+
|
28
|
+
it 'can access current directory' do
|
29
|
+
expect(File.exist?(current_dir)).to be_truthy
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
describe 'Installer', disable_cache: true do
|
5
|
+
before :all do
|
6
|
+
@version = VERSION1
|
7
|
+
@installer = Nvvm::Installer.new(@version, [], true)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:version_src_dir) { src_dir(@version) }
|
11
|
+
let(:nvim) { File.join(version_src_dir, 'build', 'bin', 'nvim') }
|
12
|
+
|
13
|
+
describe 'install' do
|
14
|
+
context 'fetch', clean: true do
|
15
|
+
before(:all) { Nvvm::Installer.fetch }
|
16
|
+
|
17
|
+
it 'exists repo dir' do
|
18
|
+
expect(File.exist?(repo_dir)).to be_truthy
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'success to clone' do
|
22
|
+
expect($?.success?).to be_truthy
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'exists Makefile file' do
|
26
|
+
expect(File.exist?(File.join(repo_dir, 'Makefile'))).to be_truthy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'pull', clean: true, repo: true do
|
31
|
+
before :all do
|
32
|
+
Dir.chdir(repo_dir) do
|
33
|
+
system('git reset --hard HEAD')
|
34
|
+
system('git clean -fdx')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'repo_dir not found' do
|
39
|
+
allow(File).to receive(:exist?).with(repo_dir).and_return(false)
|
40
|
+
allow(Nvvm::Installer).to receive(:fetch).and_return(true)
|
41
|
+
expect(Nvvm::Installer).to receive(:fetch)
|
42
|
+
Nvvm::Installer.pull
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'success to pull' do
|
46
|
+
Nvvm::Installer.pull
|
47
|
+
expect($?.success?).to be_truthy
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'checkout', clean: true, repo: true do
|
52
|
+
before :all do
|
53
|
+
@installer.checkout
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'exists src dir' do
|
57
|
+
expect(File.exist?(version_src_dir)).to be_truthy
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'exists Makefile file' do
|
61
|
+
makefile = File.join(version_src_dir, 'Makefile')
|
62
|
+
expect(File.exist?(makefile)).to be_truthy
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'make_install', clean: true, repo: true, src: true do
|
67
|
+
before :all do
|
68
|
+
@installer.make_install
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'can execute nvim' do
|
72
|
+
expect(system("#{nvim} --version > /dev/null 2>&1")).to be_truthy
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'cp_etc', clean: true do
|
77
|
+
context 'login file not exist' do
|
78
|
+
before(:all) { Nvvm::Installer.cp_etc }
|
79
|
+
|
80
|
+
it 'exists etc dir' do
|
81
|
+
expect(File.exist?(etc_dir)).to be_truthy
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'exists login file' do
|
85
|
+
expect(File.exist?(login_file)).to be_truthy
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'login file exists and it is not latest' do
|
90
|
+
before do
|
91
|
+
allow(FileUtils).to receive(:compare_file).and_return(false)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'exists login file' do
|
95
|
+
path = File.join(File.dirname(__FILE__), '..', 'etc', 'login')
|
96
|
+
login = File.expand_path(path)
|
97
|
+
expect(FileUtils).to receive(:cp).with(login, etc_dir)
|
98
|
+
Nvvm::Installer.cp_etc
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'rebuild' do
|
105
|
+
context 'make_clean', clean: true, src: true do
|
106
|
+
before :all do
|
107
|
+
@installer.make_clean
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'not exists build dir' do
|
111
|
+
path = File.join(version_src_dir, 'build')
|
112
|
+
expect(File.exist?(path)).not_to be_truthy
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'message' do
|
118
|
+
before { system('') }
|
119
|
+
|
120
|
+
it 'command failed' do
|
121
|
+
allow($?).to receive(:success?).and_return(false)
|
122
|
+
expect { @installer.message }.to_not output(/success/).to_stdout
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'silent' do
|
126
|
+
allow($?).to receive(:success?).and_return(true)
|
127
|
+
expect { @installer.message }.to_not output(/success/).to_stdout
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'success' do
|
131
|
+
allow($?).to receive(:success?).and_return(true)
|
132
|
+
installer = Nvvm::Installer.new(@version, [])
|
133
|
+
expect { installer.message }.to output(/success/).to_stdout
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|