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
|
# File 'lib/zoomq/cli.rb', line 40
def generate(name)
if File.exist?(name)
puts "!!! #{name} already exists"
exit(1)
end
puts ">>> Generating ZooMQ skeleton for #{name}"
constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
constant_array = constant_name.split('::')
config.merge!({
name: name,
constant_name: constant_name,
constant_array: constant_array,
})
{
"Gemfile" => "Gemfile",
"Rakefile" => "Rakefile",
"LICENSE.txt" => "LICENSE.txt",
"README.md" => "README.md",
".gitignore" => "gitignore",
"#{name}.gemspec" => "gemspec",
"bin/#{name}" => "binwrapper",
"bin/#{name}-console" => "console",
"config.yml" => "config.yml",
"config/mixins/production.yml" => "production.yml",
"config/mixins/staging.yml" => "staging.yml",
"config/mixins/testing.yml" => "testing.yml",
"lib/#{name}/protocol.proto" => "protocol.proto",
"lib/#{name}/protocol.rb" => "protocol.rb",
"lib/#{name}/client.rb" => "client.rb",
"#{name}/console.rb" => "console.rb",
"#{name}/server.rb" => "server.rb",
"#{name}/server/ping_request.rb" => "ping_request.rb",
}.each do |dest, source|
puts " * #{dest}"
source = File.join(@root, 'templates', "#{source}.tt")
dest = File.join(name, dest)
FileUtils.mkdir_p(File.dirname(dest))
input = File.read(source)
eruby = Erubis::Eruby.new(input)
output = File.open(dest, "w")
output.write(eruby.result(binding()))
output.close
end
Dir.chdir(name) do
puts ">>> Installing dependencies"
system("bundle install")
puts ">>> Generating protocol"
system("rake protoc")
system("chmod +x bin/*")
end
end
|