Class: Copse::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Copse::Generators::InstallGenerator
- Defined in:
- lib/generators/copse/install_generator.rb
Overview
bin/rails generate copse:install
Wires an app to Copse the way tailwindcss:install wires up Tailwind: the
app commits a bin/dev the whole team shares.
Constant Summary collapse
- BIN_DEV =
"bin/dev"- PROCFILE =
"Procfile.dev"- MARKER =
"Copse.start"- OVERMIND_MARKER =
"process_manager: :overmind"
Instance Method Summary collapse
Instance Method Details
#create_bin_dev ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/copse/install_generator.rb', line 24 def create_bin_dev # Resolved before anything is written: detection reads the very bin/dev # this method is about to overwrite. process_manager if exists?(BIN_DEV) existing = File.read(absolute(BIN_DEV)) if existing.include?(MARKER) if existing.include?(OVERMIND_MARKER) == overmind? # Already wired to this supervisor. Running the generator twice is a # no-op. say_status :identical, BIN_DEV, :blue return end # Same wiring, other supervisor. Switching is the whole point of the # flag, and a Copse bin/dev holds nothing of the app's own to preserve, # so this one is rewritten without a backup. say_status :force, "#{BIN_DEV} (#{process_manager})", :yellow else # Teams keep real setup logic in bin/dev -- dependency checks, database # bootstrapping. Replacing it without a copy would destroy that in one # command with nothing to recover from, and prompting is not an option # in a scripted run. backup = "#{BIN_DEV}.before-copse" FileUtils.cp(absolute(BIN_DEV), absolute(backup)) say_status :backup, backup, :yellow end end template "dev.tt", BIN_DEV, force: true chmod BIN_DEV, 0o755 end |
#create_procfile_dev ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/generators/copse/install_generator.rb', line 59 def create_procfile_dev if exists?(PROCFILE) # R10: never overwritten, and never silently. Whatever the app already # runs -- a tailwindcss:watch line, a vite line -- is left exactly as is. say_status :skip, "#{PROCFILE} already exists, leaving it untouched", :yellow return end template "Procfile.dev.tt", PROCFILE end |
#report_process_manager ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/generators/copse/install_generator.rb', line 70 def report_process_manager return unless File.exist?(absolute(PROCFILE)) secondaries = Copse::Procfile.parse(File.read(absolute(PROCFILE))).secondaries if overmind? say "" say "bin/dev hands all of Procfile.dev to overmind; attach with `overmind connect web`." say "Keep `web` first in Procfile.dev: overmind gives each process base + index * 100." say "Without overmind installed, bin/dev falls back to the foreman session." # The fallback is not hypothetical -- overmind is probed per machine, so a # teammate without it lands on foreman and needs it for these entries. say "Which needs foreman, so keep `gem \"foreman\"` available too." if secondaries.any? return end return if secondaries.empty? say "" say "Copse runs the `web` process in the foreground and hands the rest to foreman." say "Add `gem \"foreman\"` to your Gemfile, or install it for the Ruby you use here." end |