bootic_cli 0.4.1 → 0.4.2

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
  SHA1:
3
- metadata.gz: 2c610888d557df1cea6a07b3e8e11104476c1a7d
4
- data.tar.gz: e1d8c6f28dd1edef01bbbc8e1fb258f33532ccd0
3
+ metadata.gz: 2678e5ad8fef33d47eda0b55c2b014d3da644e42
4
+ data.tar.gz: 3eb8e3690d8d379911dd4528927c8e61c5b27515
5
5
  SHA512:
6
- metadata.gz: 7f492d23d1c5ae13cdd0a78d33578d2b1e61530d35a20cb796c4d6003dcead8bebf2318db4e8b8acad422c6b774cd7890e68eddc0d6217f75923a6eae2e5a986
7
- data.tar.gz: cc766798c0ed812aee7aa24e9464c83809cf7836c1974e1fed6dcc473615afa6374522168dc79ec4d7b0646b643e246520d6c7c43c42899684effbbb52d6eda6
6
+ metadata.gz: 173b6a35f6a715b6e75b2a5c7a4379a198b8d7b045257b8afa66143bf4fa5e87e31f53721fb9fc0e51b7f37263ae429cd92a4f9511ed0b05353286734790e9d4
7
+ data.tar.gz: ac13c53e4b8a6ede30ea4d21bca91defac55146c8245579c36f7eb11fd6ec355c1aa99c13ad76145006469b6b430f3ab92f4fded5cf07238a948ad1600f23ffb
@@ -164,7 +164,7 @@ module BooticCli
164
164
  begin
165
165
  input = shell.ask("#{question} [#{default_char}]").strip
166
166
  rescue Interrupt
167
- say "\nCtrl-C received. Bailing out!", :red
167
+ say "\nCtrl-C received. Bailing out!", :magenta
168
168
  abort
169
169
  end
170
170
 
@@ -86,9 +86,16 @@ module BooticCli
86
86
  setup
87
87
  path = File.join(dir, file_name)
88
88
 
89
+ # remove DOS line endings for new templates
90
+ # or for existing ones that don't have any.
91
+ if !File.exist?(path) or !has_dos_line_endings?(path)
92
+ body = body.gsub(/\r\n?/, "\n")
93
+ end
94
+
89
95
  File.open(path, 'w') do |io|
90
- io.write body
96
+ io.write(body)
91
97
  end
98
+
92
99
  @templates = nil
93
100
  end
94
101
 
@@ -121,6 +128,10 @@ module BooticCli
121
128
 
122
129
  attr_reader :dir
123
130
 
131
+ def has_dos_line_endings?(path)
132
+ !!IO.read(path)["\r\n"]
133
+ end
134
+
124
135
  def paths_for(patterns)
125
136
  patterns.reduce([]) {|m, pattern| m + Dir[File.join(dir, pattern)]}
126
137
  end
@@ -4,16 +4,17 @@ require 'bootic_cli/themes/missing_items_theme'
4
4
  module BooticCli
5
5
  module Themes
6
6
  class ThemeDiff
7
- def initialize(source:, target:)
7
+ def initialize(source:, target:, force_update:)
8
8
  @source, @target = source, target
9
+ @force_update = force_update
9
10
  end
10
11
 
11
12
  def updated_in_source
12
- @updated_in_source ||= UpdatedTheme.new(source: source, target: target)
13
+ @updated_in_source ||= UpdatedTheme.new(source: source, target: target, force_update: force_update)
13
14
  end
14
15
 
15
16
  def updated_in_target
16
- @updated_in_target ||= UpdatedTheme.new(source: target, target: source)
17
+ @updated_in_target ||= UpdatedTheme.new(source: target, target: source, force_update: force_update)
17
18
  end
18
19
 
19
20
  def missing_in_target
@@ -25,7 +26,7 @@ module BooticCli
25
26
  end
26
27
 
27
28
  private
28
- attr_reader :source, :target
29
+ attr_reader :source, :target, :force_update
29
30
  end
30
31
  end
31
32
  end
@@ -8,14 +8,17 @@ module BooticCli
8
8
  class UpdatedTheme
9
9
  TemplateWithDiff = Struct.new('TemplateWithDiff', :file_name, :body, :updated_on, :diff)
10
10
 
11
- def initialize(source:, target:)
11
+ def initialize(source:, target:, force_update: false)
12
12
  @source, @target = source, target
13
+ # when doing a pull or push, we don't care if the other end has a more recent version
14
+ # we only do that when syncing changes, in which case force_update should be false
15
+ @force_update = force_update
13
16
  end
14
17
 
15
18
  def templates
16
19
  @templates ||= map_pair(source.templates, target.templates) do |a, b|
17
20
  diff = Diffy::Diff.new(normalize_endings(b.body), normalize_endings(a.body), context: 1)
18
- if more_recent?(a, b) && !diff.to_s.empty?
21
+ if !diff.to_s.empty? && should_update?(a, b)
19
22
  c = TemplateWithDiff.new(a.file_name, a.body, a.updated_on, diff)
20
23
  [true, c]
21
24
  else
@@ -26,12 +29,16 @@ module BooticCli
26
29
 
27
30
  def assets
28
31
  @assets ||= map_pair(source.assets, target.assets) do |a, b|
29
- [more_recent?(a, b), a]
32
+ [should_update?(a, b), a]
30
33
  end
31
34
  end
32
35
 
33
36
  private
34
- attr_reader :source, :target
37
+ attr_reader :source, :target, :force_update
38
+
39
+ def should_update?(a, b)
40
+ force_update || more_recent?(a, b)
41
+ end
35
42
 
36
43
  def more_recent?(a, b)
37
44
  a.updated_on > b.updated_on
@@ -32,7 +32,7 @@ module BooticCli
32
32
  end
33
33
 
34
34
  def pull(local_theme, remote_theme, delete: true)
35
- diff = ThemeDiff.new(source: local_theme, target: remote_theme)
35
+ diff = ThemeDiff.new(source: local_theme, target: remote_theme, force_update: true)
36
36
  check_dupes!(local_theme.assets)
37
37
 
38
38
  download_opts = {
@@ -61,7 +61,7 @@ module BooticCli
61
61
  end
62
62
 
63
63
  def push(local_theme, remote_theme, delete: true)
64
- diff = ThemeDiff.new(source: local_theme, target: remote_theme)
64
+ diff = ThemeDiff.new(source: local_theme, target: remote_theme, force_update: true)
65
65
  check_dupes!(local_theme.assets)
66
66
 
67
67
  notice 'Pushing local changes to remote...'
@@ -1,3 +1,3 @@
1
1
  module BooticCli
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootic_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis