#!/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", "media", "admin"] if ARGV[1].nil? puts "you need to specify your app name \n `souls new app_name`" exit end puts "Which framework: \n 1. SOULs GraphQL API \n 2. SOULs Worker \n 3. SOULs Media Web \n 4. SOULs Admin Web \n Enter Number: " strain = STDIN.gets.chomp.to_i (1..4).include?(strain) ? puts("Generating SOULs.. \n") : raise(StandardError, "Choose Number 1..4") 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] when "s", "server" strain = Souls.configuration.strain case strain when "media", "admin" 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 "-v", "--version" puts Souls::VERSION 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 "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" system "rake db:create_migration NAME=create_#{ARGV[2]}" else "SOULs!" end when "d" Souls::Generate.delete_all class_name: ARGV[1] when "update" Souls::Generate.add_delete class_name: ARGV[1] Souls::Generate.single_migrate class_name: ARGV[1] when "db:create" system "rake db:create && rake db:create RACK_ENV=test" 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 "t", "test" system "rubocop -a" system "bundle exec rspec" when "run" system "docker build . -t souls:latest" system "docker run --rm -p 3000:3000 souls:latest" when "deploy" system "gcloud builds submit --config=cloudbuild.yml --project #{ARGV[1]}" else puts "Welcome to SOULs!" end rescue StandardError => error puts error.backtrace puts "Thank you!!" puts "SOULs" end