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
|
# File 'lib/vundler/vundler_command/setup.rb', line 7
def execute
if @env.home_path.join('global-plugins.json').file?
@env.ui.info "Vundler has already been set up!"
return 0
end
plugins_json = @env.home_path.join('plugins.json')
plugins_json_data = JSON.parse(plugins_json.read)
@logger.debug "Current #{plugins_json} data: #{plugins_json_data.inspect}"
@logger.debug "Getting list of installed plugins"
other_plugins = plugins_json_data['installed'].dup
other_plugins.delete('vundler')
@logger.debug "Writing #{other_plugins.inspect} to #{@env.home_path.join('global-plugins.json')}"
@env.home_path.join('global-plugins.json').open("w+") do |f|
f.write(JSON.dump({'installed' => other_plugins}))
end
plugins_json_data['installed'] = ['vundler']
@logger.debug "Writing #{plugins_json_data.inspect} to #{plugins_json}"
plugins_json.open('w+') do |f|
f.write(JSON.dump plugins_json_data)
end
vagrantfile = @env.home_path.join('Vagrantfile')
vagrantfile_contents = vagrantfile.file? ? vagrantfile.read : ''
vagrantfile_contents = <<-STR
begin
require 'vundler'
rescue LoadError; end
#{vagrantfile_contents}
STR
@logger.debug "Writing to system wide Vagrantfile:\n#{vagrantfile_contents}"
@env.home_path.join('Vagrantfile').open("w+") do |f|
f.write vagrantfile_contents
end
0
end
|