release-gem 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ae1c83005e05a5eeb8c5342aa98ae270205dbeb02c3090f585ba5eb68e26f09
4
- data.tar.gz: 6a50159b2e2acba162ea32cf9e5294805f4358ae57b3717d14ac2b825f1e66bc
3
+ metadata.gz: 25dd9ae22ee2f6e81080fb7dfad95726cf299aa4c8e437ea49ccf015ba383566
4
+ data.tar.gz: f3f0f229c66f3eb7e3c9aa2cbf275a0cbaed4f55da0987c17bddcde48bfb8890
5
5
  SHA512:
6
- metadata.gz: 96081961c0db069c1affa0f83ba4cc7ff8db5d0ca5f7ecfa50fff124bbc93244da78ba1ec0d386059fef313021896e62c25595335bdd9713bc024258a4bc1a4c
7
- data.tar.gz: e779b2b0e95fc57744a6164e157ecaf7121dbc61cee878fc735808a859fb8d103a73f5d2bfef3c4eb8630e1a36365ff17a39a5361fb87f272f95a36aab1b5fe6
6
+ metadata.gz: e892d6126c332f5266abaf1c3bb992c4cd4f9157eac46da023f4eff89b9a1217e69fed6656c24447fe903d707d2803c86241290b65f0aada86e06985faa8ee33
7
+ data.tar.gz: 2142260e3f9bc6af01c6bc6e3812b9258e8ec077dbb44d77f77243989b722ed9306fe8f6d2a467043d5681acf37fb193004b504815cef932552307e82cee3831
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- release-gem (0.1.3)
4
+ release-gem (0.1.4)
5
5
  colorize
6
6
  git_cli
7
7
  gvcs
@@ -30,32 +30,41 @@ module Release
30
30
  end
31
31
 
32
32
  def release_dependencies(*args, &block)
33
- if block
34
33
 
35
- block.call(:action_start, :relase_dependencies)
36
- puts "gem release dependencies"
37
- puts "Project has development gem? : #{gemdepInst.has_development_gem?}"
38
- keys = gemdepInst.development_gem.keys
39
- loop do
40
- begin
41
- conf = block.call(:define_gem_prod_config, { gems: keys })
42
- if conf.is_a?(Hash)
43
- conf.each do |k,v|
44
- gemdepInst.configure_gem(k,v)
34
+ if gemdepInst.has_development_gem?
35
+
36
+ if block
37
+
38
+ block.call(:action_start, :relase_dependencies)
39
+ keys = gemdepInst.development_gem.keys
40
+ loop do
41
+ begin
42
+ conf = block.call(:define_gem_prod_config, { gems: keys })
43
+ if conf.is_a?(Hash)
44
+ conf.each do |k,v|
45
+ gemdepInst.configure_gem(k,v)
46
+ end
47
+ break if gemdepInst.all_dev_gems_has_config?
48
+ keys = gemdepInst.not_configured_gem
49
+ else
50
+ block.call(:invalid_gem_prod_config, "Expected return from :define_gem_prod_config is a hash of \"gem name\" => { type: [:runtime | :dev], version: \">= 1.2.0\" }. Note version can be empty")
45
51
  end
46
- break if gemdepInst.all_dev_gems_has_config?
47
- keys = gemdepInst.not_configured_gem
48
- else
49
- block.call(:invalid_gem_prod_config, "Expected return from :define_gem_prod_config is a hash of \"gem name\" => { type: [:runtime | :dev], version: \">= 1.2.0\" }. Note version can be empty")
52
+ rescue GemDepError => ex
53
+ block.call(:invlid_gem_prod_config, ex.message)
50
54
  end
51
- rescue GemDepError => ex
52
- block.call(:invlid_gem_prod_config, ex.message)
53
55
  end
56
+
57
+ gemdepInst.transfer_gem
58
+
59
+ block.call(:development_gem_temporary_promoted)
54
60
  end
55
61
 
56
- gemdepInst.transfer_gem
57
- end
62
+ else
63
+ if block
64
+ block.call(:no_development_gems_found)
65
+ end
58
66
 
67
+ end
59
68
 
60
69
  end
61
70
 
@@ -31,7 +31,7 @@ module Release
31
31
 
32
32
  loop do
33
33
 
34
- sel = @pmt.select("\n The following development gems requires configuration. Please select one to configure") do |m|
34
+ sel = @pmt.select("\n The following development gems requires configuration. Please select one to configure ".yellow) do |m|
35
35
  selections.each do |g|
36
36
  m.choice g, g
37
37
  end
@@ -39,17 +39,17 @@ module Release
39
39
 
40
40
  config[sel] = {} if config[sel].nil?
41
41
 
42
- type = @pmt.select("\n The gem in production will be runtime or development ? ") do |m|
42
+ type = @pmt.select("\n The gem in production will be runtime or development ? ".yellow) do |m|
43
43
  m.choice "Runtime", :runtime
44
44
  m.choice "Development only", :dev
45
45
  end
46
46
 
47
47
  config[sel][:type] = type
48
48
 
49
- ver = @pmt.ask("\n Is there specific version pattern (including the ~>/>/>=/= of gemspec) for the gem in production? (Not mandatory) : ")
49
+ ver = @pmt.ask("\n Is there specific version pattern (including the ~>/>/>=/= of gemspec) for the gem in production? (Not mandatory) : ".yellow)
50
50
  config[sel][:version] = ver if not_empty?(ver)
51
51
 
52
- @pmt.puts " ** Done configure for gem #{sel}"
52
+ @pmt.puts " ** Done configure for gem #{sel}".yellow
53
53
  selections.delete_if { |v| v == sel }
54
54
  break if selections.length == 0
55
55
 
@@ -57,6 +57,12 @@ module Release
57
57
 
58
58
  config
59
59
 
60
+ when :development_gem_temporary_promoted
61
+ @pmt.puts "\n Development gem(s) temporary promoted to production status".yellow
62
+
63
+ when :no_development_gems_found
64
+ @pmt.puts "\n No development gem(s) in used found".yellow
65
+
60
66
  end
61
67
  end
62
68
 
@@ -0,0 +1,171 @@
1
+
2
+ require 'bundler'
3
+
4
+ module Release
5
+ module Gem
6
+
7
+ class GemDepError < StandardError; end
8
+
9
+ class GemDep
10
+ include TR::CondUtils
11
+
12
+ def initialize(root, opts = { })
13
+ @root = root
14
+ @devGems = {}
15
+ @gemConfig = {}
16
+ @fileHistory = {}
17
+ load_gemfile_deps
18
+ load_gemspec_deps
19
+ end
20
+
21
+ def load_gemfile_deps
22
+ gdef = Bundler::Definition.build(gemfile_file, nil, {})
23
+ gdef.dependencies.each do |d|
24
+ if not d.source.nil? and d.source.path.to_s != "."
25
+ @devGems[d.name] = d.source.path.to_s
26
+ end
27
+ end
28
+ end
29
+
30
+ def load_gemspec_deps
31
+ gs = ::Gem::Specification.load(gemspec_file)
32
+ gs.dependencies.each do |d|
33
+ if not d.source.nil? and d.source.path.to_s != "."
34
+ @devGems[d.name] = d.source.path.to_s
35
+ end
36
+ end
37
+ end
38
+
39
+ def has_development_gem?
40
+ not_empty?(@devGems)
41
+ end
42
+
43
+ def development_gem
44
+ @devGems
45
+ end
46
+
47
+ def configure_gem(name, opts = { type: :runtime, version: "" })
48
+ raise GemDepError, "Given option to configure the gem is empty" if is_empty?(opts)
49
+ raise GemDepError, "Given option is not a hash. Hash wity keys :type and/or :version (can be empty) is expected" if not opts.is_a?(Hash)
50
+ raise GemDepError, "Production gem type not given. Please provide the gem type via key :type (valid value is either :runtime or :dev)" if is_empty?(opts[:type])
51
+
52
+ if @devGems.keys.include?(name.to_s)
53
+ @gemConfig[name.to_s] = opts
54
+ else
55
+ raise GemDepError, "Name '#{name}' is not in the list of development gems. Valid value including : #{@devGems.keys.join(", ")}"
56
+ end
57
+ end
58
+
59
+ def transfer_gem
60
+ if not all_dev_gems_has_config?
61
+ raise GemDepError, "Not all gem has configuration. Gem required configuration includes: #{not_configured_gem.join(", ")}"
62
+ end
63
+
64
+ remove_dev_gem_from_gemfile
65
+ add_gem_to_gemspec(@gemConfig)
66
+
67
+ end
68
+
69
+ def all_dev_gems_has_config?
70
+ not_configured_gem.length == 0
71
+ end
72
+
73
+ def not_configured_gem
74
+ @devGems.keys.difference(@gemConfig.keys)
75
+ end
76
+
77
+ def restore_dev_gem
78
+ @fileHistory.each do |k,v|
79
+ FileUtils.mv(k,"#{k}.prod")
80
+ FileUtils.cp(v,k)
81
+ end
82
+ @fileHistory.clear
83
+ end
84
+
85
+ private
86
+ def remove_dev_gem_from_gemfile
87
+ if has_development_gem?
88
+ orin = gemfile_file
89
+ dest = "#{gemfile_file}.dev"
90
+ FileUtils.cp(orin, dest)
91
+ @fileHistory[orin] = dest
92
+
93
+ tmpOut = "#{orin}.tmp"
94
+
95
+ File.open(tmpOut, "w") do |f|
96
+ cont = File.read(dest)
97
+ cont.each_line do |l|
98
+ next if l =~ /^gem ('|")(#{development_gem.keys.join("|")})('|")/
99
+ f.puts l
100
+ end
101
+ end
102
+
103
+ FileUtils.rm(orin)
104
+ FileUtils.mv(tmpOut, orin)
105
+
106
+ # to make sure has_development_gem? return false in subsequent run
107
+ load_gemfile_deps
108
+
109
+ end
110
+ end
111
+
112
+ def add_gem_to_gemspec(spec = {})
113
+
114
+ if has_development_gem?
115
+
116
+ orin = gemspec_file
117
+ dest = "#{gemspec_file}.dev"
118
+ FileUtils.cp(orin, dest)
119
+ @fileHistory[orin] = dest
120
+
121
+ tmpOut = "#{orin}.tmp"
122
+
123
+ cont = File.read(gemspec_file)
124
+ lastEnd = cont.rindex("end")
125
+
126
+ File.open(tmpOut, "w") do |f|
127
+ f.write cont[0...lastEnd]
128
+ spec.each do |k,v|
129
+ case v[:type]
130
+ when :runtime
131
+ f.puts " spec.add_dependency \"#{k}\"#{is_empty?(v[:version]) ? "" : ", \"#{v[:version]}\""}"
132
+ when :dev
133
+ f.puts " spec.add_development_dependency \"#{k}\"#{is_empty?(v[:version]) ? "" : ", \"#{v[:version]}\""}"
134
+ end
135
+ end
136
+
137
+ f.puts "end"
138
+ end
139
+
140
+ FileUtils.rm(orin)
141
+ FileUtils.mv(tmpOut, orin)
142
+
143
+ # to make sure has_development_gem? return false in subsequent run
144
+ load_gemspec_deps
145
+
146
+ end
147
+
148
+
149
+ end
150
+
151
+ def gemspec_file
152
+ if @_gemspec.nil?
153
+ @_gemspec = Dir.glob(File.join(@root,"*.gemspec"))
154
+ raise GemDepError, "Cannot find gemspec at '#{@root}'" if is_empty?(@_gemspec)
155
+ @_gemspec = @_gemspec.first
156
+ end
157
+ @_gemspec
158
+ end
159
+
160
+ def gemfile_file
161
+ if @_gemfile_file.nil?
162
+ @_gemfile_file = Dir.glob(File.join(@root,"Gemfile"))
163
+ raise GemDepError, "Cannot find Gemfile at '#{@root}'" if is_empty?(@_gemfile_file)
164
+ @_gemfile_file = @_gemfile_file.first
165
+ end
166
+ @_gemfile_file
167
+ end
168
+
169
+ end
170
+ end
171
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Release
4
4
  module Gem
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
@@ -17,6 +17,9 @@ Release::Gem.engine(:gem, root: Dir.getwd) do
17
17
 
18
18
  # step 3 : build the gem
19
19
  st, ver = build
20
+
21
+ dependency_restore
22
+
20
23
  if st
21
24
  # step 4, push the gem to rubygems
22
25
  push(version: ver)
@@ -25,6 +28,7 @@ Release::Gem.engine(:gem, root: Dir.getwd) do
25
28
 
26
29
  end # gem_cli_action
27
30
 
31
+
28
32
  vcs_cli_action do
29
33
  @selVer = value(:selected_version)
30
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: release-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
@@ -125,6 +125,7 @@ files:
125
125
  - lib/release/gem/gem_action.rb
126
126
  - lib/release/gem/gem_cli_action.rb
127
127
  - lib/release/gem/gem_engine.rb
128
+ - lib/release/gem/gemdep.rb
128
129
  - lib/release/gem/vcs_action.rb
129
130
  - lib/release/gem/vcs_cli_action.rb
130
131
  - lib/release/gem/version.rb