Sha256: 1fa9048a5f5e35d94531ec0a302bddd7334a5d8d6c6f818be10e440e2593193c

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

module Souls
  class Sync < Thor
    # rubocop:disable Style/StringHashKeys
    map "models" => :model
    # rubocop:enable Style/StringHashKeys

    desc "model", "Sync Model, DB, Factory Files with API"
    def model
      cp_dir = %w[db app/models spec/factories]
      cp_dir.each do |dir|
        cp_and_dl_files(dir: dir)
        cp_env_files
      end
      puts(Paint % ["Synced! : %{white_text}", :green, { white_text: [cp_dir.to_s, :white] }])
    rescue Thor::Error => e
      raise(Thor::Error, e)
    end

    private

    def cp_and_dl_files(dir: "db")
      require("#{Souls.get_mother_path}/config/souls")
      worker_paths = Souls.configuration.workers.map { |n| n[:name].split("-").last }
      worker_paths.each do |path|
        cp_path = "./apps/api/#{dir}"
        old_path = "./apps/#{path}/#{dir}"

        system("rm -rf #{old_path}", chdir: Souls.get_mother_path)
        system("mkdir -p #{old_path}", chdir: Souls.get_mother_path)
        system("cp -r #{cp_path}/* #{old_path}", chdir: Souls.get_mother_path)
      rescue StandardError
        # Do nothing
      end
    end

    def cp_env_files
      return unless File.exist?("./apps/api/.env")

      worker_paths = Souls.configuration.workers.map { |n| n[:name].split("-").last }
      worker_paths.each do |path|
        system("rm -f ./apps/#{path}/.env", chdir: Souls.get_mother_path)
        system("cp -f ./apps/api/.env ./apps/#{path}/.env", chdir: Souls.get_mother_path)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
souls-1.8.3 lib/souls/cli/sync/model.rb
souls-1.8.2 lib/souls/cli/sync/model.rb
souls-1.8.1 lib/souls/cli/sync/model.rb
souls-1.8.0 lib/souls/cli/sync/model.rb
souls-1.7.38 lib/souls/cli/sync/model.rb