guard-mirror 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/guard/mirror.rb +22 -19
  2. metadata +1 -1
data/lib/guard/mirror.rb CHANGED
@@ -35,39 +35,42 @@ module ::Guard
35
35
  end
36
36
 
37
37
  def start
38
- UI.info "A mirror has started."
38
+ UI.info 'A mirror has started.'
39
39
  run_all
40
40
  end
41
41
 
42
42
  def run_all
43
- UI.info "Mirroring all files..."
44
- run_on_changes(
45
- @options[:target] ?
46
- [@options[:target]] :
47
- Dir[File.join @env.paths.first, '**{,/*/**}.*'].map do |path|
48
- path[@env.paths.first.length + 1 .. -1]
49
- end
50
- )
43
+ UI.info 'Mirroring all files...'
44
+ if @options[:target]
45
+ paths = [@options[:target]]
46
+ else
47
+ paths = @env.paths.map do |path|
48
+ Dir[File.join path, '**{,/*/**}.*'].map do |file|
49
+ file[path.length + 1 .. -1]
50
+ end
51
+ end.flatten
52
+ end
53
+ run_on_changes paths
51
54
  end
52
55
 
53
56
  def run_on_changes paths
54
- (@options[:target] ? [@options[:target]] : paths).each do |src|
55
- dest = src_to_dest src
57
+ (@options[:target] ? [@options[:target]] : paths).each do |path|
58
+ dest = src_to_dest path
56
59
  dirname = File.dirname dest
57
- UI.info "Mirroring #{src} -> #{dest}"
60
+ UI.info "Mirroring #{path}..."
58
61
  FileUtils.mkdir_p dirname unless File.directory? dirname
59
62
  File.open(dest, 'w') do |f|
60
63
  f.write(
61
64
  begin
62
- @env[src]
63
- rescue ExecJS::ProgramError => e
64
- e
65
- rescue ExecJS::RuntimeError => e
66
- e
67
- end)
65
+ @env[path]
66
+ rescue => e
67
+ UI.error e.message
68
+ e.message
69
+ end
70
+ )
68
71
  end
72
+ UI.info "Saved to #{dest}."
69
73
  end
70
- UI.info 'Done.'
71
74
  end
72
75
 
73
76
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-mirror
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: