#!/usr/bin/env ruby require "souls" begin require "./config/souls" unless ARGV[0] == "new" || ARGV[0] == "i" || ARGV[0] == "-v" rescue puts "Make sure you are at SOULs APP directory!" end begin case ARGV[0] when "new" STRAINS = ["api", "worker", "console", "admin", "media"] if ARGV[1].nil? puts Paint["you need to specify your app name", :red] puts Paint["`souls new app_name`", :yellow] exit end first_message = Paint % [ "Select Strain: %{red_text} %{yellow_text} %{green_text} %{blue_text} %{cyan_text}", :white, { red_text: ["\n1. SOULs GraphQL API", :red], yellow_text: ["\n2. SOULs Worker", :yellow], green_text: ["\n3. SOULs Console Web", :green], blue_text: ["\n4. SOULs Admin Web", :blue], cyan_text: ["\n5. SOULs Media Web", :cyan] } ] puts first_message strain = STDIN.gets.chomp.to_i case strain when 1, 2 Souls::Init.download_souls app_name: ARGV[1], repository_name: "souls_#{STRAINS[strain.to_i - 1]}" Souls::Init.initial_config_init app_name: ARGV[1], strain: STRAINS[strain.to_i - 1] else puts Paint["Coming Soon...", :blue] end when "s", "server" strain = Souls.configuration.strain case strain when "media", "admin", "console" system "yarn dev" when "worker" system "bundle exec puma -p 3000 -e development" else system "foreman start -f Procfile.dev" end when "c", "console" strain = Souls.configuration.strain case strain when "media", "admin" system "yarn dev" else case ARGV[1] when "RACK_ENV=production" system "RACK_ENV=production bundle exec irb" else system "bundle exec irb" end end when "i", "infra" Souls.send ARGV[1] when "gcloud" Souls::Gcloud.send ARGV[1] when "-v", "--version" puts Souls::VERSION when "gem:update", "gemfile:update" status = Paint["Checking for updates...", :yellow] Whirly.start spinner: "clock", interval: 1000, stop: "🎉" do Whirly.status = status Souls.update_gemfile Whirly.status = "Done!" end when "add" case ARGV[1] 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 "HOI!" end when "g", "generate" case ARGV[1] when "test_dir" Souls::Generate.test_dir when "model" Souls::Generate.model class_name: ARGV[2] when "mutation" Souls::Generate.mutation class_name: ARGV[2] when "query" Souls::Generate.query class_name: ARGV[2] when "type" Souls::Generate.type class_name: ARGV[2] when "edge" Souls::Generate.edge class_name: ARGV[2] when "connection" Souls::Generate.connection class_name: ARGV[2] when "resolver" Souls::Generate.resolver class_name: ARGV[2] when "policy" Souls::Generate.policy class_name: ARGV[2] when "rspec_factory" Souls::Generate.rspec_factory class_name: ARGV[2] when "rspec_model" Souls::Generate.rspec_model class_name: ARGV[2] when "rspec_mutation" Souls::Generate.rspec_mutation class_name: ARGV[2] when "rspec_query" Souls::Generate.rspec_query class_name: ARGV[2] when "rspec_resolver" Souls::Generate.rspec_resolver class_name: ARGV[2] when "rspec_policy" Souls::Generate.rspec_policy class_name: ARGV[2] when "node_type" Souls::Generate.node_type class_name: ARGV[2] when "job" Souls::Generate.job class_name: ARGV[2] when "migrate" Souls::Generate.single_migrate class_name: ARGV[2] when "migrate_all" Souls::Generate.migrate_all when "migration" class_name = ARGV[2].underscore.pluralize system "rake db:create_migration NAME=create_#{class_name}" when "update" Souls::Generate.update_delete class_name: ARGV[2] Souls::Generate.single_migrate class_name: ARGV[2] else "SOULs!" end when "d" Souls::Generate.delete_all class_name: ARGV[1] when "db:create" case ARGV[1] 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" case ARGV[1] 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" case ARGV[1] when "RACK_ENV=production" system "rake db:seed RACK_ENV=production" else system "rake db:seed" end when "db:migrate:reset" case ARGV[1] 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" system "gcloud builds submit --config=cloudbuild.yml --project #{ARGV[1]}" else puts Paint["Welcome to SOULs!", :green] end rescue StandardError => error puts Paint["Something Wrong...", :red] end