release-gem 0.1.5 → 0.1.7

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: 4a3f43d3c0b887a2346a0ee9b126a6f7a2edd0715f77b910762caeec3056bd76
4
- data.tar.gz: 937d525b33b1695c16ddd1ff3edd77a554ea8be086832cc1052d27e468d4b7a0
3
+ metadata.gz: dea9d324f7b793ed225472a24d957dcd38eabb8f713271d2cb524a6f1e5f1923
4
+ data.tar.gz: 6581b5e4fa0d949871b87392e97f139f30785791d93a6fa040260ba52ab312d3
5
5
  SHA512:
6
- metadata.gz: ca0da466583bf5191772d82a08507acaca1db045a6e93c6dc9573ed5a445f58a31570328f73a0f1840fcc328bfadf92fc40b03696a46086628ebfe1a99d828ea
7
- data.tar.gz: b2a5f5d9ec4d3bda1fb86bed8b001b85ca7b1e12fefe585dba8297dcda51cd76f7b9acccddd63192c6119bb0237ba671dd0cb7662847c9d7cf9960f0e0b74b91
6
+ metadata.gz: 970ea9b05c234620c01a03193e2a92a1c485e0019ac381ba87b3e09c0a82b6d6ba2e8abd80d911d6250e995d1fc36435000ce4f9491f3c1628b474ec78489c1f
7
+ data.tar.gz: e45f427d07988e498c13cbcf7cc95eacde6523f5e2551ea7e098f9ad6062f60b7039e24800e0c79f8da3b7010c909d5c517273f28d4d69cdc2b4aa639700feda
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- release-gem (0.1.5)
4
+ release-gem (0.1.7)
5
5
  colorize
6
6
  git_cli
7
7
  gvcs
@@ -38,8 +38,10 @@ module Release
38
38
  block.call(:action_start, :relase_dependencies)
39
39
 
40
40
  gemdepInst.development_gem.each do |k,v|
41
- gemdepInst.infect_gem(v, k, &block)
42
- block.call(:block_until_dev_gem_done, { name: k, path: v })
41
+ res = gemdepInst.infect_gem(v, k, &block)
42
+ if res != :skip
43
+ block.call(:block_until_dev_gem_done, { name: k, path: v })
44
+ end
43
45
  end
44
46
 
45
47
 
@@ -329,7 +331,7 @@ module Release
329
331
  end
330
332
 
331
333
  def method_missing(mtd, *args, &block)
332
- if not @engine.nil? and @engine.respond_to?(mtd)
334
+ if not @engine.nil?
333
335
  @engine.send(mtd, *args, &block)
334
336
  else
335
337
  super
@@ -61,6 +61,7 @@ module Release
61
61
  v[:options].each do |t|
62
62
  m.choice t, t
63
63
  end
64
+ m.choice "Skip", :skip
64
65
  end
65
66
 
66
67
  when :new_terminal_launching
@@ -53,14 +53,14 @@ module Release
53
53
  end
54
54
 
55
55
  def method_missing(mtd, *args, &block)
56
- if mtd.to_s.start_with?("gem_cli")
56
+ if mtd.to_s.start_with?("gem_cli_")
57
57
  Gem.logger.debug "Passing method '#{mtd}' to gem_cli action"
58
- pmtd = mtd.to_s[7..-1].to_sym
58
+ pmtd = mtd.to_s[8..-1].to_sym
59
59
  gem_cli_action_inst.send(pmtd, *args, &block)
60
60
 
61
- elsif mtd.to_s.start_with?("vcs_cli")
61
+ elsif mtd.to_s.start_with?("vcs_cli_")
62
62
  Gem.logger.debug "Passing method '#{mtd}' to vcs_cli action"
63
- pmtd = mtd.to_s[7..-1].to_sym
63
+ pmtd = mtd.to_s[8..-1].to_sym
64
64
  vcs_cli_action_inst.send(pmtd, *args, &block)
65
65
 
66
66
  elsif mtd.to_s.start_with?("gem_")
@@ -0,0 +1,184 @@
1
+
2
+
3
+ module Release
4
+ module Gem
5
+
6
+ class ReleaseInfectorError < StandardError; end
7
+
8
+ #
9
+ # Setup the release-gem into other gem project automatically!
10
+ #
11
+ class ReleaseInfector
12
+ include TR::CondUtils
13
+ include TR::TerminalUtils
14
+
15
+ def initialize(root, name)
16
+ @root = root
17
+ @name = name
18
+ @backupFiles = {}
19
+ end
20
+
21
+ def infect(&block)
22
+ if not is_release_gem_installed?
23
+ add_to_gemspec(&block)
24
+ Bundler.with_clean_env do
25
+ res = `cd #{@root} && bundle`
26
+ end
27
+ end
28
+
29
+ if not is_rakefile_activated?
30
+ activate_rakefile(&block)
31
+ end
32
+ end
33
+
34
+ def trigger_release_gem(&block)
35
+
36
+ block.call(:triggering_release_gem) if block
37
+
38
+ poss = tu_possible_terminal
39
+ raise ReleaseInfectorError, "No possible terminal found" if is_empty?(poss)
40
+
41
+ terminal = ""
42
+ Bundler.with_clean_env do
43
+
44
+ cmd = "cd #{@root} && rake gem:release"
45
+ if block
46
+ terminal = block.call(:select_terminal, name: @name, options: poss)
47
+ if terminal != :skip
48
+ terminal = poss.first if is_empty?(terminal)
49
+
50
+ block.call(:new_terminal_launching, name: @name, terminal: terminal)
51
+ tu_new_terminal(terminal, cmd)
52
+ end
53
+
54
+ else
55
+ terminal = poss.first
56
+ block.call(:new_terminal_launching, name: @name, terminal: terminal)
57
+ tu_new_terminal(terminal, cmd)
58
+ end
59
+
60
+ block.call(:new_terminal_launched, name: @name, terminal: terminal) if block
61
+
62
+ end
63
+
64
+ terminal
65
+
66
+ end
67
+
68
+ def is_release_gem_installed?
69
+ #Bundler.with_clean_env do
70
+ Bundler.with_unbundled_env do
71
+
72
+ res = `cd #{@root} && bundle 2>&1`
73
+
74
+ puts res
75
+
76
+ if $?.success?
77
+ found = false
78
+ res.each_line do |l|
79
+ if l =~ / release-gem /
80
+ found = true
81
+ break
82
+ end
83
+ end
84
+
85
+ found
86
+ else
87
+ raise ReleaseInfectorError, "Error running bundle in '#{@root}'. Error was :\n#{res}"
88
+ end
89
+
90
+ end
91
+ end # is_release_gem_installed?
92
+
93
+ def add_to_gemspec(&block)
94
+
95
+
96
+ gs = Dir.glob(File.join(@root,"*.gemspec"))
97
+ raise ReleaseInfectorError, "gemspec not found at '#{@root}'" if is_empty?(gs)
98
+
99
+ block.call(:adding_to_gemspec, gemspec: gs) if block
100
+
101
+ if gs.length > 1
102
+ if block
103
+ gs = block.call(:multiple_gemspecs, gs)
104
+ else
105
+ raise ReleaseInfectorError, "There are more than 1 gemspec file found (#{gs.length} found). Since no block to filter out the required one, this will be an error condition"
106
+ end
107
+
108
+ else
109
+ gs = gs.first
110
+ end
111
+
112
+ cont = File.read(gs)
113
+ lastEnd = cont.rindex("end")
114
+
115
+ FileUtils.mv(gs, "#{gs}.bak")
116
+ @backupFiles[gs] = "#{gs}.bak"
117
+
118
+ File.open(gs, "w") do |f|
119
+ f.write cont[0...lastEnd]
120
+ f.puts " spec.add_development_dependency 'release-gem'"
121
+ f.puts "end"
122
+ end
123
+ block.call(:gemspec_updated, name: @name, gemspec: gs )
124
+
125
+ end # add_to_gemspec
126
+
127
+ def activate_rakefile(&block)
128
+
129
+ rf = File.join(@root,"Rakefile")
130
+ if not File.exist?(rf)
131
+ rfCont <<-END
132
+ # frozen_string_literal: true
133
+
134
+ require "bundler/gem_tasks"
135
+ require "rspec/core/rake_task"
136
+
137
+ require "release/gem"
138
+
139
+ RSpec::Core::RakeTask.new(:spec)
140
+
141
+ task default: :spec
142
+ END
143
+ block.call(:creating_new_rakefile, rakefile: rf )
144
+ File.open(rf,"w") do |f|
145
+ f.write rfCont
146
+ end
147
+ else
148
+
149
+ block.call(:adding_to_rakefile, rakefile: rf )
150
+
151
+ cont = File.read(rf)
152
+ FileUtils.mv(rf, "#{rf}.bak")
153
+ @backupFiles[rf] = "#{rf}.bak"
154
+
155
+ File.open(rf,"w") do |f|
156
+ f.puts cont
157
+ f.puts "require 'release/gem'"
158
+ end
159
+
160
+ block.call(:rakefile_updated, name: @name, rakefile: rf) if block
161
+
162
+ end
163
+ end
164
+
165
+ def is_rakefile_activated?
166
+ rf = File.join(@root,"Rakefile")
167
+ if not File.exist?(rf)
168
+ false
169
+ else
170
+ cont = File.read(rf)
171
+ found = false
172
+ cont.each_line do |l|
173
+ if l =~ /require ('|")(release\/gem)("|')/
174
+ found = true
175
+ break
176
+ end
177
+ end
178
+ found
179
+ end
180
+ end
181
+
182
+ end
183
+ end
184
+ end
@@ -42,6 +42,106 @@ module Release
42
42
  instance_eval(&block) if block
43
43
  end
44
44
 
45
+ def overview_changes(&block)
46
+
47
+ res = :done
48
+ if block
49
+
50
+ loop do
51
+
52
+ stgDir, stgFiles = @ws.staged_files
53
+ modDir, modFiles = @ws.modified_files
54
+ newDir, newFiles = @ws.new_files
55
+ delDir, delFiles = @ws.deleted_files
56
+
57
+ modFiles.delete_if { |f| stgFiles.include?(f) }
58
+ modDir.delete_if { |f| stgDir.include?(f) }
59
+
60
+ newFiles.delete_if { |f| stgFiles.include?(f) }
61
+ newDir.delete_if { |f| stgDir.include?(f) }
62
+
63
+ delFiles.delete_if { |f| stgFiles.include?(f) }
64
+ delDir.delete_if { |f| stgDir.include?(f) }
65
+
66
+ # block should call vcs for remove, ignore and diff
67
+ res = block.call(:select_files_to_manage, { modified: { files: modFiles, dirs: modDir }, new: { files: newFiles, dirs: newDir }, deleted: { files: delFiles, dirs: delDir }, staged: { files: stgFiles, dirs: stgDir }, vcs: self } )
68
+
69
+ break if res == :done
70
+
71
+ end
72
+
73
+ end
74
+
75
+ res
76
+
77
+ end
78
+
79
+ #
80
+ # Special operation since the gem build will only include files from
81
+ # git ls-files
82
+ #
83
+ def commit_new_files(msg = nil, &block)
84
+
85
+ res = :value
86
+ if block
87
+
88
+ loop do
89
+
90
+ stgDir, stgFiles = @ws.staged_files
91
+ newDir, newFiles = @ws.new_files
92
+
93
+ if is_empty?(newFiles)
94
+ res = :skip
95
+ break
96
+ end
97
+
98
+ newFiles.delete_if { |f| stgFiles.include?(f) }
99
+ newDir.delete_if { |f| stgDir.include?(f) }
100
+
101
+ res = block.call(:select_files_to_commit, { new: { files: newFiles, dirs: newDir }, staged: { files: stgFiles, dirs: stgDir }, vcs: self } )
102
+
103
+ break if res == :skip or res == :done
104
+
105
+ end
106
+
107
+ if res == :done
108
+
109
+ stgDir, stgFiles = @ws.staged_files
110
+ block.call(:staged_elements_of_commit, { files: stgFiles, dirs: stgDir })
111
+
112
+ msg = block.call(:commit_message) if is_empty?(msg)
113
+ raise VcsActionError, "Commit message is empty" if is_empty?(msg)
114
+
115
+ cp "Commit with user message : #{msg}"
116
+ st, res = @ws.commit(msg)
117
+ if st
118
+ block.call(:commit_successful, res) if block
119
+ else
120
+ block.call(:commit_failed, res) if block
121
+ end
122
+ [st, res]
123
+
124
+ end
125
+
126
+
127
+ elsif not_empty?(msg)
128
+
129
+ newDir, newFiles = @ws.new_files
130
+ add_to_staging(*newFiles)
131
+
132
+ cp "Commit with user message : #{msg}"
133
+ st, res = @ws.commit(msg)
134
+ if st
135
+ block.call(:commit_successful, res) if block
136
+ else
137
+ block.call(:commit_failed, res) if block
138
+ end
139
+ [st, res]
140
+
141
+ end
142
+
143
+ end
144
+
45
145
  def commit(msg = nil, &block)
46
146
 
47
147
  res = :value
@@ -57,6 +157,12 @@ module Release
57
157
 
58
158
  modFiles.delete_if { |f| stgFiles.include?(f) }
59
159
  modDir.delete_if { |f| stgDir.include?(f) }
160
+
161
+ newFiles.delete_if { |f| stgFiles.include?(f) }
162
+ newDir.delete_if { |f| stgDir.include?(f) }
163
+
164
+ delFiles.delete_if { |f| stgFiles.include?(f) }
165
+ delDir.delete_if { |f| stgDir.include?(f) }
60
166
 
61
167
  # block should call vcs for add, remove, ignore and other operations
62
168
  res = block.call(:select_files_to_commit, { modified: { files: modFiles, dirs: modDir }, new: { files: newFiles, dirs: newDir }, deleted: { files: delFiles, dirs: delDir }, staged: { files: stgFiles, dirs: stgDir }, vcs: self, counter: counter } )
@@ -20,6 +20,176 @@ module Release
20
20
  instance_eval(&block) if block
21
21
  end
22
22
 
23
+ def overview_changes(*args, &block)
24
+ @inst.overview_changes do |ops, *args|
25
+ preset = false
26
+ if block
27
+ res = block.call(ops, *args)
28
+ if res.nil?
29
+ preset = true
30
+ else
31
+ res
32
+ end
33
+ else
34
+ preset = true
35
+ end
36
+
37
+ if preset
38
+ case ops
39
+ when :select_files_to_manage
40
+ mfiles = args.first
41
+
42
+ sel = @prmt.select pmsg("\n Following are files that could be managed : ") do |m|
43
+
44
+ [:staged, :modified, :new, :deleted].each do |cat|
45
+ mfiles[cat].each do |k,v|
46
+ v.each do |vv|
47
+ m.choice vv, vv
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ m.choice "Done", :done
54
+
55
+ end
56
+
57
+ if sel != :done
58
+
59
+ selOps = @prmt.select pmsg("\n What do you want to do with file '#{sel}'?") do |m|
60
+
61
+ m.choice "Diff", :diff
62
+ m.choice "Ignore", :ignore
63
+ m.choice "Remove from staging", :remove_from_staging if sel.is_a?(GitCli::Delta::StagedFile)
64
+ m.choice "Done", :done
65
+ end
66
+
67
+ case selOps
68
+ when :diff
69
+ puts @inst.diff_file(sel.path)
70
+ STDIN.getc
71
+ when :ignore
72
+ confirm = @prmt.yes?(pmsg("\n Add file '#{sel.path}' to gitignore file?"))
73
+ if confirm
74
+ @inst.ignore(sel.path)
75
+ end
76
+ when :remove_from_staging
77
+ confirm = @prmt.yes?(pmsg("\n Remove file '#{sel.path}' from staging?"))
78
+ if confirm
79
+ @inst.remove_from_staging(sel.path)
80
+ end
81
+ when :done
82
+ end
83
+
84
+ end
85
+
86
+ sel
87
+
88
+ end
89
+ end
90
+
91
+ end
92
+ end # overview_changes
93
+
94
+ def commit_new_files(*args, &block)
95
+ res = @inst.commit_new_files do |ops, *args|
96
+
97
+ preset = false
98
+ if block
99
+ res = block.call(ops, *args)
100
+ if res.nil?
101
+ preset = true
102
+ else
103
+ res
104
+ end
105
+ else
106
+ preset = true
107
+ end
108
+
109
+ if preset
110
+
111
+ case ops
112
+ when :select_files_to_commit
113
+ mfiles = args.first
114
+ @prmt.puts pmsg("\n Files already added to staging : ")
115
+ mfiles[:staged].each do |k,v|
116
+ v.each do |vv|
117
+ @prmt.puts " * #{vv}"
118
+ end
119
+ end
120
+
121
+ @prmt.puts ""
122
+
123
+ sel = @prmt.multi_select pmsg("\n Following are new files that could be added to version control : ") do |m|
124
+
125
+ mfiles[:new].each do |k,v|
126
+ v.each do |vv|
127
+ m.choice vv, vv.path
128
+ end
129
+ end
130
+
131
+ m.choice "Skip", :skip #if mfiles[:counter] == 0
132
+ m.choice "Done", :done
133
+ m.choice "Abort", :abort
134
+ end
135
+
136
+ if sel.include?(:abort)
137
+ raise Release::Gem::Abort, "User aborted"
138
+ elsif sel.include?(:skip)
139
+ :skip
140
+ else
141
+ res = :done if sel.include?(:done)
142
+ s = sel.clone
143
+ s.delete_if { |e| e == :done }
144
+ if not_empty?(s)
145
+ st, cres = add_to_staging(*s) if not_empty?(s)
146
+ if st
147
+ @prmt.puts pmsg("\n Files added successfully", :green)
148
+ else
149
+ @prmt.puts pmsg("\n Files failed to be added. Message was : #{cres}", :red)
150
+ end
151
+ end
152
+
153
+ res
154
+
155
+ end
156
+
157
+ when :commit_message
158
+ msg = ""
159
+ loop do
160
+ msg = @prmt.ask(pmsg("\n Commit message : "), required: true)
161
+ confirm = @prmt.yes?(pmsg(" Commit message : #{msg}\n Proceed? No to provide a new commit message "))
162
+ if confirm
163
+ break
164
+ end
165
+ end
166
+
167
+ msg
168
+
169
+ when :staged_elements_of_commit
170
+
171
+ elements = args.first
172
+ @prmt.puts pmsg("\n Following new files/directories shall be committed in this session : ")
173
+ elements.each do |k,v|
174
+ v.each do |vv|
175
+ @prmt.puts " * #{vv}"
176
+ end
177
+ end
178
+
179
+ when :commit_successful
180
+ @prmt.puts pmsg("\n Changes committed",:green)
181
+ @prmt.puts args.first
182
+
183
+ when :commit_failed
184
+ @prmt.puts pmsg("\n Changes failed to be committed. Error was : #{args.first}")
185
+
186
+ end
187
+ end
188
+ end # commit_new_files block
189
+
190
+ end # commit_new_files
191
+
192
+
23
193
  def commit(*args, &block)
24
194
  res = @inst.commit do |ops, *args|
25
195
 
@@ -60,7 +230,7 @@ module Release
60
230
 
61
231
  end
62
232
 
63
- m.choice "Skip", :skip if mfiles[:counter] == 0
233
+ m.choice "Skip", :skip #if mfiles[:counter] == 0
64
234
  m.choice "Done", :done
65
235
  m.choice "Abort", :abort
66
236
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Release
4
4
  module Gem
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.7"
6
6
  end
7
7
  end
@@ -10,11 +10,16 @@ Release::Gem.engine(:gem, root: Dir.getwd) do
10
10
  # step 1 : run test
11
11
  run_test(:rspec)
12
12
 
13
+ # to allow user to get a view on what's changed
14
+ vcs_cli_overview_changes
15
+
13
16
  gem_cli_action do
14
17
 
15
18
  # step 2 : check dependency
16
19
  release_dependencies
17
20
 
21
+ vcs_cli_commit_new_files
22
+
18
23
  # step 3 : build the gem
19
24
  st, ver = build
20
25
 
@@ -59,6 +59,87 @@ Release::Gem.engine(:gem, root: Dir.getwd, ui: STDOUT) do
59
59
  end
60
60
  end
61
61
 
62
+ ## Check in NEW file first or else the gem build will not pick up by the git ls-files
63
+ vcs_commit_new_files do |ops, *args|
64
+
65
+ case ops
66
+ when :select_files_to_commit
67
+ mfiles = args.first
68
+ pmt.puts "\n Files already added to staging : ".yellow
69
+ mfiles[:staged].each do |k,v|
70
+ v.each do |vv|
71
+ pmt.puts " * #{vv}"
72
+ end
73
+ end
74
+
75
+ pmt.puts ""
76
+
77
+ sel = pmt.multi_select "\n Following are new files that could be added to version control : ".yellow do |m|
78
+
79
+ [:modified, :new, :deleted].each do |cat|
80
+ mfiles[cat].each do |k,v|
81
+ v.each do |vv|
82
+ m.choice vv, vv.path
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ m.choice "Skip", :skip if mfiles[:counter] == 0
89
+ m.choice "Done", :done
90
+ m.choice "Abort", :abort
91
+ end
92
+
93
+ if sel.include?(:abort)
94
+ raise Release::Gem::Abort, "User aborted"
95
+ elsif sel.include?(:skip)
96
+ :skip
97
+ else
98
+ res = :done if sel.include?(:done)
99
+ s = sel.clone
100
+ s.delete_if { |e| e == :done }
101
+ if not_empty?(s)
102
+ st, cres = add_to_staging(*s) if not_empty?(s)
103
+ if st
104
+ pmt.puts "\n Files added successfully".green
105
+ else
106
+ pmt.puts "\n Files failed to be added. Message was : #{cres}".red
107
+ end
108
+ end
109
+
110
+ res
111
+ end
112
+
113
+ when :commit_message
114
+ msg = ""
115
+ loop do
116
+ msg = pmt.ask("\n Commit message : ".yellow, required: true)
117
+ confirm = pmt.yes?(" Commit message : #{msg}\n Proceed? No to provide a new commit message ".yellow)
118
+ if confirm
119
+ break
120
+ end
121
+ end
122
+ msg
123
+
124
+ when :staged_elements_of_commit
125
+ elements = args.first
126
+ pmt.puts "\n Following files/directories shall be committed in this session : ".yellow
127
+ elements.each do |k,v|
128
+ v.each do |vv|
129
+ pmt.puts " * #{vv}"
130
+ end
131
+ end
132
+
133
+ when :commit_successful
134
+ pmt.puts "\n Changes committed".green
135
+
136
+ when :commit_failed
137
+ pmt.puts "\n Changes failed to be committed. Error was : #{args.first}"
138
+
139
+ end
140
+
141
+ end
142
+
62
143
  # step 3 : build the gem
63
144
  st, ver = build do |ops, *args|
64
145
  case ops
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.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
@@ -126,6 +126,7 @@ files:
126
126
  - lib/release/gem/gem_cli_action.rb
127
127
  - lib/release/gem/gem_engine.rb
128
128
  - lib/release/gem/gemdep.rb
129
+ - lib/release/gem/release_infector.rb
129
130
  - lib/release/gem/vcs_action.rb
130
131
  - lib/release/gem/vcs_cli_action.rb
131
132
  - lib/release/gem/version.rb