-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.rb
109 lines (89 loc) · 3.1 KB
/
compile.rb
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require 'json'
# requires path of the parent folder where your deploy scripts live
# => ex: `ruby ./compile.rb /Users/matthew.retzer/bookmaker_local`
unescapeargv = ARGV[0].chomp('"').reverse.chomp('"').reverse
scripts_dir = File.expand_path(unescapeargv)
scripts_dir = scripts_dir.split(Regexp.union(*[File::SEPARATOR, File::ALT_SEPARATOR].compact)).join(File::SEPARATOR)
# The addon files JSON
file = File.join(scripts_dir, "bookmaker_deploy", "scripts.json")
json = File.read(file)
deploy_hash = JSON.parse(json)
# figure out which addon files to apply
projects = []
templatesdir = File.join(scripts_dir, "bookmaker_deploy", "templates")
default_header = File.join(scripts_dir, "bookmaker_deploy", "templates", "_header.bat")
midfile = File.join(scripts_dir, "bookmaker_deploy", "templates", "_mid.bat")
footerfile = File.join(scripts_dir, "bookmaker_deploy", "templates", "_footer.bat")
loggerline = ">> %logfile% 2>&1 && call :ProcessLogger"
rubycmd = "ruby"
corepath = "S:\\resources\\bookmaker_scripts\\bookmaker\\core"
addonspath = "S:\\resources\\bookmaker_scripts\\bookmaker_addons"
pitstoppath = "S:\\resources\\bookmaker_scripts\\pitstop_watch"
deploy_hash['projects'].each do |p|
filename = p['name']
filepath = File.join(scripts_dir, "bookmaker_deploy", "#{filename}")
if p.key?("extra_argv")
p_extra_args = p['extra_argv']
else
p_extra_args = ''
end
if p.key?("header")
alt_header_path = File.join(templatesdir, p['header'])
header = File.read(alt_header_path)
else
header = File.read(default_header)
end
mid = File.read(midfile)
footer = File.read(footerfile)
scripts = p['scripts']
unless p['processwatch'] == true
header = ""
end
File.open(filepath, 'w+') do |f|
f.puts header
end
scripts.each do |s|
deploy_hash['scripts'].each do |f|
if f['name'] == s['name']
processwatcher = " echo #{f['testvalue']}"
File.open(filepath, 'a+') do |f|
f.puts processwatcher
end
end
end
end
if p['statuscheck'] == true
mid = mid.gsub(/REM STATUSHERE/, "echo status_check")
else
mid = mid.gsub(/REM STATUSHERE/, '')
end
unless p['processwatch'] == true
mid = ""
end
File.open(filepath, 'a+') do |f|
f.puts mid
end
scripts.each do |s|
deploy_hash['scripts'].each do |f|
if f['name'] == s['name']
runcommand = "#{f['command']} #{f['location']} #{f['argv']}#{p_extra_args}#{loggerline} #{f['testvalue']}"
runcommand = runcommand.gsub(/RUBYCMD/,rubycmd).gsub(/BKMKRCORE/,corepath).gsub(/BKMKRADDONS/,addonspath).gsub(/PITSTOP/,pitstoppath).gsub(/\s\s/," ")
File.open(filepath, 'a+') do |f|
f.puts runcommand
end
end
end
end
unless p['processwatch'] == true
footer = ""
end
statusline = "#{rubycmd} S:\\resources\\bookmaker_scripts\\utilities\\bookmaker_status_checker.rb '%1' >> %logfile% 2>&1 && call :ProcessLogger status_check"
if p['statuscheck'] == true
footer = footer.gsub(/REM STATUSHERE/,statusline)
else
footer = footer.gsub(/REM STATUSHERE/,"")
end
File.open(filepath, 'a+') do |f|
f.puts footer
end
end