-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnfs_gems
executable file
·78 lines (63 loc) · 1.83 KB
/
cnfs_gems
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
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'fileutils'
require 'thor'
class GemCli < Thor
class_option :dry_run, desc: 'Do not execute commands', aliases: '-d', type: :boolean, default: false
desc 'build', 'Build all Cnfs gems'
def build
each_dir do |_name, gemspec|
exec("gem build #{gemspec}")
end
end
desc 'install', 'Install all Cnfs gems'
option :deps, desc: 'Install all Cnfs gems dependencies, but not the Cnfs gems themselves', type: :boolean
def install
if options.deps
install_deps
return
end
each_dir do |_name, gemspec|
exec("gem build #{gemspec}")
next unless (gem_file = Dir['*.gem'].shift)
exec("gem install ./#{gem_file}")
FileUtils.rm(gem_file)
end
end
desc 'uninstall', 'Uninstall all Cnfs gems'
def uninstall
each_dir do |_name, gemspec|
exec("gem uninstall -a -x #{gemspec.delete_suffix('.gemspec')}")
end
end
private
# Use this to quickly install all dependencies while running the Cnfs gems from source
def install_deps
each_dir do |dir, gemspec|
next if dir.eql?('packer')
if (gemfile = Dir['*.gem'].shift)
FileUtils.rm(gemfile)
end
puts "** #{Dir.pwd.split('/').last}"
File.open('Gemfile', 'w') { |f| f.write("source ENV['GEM_SERVER'] || 'https://rubygems.org'\ngemspec") }
system('bundle install') unless options.dry_run
FileUtils.rm('Gemfile')
FileUtils.rm_rf('Gemfile.lock')
FileUtils.rm_rf('.bundle')
end
end
def each_dir
Dir['*/'].sort.each do |dir|
dir = dir.delete_suffix('/')
Dir.chdir(dir) do
next unless (gemspec = Dir['*.gemspec'].shift)
yield dir, gemspec
end
end
end
def exec(cmd)
puts cmd if options.verbose
system(cmd) unless options.noop
end
end
GemCli.start