Sha256: f0a735513b338a7a5ed8a8da67ff60c9a9d79662cdb6430f66dca7d2f3986746

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

require_relative "base"

module Suspenders
  class RunnerGenerator < Generators::Base
    def procfile
      copy_file "Procfile", "Procfile"
    end

    def sample_env
      copy_file "sample_env", ".sample.env"
    end

    def copy_sample_env
      if bin_setup_is_ruby?
        inject_template_into_file(
          "bin/setup",
          "partials/runner_setup.rb",
          before: %(  puts "\\n== Preparing database ==")
        )
      elsif bin_setup_mentions_ci?
        inject_into_file(
          "bin/setup",
          %(  cp -i .sample.env .env\n),
          after: %(if [ -z "$CI" ]; then\n)
        )
      else
        append_to_file(
          "bin/setup",
          %(\nif [ -z "$CI" ]; then\n  cp -i .sample.env .env\nfi)
        )
      end
    end

    def update_readme
      append_template_to_file "README.md", "partials/runner_readme.md"
    end

    private

    def bin_setup_is_ruby?
      File.read("bin/setup", 20).match?(%r{#!/usr/bin/env ruby})
    end

    def bin_setup_mentions_ci?
      File.read("bin/setup").match?(/if \[ -z "\$CI" \]/)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
suspenders-20230113.0 lib/suspenders/generators/runner_generator.rb
suspenders-1.56.1 lib/suspenders/generators/runner_generator.rb
suspenders-1.55.1 lib/suspenders/generators/runner_generator.rb
suspenders-1.55.0 lib/suspenders/generators/runner_generator.rb