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.
- data/lib/guard/mirror.rb +22 -19
- 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
|
38
|
+
UI.info 'A mirror has started.'
|
39
39
|
run_all
|
40
40
|
end
|
41
41
|
|
42
42
|
def run_all
|
43
|
-
UI.info
|
44
|
-
|
45
|
-
@options[:target]
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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 |
|
55
|
-
dest = src_to_dest
|
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 #{
|
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[
|
63
|
-
rescue
|
64
|
-
e
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|