caravan 0.4.0 → 0.5.0.alpha1
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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -4
- data/.travis.yml +1 -0
- data/README.md +6 -1
- data/caravan.gemspec +2 -2
- data/lib/caravan/deploy.rb +100 -10
- data/lib/caravan/deploy_methods/rsync.rb +2 -2
- data/lib/caravan/deploy_methods/rsync_local.rb +2 -2
- data/lib/caravan/deploy_methods/scp.rb +2 -2
- data/lib/caravan/deploy_methods/shell.rb +26 -2
- data/lib/caravan/version.rb +1 -1
- data/lib/caravan.rb +12 -15
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba029c54b538361378d648eb8e1bd8cc78079a1b
|
4
|
+
data.tar.gz: cc59b3a03e11ae33e636aa4feac5261c5a239de8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6425491bd500a8ce5d21362b8d01667a317d15a9f61772c8f70b09341605049dae897d13058545b9f1600ad8ad93c059438adef9ec131b9ebd05abe6f3ac197d
|
7
|
+
data.tar.gz: 4350a3578c5c0bfdfe99763f5a0c6d34ba04cc255c3b8619bf68bb5db721477f536df68c7b4a5a939915ee0d686f687592b31a2a997e655484b13d05884024cf
|
data/.codeclimate.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -60,7 +60,12 @@ exclude:
|
|
60
60
|
- [x] Exclude watching unwanted files
|
61
61
|
- [x] `caravan.yml` for project-specialized configuration
|
62
62
|
- [ ] Watch and deploy only the changed file instead of the whole folder
|
63
|
-
- [
|
63
|
+
- [x] Callbacks for deployment
|
64
|
+
- [x] `after_create`
|
65
|
+
- [x] `after_change`
|
66
|
+
- [x] `before_deploy`
|
67
|
+
- [x] `after_deploy`
|
68
|
+
- [x] `before_destroy`
|
64
69
|
- [ ] Multiple deployment configurations
|
65
70
|
|
66
71
|
## LICENSE
|
data/caravan.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["David Zhang"]
|
10
10
|
spec.email = ["crispgm@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Simple watcher and deployer}
|
13
|
-
spec.description = %q{Caravan is a simple file watcher and deployer for local development.}
|
12
|
+
spec.summary = %q{Simple project files watcher and deployer}
|
13
|
+
spec.description = %q{Caravan is a simple file watcher and deployer of project files for local development.}
|
14
14
|
spec.homepage = "https://crispgm.github.io/caravan/"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
data/lib/caravan/deploy.rb
CHANGED
@@ -3,42 +3,132 @@ require "colorize"
|
|
3
3
|
module Caravan
|
4
4
|
module Deploy
|
5
5
|
class << self
|
6
|
-
def create_deployer(method = "shell")
|
6
|
+
def create_deployer(src, dst, method = "shell")
|
7
7
|
case method
|
8
8
|
when "shell"
|
9
|
-
|
9
|
+
Caravan::DeployMethods::Shell.new(src, dst)
|
10
10
|
when "scp"
|
11
|
-
|
11
|
+
Caravan::DeployMethods::Scp.new(src, dst)
|
12
12
|
when "rsync"
|
13
|
-
|
13
|
+
Caravan::DeployMethods::Rsync.new(src, dst)
|
14
14
|
when "rsync_local"
|
15
|
-
|
15
|
+
Caravan::DeployMethods::RsyncLocal.new(src, dst)
|
16
16
|
else
|
17
17
|
Message.error("Unknown deploy method \"#{method}\"")
|
18
|
-
|
18
|
+
nil
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
class Base
|
24
24
|
attr_accessor :debug
|
25
|
+
attr_reader :src, :dst
|
25
26
|
|
26
|
-
def initialize
|
27
|
+
def initialize(src, dst)
|
27
28
|
Message.info("Creating #{self.class.name}...")
|
29
|
+
@src = src
|
30
|
+
@dst = dst
|
28
31
|
@debug = false
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
34
|
+
def handle_change(modified, added, removed)
|
35
|
+
@modified = modified
|
36
|
+
@added = added
|
37
|
+
@removed = removed
|
38
|
+
|
39
|
+
after_change
|
40
|
+
end
|
41
|
+
|
42
|
+
def after_create
|
43
|
+
Message.info("#{self.class.name} is created.")
|
44
|
+
|
45
|
+
if block_given?
|
46
|
+
ret_val = yield
|
47
|
+
debug_msg("Block `after_create` returned #{ret_val}")
|
48
|
+
false if ret_val == false
|
49
|
+
end
|
50
|
+
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
def after_change
|
55
|
+
@modified.each do |change|
|
56
|
+
Caravan::Message.info("#{change} was changed.")
|
57
|
+
end
|
58
|
+
|
59
|
+
@added.each do |change|
|
60
|
+
Caravan::Message.info("#{change} was created.")
|
61
|
+
end
|
62
|
+
|
63
|
+
@removed.each do |change|
|
64
|
+
Caravan::Message.info("#{change} was removed.")
|
65
|
+
end
|
66
|
+
|
67
|
+
if block_given?
|
68
|
+
ret_val = yield @modified, @added, @removed
|
69
|
+
debug_msg("Block `after_change` returned #{ret_val}")
|
70
|
+
false if ret_val == false
|
71
|
+
end
|
72
|
+
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
def before_deploy
|
77
|
+
if block_given?
|
78
|
+
ret_val = yield
|
79
|
+
debug_msg("Block `before_deploy` returned #{ret_val}")
|
80
|
+
false if ret_val == false
|
81
|
+
end
|
82
|
+
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def run
|
32
87
|
time_str = Time.now.strftime("%H:%M:%S").green
|
33
88
|
Message.info("#{time_str} Deploying #{src} to #{dst}...")
|
34
89
|
|
35
90
|
status = 0
|
36
91
|
if block_given?
|
37
92
|
status, output = yield src, dst
|
93
|
+
debug_msg("Block `run` returned #{status}")
|
94
|
+
end
|
95
|
+
|
96
|
+
Message.error("Deploying block returned false") unless status == 0
|
97
|
+
status
|
98
|
+
end
|
99
|
+
|
100
|
+
def after_deploy
|
101
|
+
if block_given?
|
102
|
+
ret_val = yield
|
103
|
+
debug_msg("Block `after_deploy` returned #{ret_val}")
|
104
|
+
false if ret_val == false
|
105
|
+
end
|
106
|
+
|
107
|
+
true
|
108
|
+
end
|
109
|
+
|
110
|
+
def before_destroy
|
111
|
+
if block_given?
|
112
|
+
ret_val = yield
|
113
|
+
debug_msg("Block `before_destroy` returned #{ret_val}")
|
114
|
+
false if ret_val == false
|
38
115
|
end
|
39
116
|
|
40
|
-
|
41
|
-
|
117
|
+
true
|
118
|
+
end
|
119
|
+
|
120
|
+
def relative_path(path)
|
121
|
+
working_dir = Dir.pwd
|
122
|
+
path_routes = path.split(working_dir)
|
123
|
+
return nil if path_routes.nil? || path_routes.empty? || path_routes.size < 2
|
124
|
+
|
125
|
+
path_routes[-1]
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def debug_msg(msg)
|
131
|
+
Caravan::Message.debug(msg) if @debug
|
42
132
|
end
|
43
133
|
end
|
44
134
|
end
|
@@ -1,11 +1,35 @@
|
|
1
1
|
module Caravan
|
2
2
|
module DeployMethods
|
3
3
|
class Shell < Caravan::Deploy::Base
|
4
|
-
def
|
5
|
-
super
|
4
|
+
def after_create
|
5
|
+
super do
|
6
|
+
Caravan::Message.info("Notice: Shell Deployer is like copy, mainly designed for test.")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def before_deploy
|
11
|
+
super do
|
12
|
+
Caravan::Message.info("Hook: before_deploy")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
super do |s, d|
|
6
18
|
Caravan::Command.run("cp -r #{s} #{d}", @debug)
|
7
19
|
end
|
8
20
|
end
|
21
|
+
|
22
|
+
def after_deploy
|
23
|
+
super do
|
24
|
+
Caravan::Message.info("Hook: after_deploy")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def before_destroy
|
29
|
+
super do
|
30
|
+
Caravan::Message.info("Deployer destroyed")
|
31
|
+
end
|
32
|
+
end
|
9
33
|
end
|
10
34
|
end
|
11
35
|
end
|
data/lib/caravan/version.rb
CHANGED
data/lib/caravan.rb
CHANGED
@@ -24,39 +24,36 @@ module Caravan
|
|
24
24
|
|
25
25
|
Caravan::Config.pretty_puts(merged_conf)
|
26
26
|
|
27
|
-
deployer = Caravan::Deploy.create_deployer(deploy_mode)
|
27
|
+
deployer = Caravan::Deploy.create_deployer(src_path, target_path, deploy_mode)
|
28
28
|
deployer.debug = true if debug
|
29
|
-
if deployer.nil?
|
30
|
-
exit -1
|
31
|
-
end
|
29
|
+
exit(-1) if deployer.nil?
|
32
30
|
|
33
|
-
listener = create_listener(deployer, src_path
|
31
|
+
listener = create_listener(deployer, src_path)
|
34
32
|
ignores.each do |item|
|
35
33
|
listener.ignore(Regexp.compile(item))
|
36
34
|
end
|
37
35
|
|
38
36
|
Caravan::Message.success("Starting to watch #{src_path}...")
|
39
|
-
deployer.
|
37
|
+
deployer.after_create
|
40
38
|
listener.start
|
41
39
|
|
42
40
|
trap("INT") do
|
43
41
|
listener.stop
|
42
|
+
deployer.before_destroy
|
44
43
|
Caravan::Message.success("\tHalting watching.")
|
45
|
-
exit
|
44
|
+
exit(0)
|
46
45
|
end
|
47
46
|
|
48
47
|
sleep_forever
|
49
48
|
end
|
50
49
|
|
51
|
-
def create_listener(deployer, src_path
|
50
|
+
def create_listener(deployer, src_path)
|
52
51
|
Listen.to(src_path) do |modified, added, removed|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
deployer.run(src_path, target_path)
|
59
|
-
end
|
52
|
+
# rubocop:disable Lint/NonLocalExitFromIterator
|
53
|
+
return unless deployer.handle_change(modified, added, removed)
|
54
|
+
return unless deployer.before_deploy
|
55
|
+
deployer.run
|
56
|
+
deployer.after_deploy
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caravan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Zhang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|
@@ -108,7 +108,8 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.0.0
|
111
|
-
description: Caravan is a simple file watcher and deployer for local
|
111
|
+
description: Caravan is a simple file watcher and deployer of project files for local
|
112
|
+
development.
|
112
113
|
email:
|
113
114
|
- crispgm@gmail.com
|
114
115
|
executables:
|
@@ -152,13 +153,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
153
|
version: '0'
|
153
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
155
|
requirements:
|
155
|
-
- - "
|
156
|
+
- - ">"
|
156
157
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
158
|
+
version: 1.3.1
|
158
159
|
requirements: []
|
159
160
|
rubyforge_project:
|
160
161
|
rubygems_version: 2.6.11
|
161
162
|
signing_key:
|
162
163
|
specification_version: 4
|
163
|
-
summary: Simple watcher and deployer
|
164
|
+
summary: Simple project files watcher and deployer
|
164
165
|
test_files: []
|