exe/shatter in shatter-rb-0.0.2 vs exe/shatter in shatter-rb-0.1.0
- old
+ new
@@ -1,64 +1,74 @@
#!/usr/bin/env ruby
-require 'shatter'
-require 'thor'
-require 'erb'
+# frozen_string_literal: true
+
+require "shatter"
+require "thor"
+require "erb"
+require "fileutils"
+require 'zk'
$stdout.sync = true
def safe_makedir(path)
FileUtils.mkdir(path, noop: Dir.exist?(path), verbose: true)
end
class ShatterCLI < Thor
desc "init_service_discovery", "Sets up required keys for service discovery to work properly"
+ desc "init_service_discovery", "creates necessary keys in zookeeper"
def init_service_discovery
+ Shatter.load_environment
zk = ZK.new(Shatter::Config.zookeeper_host)
- zk.create('/shater_service_instances')
- zk.create('/shatter::response_data_locations')
+ [
+ Shatter::Util.instances_key,
+ Shatter::Util.zookeeper_response_key_root,
+ ].each do |key|
+ next if zk.exists?(key)
+ zk.create(key)
+ end
zk.close
end
+ desc "generate_typescript", "generates typescript defs of your service definition"
+ option :path
+ def generate_typescript
+ Shatter.load_environment
+ File.open("#{Shatter.root}/#{options[:path]}/Client.ts", "w") { |f| f.write(ServiceDefinition.to_typescript) }
+ end
+
desc "new APP_NAME", "scaffold a new shatter app"
def new(app_name)
puts "Generating new Shatter APP - #{app_name}"
puts "Updating Gemfile"
- FileUtils.cp("#{__dir__}/../templates/Gemfile.template","./Gemfile")
+ ::FileUtils.cp("#{__dir__}/../templates/Gemfile.template", "./Gemfile")
system("bundle install")
puts "Generating scripts"
- FileUtils.mkdir("./bin", noop: Dir.exist?('./bin'))
+ FileUtils.mkdir("./bin", noop: Dir.exist?("./bin"))
FileUtils.cp("#{__dir__}/../bin/service", "./bin/service", verbose: true)
FileUtils.cp("#{__dir__}/../bin/server", "./bin/server", verbose: true)
puts "Generating boilerplate"
application_code = ERB.new(File.read("#{__dir__}/../templates/application.erb")).result(binding)
- File.open("./application.rb", "w") do |f|
- f.write application_code
- end
+ safe_makedir("./app")
+ File.write("./app/application.rb", application_code)
FileUtils.cp("#{__dir__}/../templates/config.ru", "./config.ru", verbose: true)
FileUtils.cp("#{__dir__}/../templates/docker-compose.yml.example", "./docker-compose.yml", verbose: true)
- safe_makedir('./app')
service_definition = ERB.new(File.read("#{__dir__}/../templates/service_definition.rb.erb")).result(binding)
- File.open("./app/service_definition.rb", "w") do |f|
- f.write service_definition
- end
+ File.write("./app/service_definition.rb", service_definition)
- safe_makedir('./app/functions')
+ safe_makedir("./app/functions")
sample_function = ERB.new(File.read("#{__dir__}/../templates/hello_world_function.rb.erb")).result(binding)
- File.open("./app/functions/hello_world_function.rb", "w") do |f|
- f.write sample_function
- end
- safe_makedir('./config')
+ File.write("./app/functions/hello_world_function.rb", sample_function)
+ safe_makedir("./config")
environment_config = ERB.new(File.read("#{__dir__}/../templates/environment.rb.erb")).result(binding)
- File.open("./config/environment.rb", "w") do |f|
- f.write environment_config
- end
+ File.write("./config/environment.rb", environment_config)
end
end
-ShatterCLI.start(ARGV)
\ No newline at end of file
+ShatterCLI.start(ARGV)