-
Notifications
You must be signed in to change notification settings - Fork 1
/
autopush.watchr
executable file
·75 lines (56 loc) · 1.53 KB
/
autopush.watchr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env watchr
require 'rubygems'
# require 'couchrest'
require 'json'
begin
require 'ruby-growl'
is_growl = true
rescue LoadError
puts "growl skiped ..."
end
Signal.trap('INT') { abort("\nTerminated Successfuly.") } # Ctrl-C
def check_file(filename)
filepath = File.join(Dir.pwd, filename)
unless File.exist?(filepath)
puts "missing #{filename}"
exit
end
filepath
end
def push(appname, growl)
if growl
growl.notify("CouchApp AutoPush", "CouchAPP '#{appname}' Pushed", "default & test", 1, true)
end
# couch = CouchRest.new("http://localhost:5984")
# db = couch.database!(dbname)
# puts "cleanup test database!"
# db.documents["rows"].each do |doc|
# unless doc["id"] == "_design/#{appname}"
# puts "removing : #{doc}"
# db.delete_doc({"_id" => doc["id"], "_rev" => doc["value"]["rev"]})
# end
# end
run "soca push test"
run "soca push"
end
def run(cmd)
puts cmd
system cmd
end
# couchapprc = check_file(".couchapprc")
# couchapprc = JSON.parse(File.read(couchapprc))
# dbname = couchapprc["env"]["test"]["db"].match(/\d\/(\S*)$/m)[1]
configjs = check_file("config.js")
configjs = JSON.parse(File.read(configjs))
appname = configjs["id"]
if is_growl
growl = Growl.new("localhost", "ruby-growl", ["CouchApp AutoPush"])
growl.notify("CouchApp AutoPush", "CouchAPP Pusher Started", "default & test.", 1, true)
end
push(appname, growl)
watch('.*') do |m|
unless m[0].match(/\/.idea\//) or m[0].match(/\/.git\//)
puts "#{m[0]} was changed."
push(appname, growl)
end
end