#!/usr/bin/env ruby require "souls" begin require("./config/souls") unless ARGV[0] == "new" || ARGV[0] == "i" || ARGV[0] == "-v" || ARGV[0] == "deploy" rescue StandardError puts("Make sure you are at SOULs APP directory!") end begin souls_command = ARGV[0] case souls_command when "new" args = ARGV Souls::Init.return_method(args) when "s", "server" strain = Souls.configuration.strain case strain when "media", "admin", "console", "doc" system("yarn dev") else system("foreman start -f Procfile.dev") end when "c", "console" strain = Souls.configuration.strain case strain when "media", "admin", "console", "doc" system("yarn dev") else rack_env = ARGV[1] case rack_env when "RACK_ENV=production" system("RACK_ENV=production bundle exec irb") else system("bundle exec irb") end end when "i", "infra" send_method = ARGV[1] Souls.public_send(send_method) when "gcloud" args = ARGV status = Paint["Running Gcloud Commands...", :yellow] Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do Whirly.status = status Souls::Gcloud.return_method(args) Whirly.status = "Done!" end when "-v", "--version" puts(Paint[Souls::VERSION, :white]) when "gem:update", "gemfile:update" status = Paint["Checking for updates...", :yellow] Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do Whirly.status = status Souls.update_gemfile Whirly.status = "Done!" end when "release" Souls::Release.return_method when "model:update" status = Paint["Updating Models...", :yellow] Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do Whirly.status = status Souls.update_models Whirly.status = "Done!" end when "add" graphql_class = ARGV[1] case graphql_class when "mutation" Souls::Init.add_mutation(class_name: "user", file_name: "hoi") when "type" Souls::Init.add_type(class_name: "user", file_name: "hoi") when "connection" Souls::Init.add_connection(class_name: "user", file_name: "hoi") when "edge" Souls::Init.add_edge(class_name: "user", file_name: "hoi") when "rspec_mutation" Souls::Init.add_rspec_mutation(class_name: "user", file_name: "hoi") else puts(Paint["Wrong Argument!", :red]) end when "g", "generate" args = ARGV status = Paint["Generating Files...", :yellow] done = Paint["You're All Set ☻", :yellow] Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do Whirly.status = status Souls::Generate.return_method(args) Whirly.status = done end when "d", "delete" class_name = ARGV[1] Souls::Generate.delete_all(class_name: class_name) when "db:create" rack_env = ARGV[1] case rack_env when "RACK_ENV=production" system("rake db:create RACK_ENV=production") else system("rake db:create && rake db:create RACK_ENV=test") end when "db:migrate" rack_env = ARGV[1] case rack_env when "RACK_ENV=production" system("rake db:migrate RACK_ENV=production") else system("rake db:migrate && rake db:migrate RACK_ENV=test") end when "db:seed" rack_env = ARGV[1] case rack_env when "RACK_ENV=production" system("rake db:seed RACK_ENV=production") else system("rake db:seed") end when "db:migrate:reset" rack_env = ARGV[1] case rack_env when "RACK_ENV=production" system("rake db:migrate:reset RACK_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1") else system("rake db:migrate:reset && rake db:migrate:reset RACK_ENV=test") end when "db:update" strain = Souls.configuration.strain case strain when "api" other_app = Souls.configuration.worker_name when "worker" other_app = Souls.configuration.api_name else raise(StandardError, "Unknown app name!") end system("rm -rf ../#{other_app}/db/*") system("cp -r ./db/* ../#{other_app}/db/*") when "t", "test" system("rubocop -A") system("bundle exec rspec") when "run" system("docker build . -t souls -f Dockerfile.dev") system("docker run --rm --env-file .env -p 3000:3000 souls:latest") when "deploy" project_id = Souls.configuration.project_id system("gcloud builds submit --config=cloudbuild.yml --project #{project_id}") else puts(Paint["Welcome to SOULs!", :green]) end rescue StandardError => e puts(Paint[e, :red]) end