Sha256: eb2290b12dccf9da3d0db70858e85ab844cbc4d7a804b2961cb491bc7be140d6

Contents?: true

Size: 1.82 KB

Versions: 18

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

module ReactOnRails
  module TaskHelpers
    # Returns the root folder of the react_on_rails gem
    def gem_root
      File.expand_path("..", __dir__)
    end

    # Returns the folder where examples are located
    def examples_dir
      File.join(gem_root, "gen-examples", "examples")
    end

    def dummy_app_dir
      File.join(gem_root, "spec/dummy")
    end

    # Executes a string or an array of strings in a shell in the given directory in an unbundled environment
    def sh_in_dir(dir, *shell_commands)
      shell_commands.flatten.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
    end

    # Executes a string or an array of strings in a shell in the given directory
    def unbundled_sh_in_dir(dir, *shell_commands)
      Dir.chdir(dir) do
        # Without `with_unbundled_env`, running bundle in the child directories won't correctly
        # update the Gemfile.lock
        Bundler.with_unbundled_env do
          shell_commands.flatten.each do |shell_command|
            sh(shell_command.strip)
          end
        end
      end
    end

    def bundle_install_in(dir)
      unbundled_sh_in_dir(dir, "bundle install")
    end

    def bundle_install_in_no_turbolinks(dir)
      sh_in_dir(dir, "DISABLE_TURBOLINKS=TRUE bundle install")
    end

    # Runs bundle exec using that directory's Gemfile
    def bundle_exec(dir: nil, args: nil, env_vars: "")
      sh_in_dir(dir, "#{env_vars} #{args}")
    end

    def generators_source_dir
      File.join(gem_root, "lib/generators/react_on_rails")
    end

    def symbolize_keys(hash)
      hash.each_with_object({}) do |(key, value), new_hash|
        new_key = key.is_a?(String) ? key.to_sym : key
        new_value = value.is_a?(Hash) ? symbolize_keys(value) : value
        new_hash[new_key] = new_value
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
react_on_rails-13.4.0 rakelib/task_helpers.rb
react_on_rails-13.3.5 rakelib/task_helpers.rb
react_on_rails-13.3.4 rakelib/task_helpers.rb
react_on_rails-13.3.3 rakelib/task_helpers.rb
react_on_rails-13.3.2 rakelib/task_helpers.rb
react_on_rails-13.3.1 rakelib/task_helpers.rb
react_on_rails-13.3.0 rakelib/task_helpers.rb
react_on_rails-13.2.0 rakelib/task_helpers.rb
react_on_rails-13.1.0 rakelib/task_helpers.rb
react_on_rails-13.0.2 rakelib/task_helpers.rb
react_on_rails-13.0.1 rakelib/task_helpers.rb
react_on_rails-13.0.0 rakelib/task_helpers.rb
react_on_rails-13.0.0.beta.0 rakelib/task_helpers.rb
react_on_rails-12.4.0 rakelib/task_helpers.rb
react_on_rails-12.4.0.rc.0 rakelib/task_helpers.rb
react_on_rails-12.3.0 rakelib/task_helpers.rb
react_on_rails-12.2.0 rakelib/task_helpers.rb
react_on_rails-12.1.0 rakelib/task_helpers.rb