require_relative "souls/version" require "active_support/core_ext/string/inflections" require_relative "souls/init" require_relative "souls/generate" require_relative "souls/gcloud" require "json" require "fileutils" require "net/http" require "paint" module Souls SOULS_METHODS = [ "model", "query", "mutation", "type", "resolver", "policy", "rspec_factory", "rspec_model", "rspec_query", "rspec_mutation", "rspec_resolver", "rspec_policy" ] class Error < StandardError; end class << self attr_accessor :configuration def run_psql system "docker run --rm -d \ -p 5433:5432 \ -v postgres-tmp:/var/lib/postgresql/data \ -e POSTGRES_USER=postgres \ -e POSTGRES_PASSWORD=postgres \ -e POSTGRES_DB=souls_test \ postgres:13-alpine" system "docker ps" end def run_mysql system "docker run --rm -d \ -p 3306:3306 \ -v mysql-tmp:/var/lib/mysqlql/data \ -e MYSQL_USER=mysql \ -e MYSQL_PASSWORD=mysql \ -e MYSQL_DB=souls_test \ mysql:latest" system "docker ps" end def run_awake url app = Souls.configuration.app system "gcloud scheduler jobs create http #{app}-awake --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET" end def gemfile_latest_version file_path = "./Gemfile" updated_gems = [] updated_gem_versions = [] updated_lines = [] console_log = [] File.open(file_path, "r") do |f| f.each_line do |line| next unless line.include? "gem " gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",") url = URI("https://rubygems.org/api/v1/versions/#{gem[0]}/latest.json") res = Net::HTTP.get_response(url) data = JSON.parse res.body next if data["version"].to_s == gem[1].to_s updated_lines << "gem \"#{gem[0]}\", \"#{data["version"]}\"" updated_gems << (gem[0]).to_s updated_gem_versions << data["version"] system "gem update #{gem[0]}" console_log << "#{gem[0]} v#{gem[1]} → v#{data["version"]}" end end { gems: updated_gems, lines: updated_lines, console_log: console_log, updated_gem_versions: updated_gem_versions } end def update_gemfile file_path = "./Gemfile" tmp_file = "./tmp/Gemfile" new_gems = gemfile_latest_version logs = [] return "Already Up to date!" && puts("Already Up to date!") if new_gems[:gems].blank? @i = 0 File.open(file_path, "r") do |f| File.open(tmp_file, "w") do |new_line| f.each_line do |line| gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",") if new_gems[:gems].include? gem[0] logs << Paint % [ "#{gem[0]} %{yellow_text} → %{green_text}", :blue, { yellow_text: ["v#{gem[1]}", :yellow], green_text: ["v#{new_gems[:updated_gem_versions][@i]}", :green] } ] new_line.write "#{new_gems[:lines][@i]}\n" @i += 1 else new_line.write line end end end end FileUtils.rm "./Gemfile" FileUtils.rm "./Gemfile.lock" FileUtils.mv "./tmp/Gemfile", "./Gemfile" system "bundle update" success = Paint["\n\nSuccessfully Updated These Gems!\n", :green] puts success logs.each do |line| puts line end end end def self.configure self.configuration ||= Configuration.new yield(configuration) end class Configuration attr_accessor :app, :strain, :project_id, :worker_name, :api_name def initialize @app = nil @project_id = nil @strain = nil @worker_name = nil @api_name = nil end end end