Sha256: 722620eef9afd1238a9095484a3cb83fd98770474a07d708fd9ff851a6d907e6

Contents?: true

Size: 1.78 KB

Versions: 95

Compression:

Stored size: 1.78 KB

Contents

require "rainbow"

module GeneratorHelper
  # Takes a relative path from the destination root, such as `.gitignore` or `app/assets/javascripts/application.js`
  def dest_file_exists?(file)
    dest_file = File.join(destination_root, file)
    File.exist?(dest_file) ? dest_file : nil
  end

  def dest_dir_exists?(dir)
    dest_dir = File.join(destination_root, dir)
    Dir.exist?(dest_dir) ? dest_dir : nil
  end

  def setup_file_error(file, data)
    <<-MSG
#{file} was not found.
Please add the following content to your #{file} file:
#{data}
    MSG
  end

  def empty_directory_with_keep_file(destination, config = {})
    empty_directory(destination, config)
    keep_file(destination)
  end

  def keep_file(destination)
    create_file("#{destination}/.keep") unless options[:skip_keeps]
  end

  # As opposed to Rails::Generators::Testing.create_link, which creates a link pointing to
  # source_root, this symlinks a file in destination_root to a file also in
  # destination_root.
  def symlink_dest_file_to_dest_file(target, link)
    target_pathname = Pathname.new(File.join(destination_root, target))
    link_pathname = Pathname.new(File.join(destination_root, link))

    link_directory = link_pathname.dirname
    link_basename = link_pathname.basename
    target_relative_path = target_pathname.relative_path_from(link_directory)

    `cd #{link_directory} && ln -s #{target_relative_path} #{link_basename}`
  end

  def copy_file_and_missing_parent_directories(source_file, destination_file = nil)
    destination_file = source_file unless destination_file
    destination_path = Pathname.new(destination_file)
    parent_directories = destination_path.dirname
    empty_directory(parent_directories) unless dest_dir_exists?(parent_directories)
    copy_file source_file, destination_file
  end
end

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
react_on_rails-8.0.1 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-8.0.0 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-8.0.0.beta.3 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-8.0.0.beta.2 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-8.0.0.beta.1 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.1.0.beta.3 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.0.4 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.1.0.beta.2 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.0.3 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.1.0.beta.1 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.0.2 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.0.1 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-7.0.0 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-6.10.1 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-6.10.0 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-6.9.3 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-6.9.2 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-6.9.1 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-6.9.0 lib/generators/react_on_rails/generator_helper.rb
react_on_rails-6.8.2 lib/generators/react_on_rails/generator_helper.rb