Class: Iron::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/iron/install/install_generator.rb

Constant Summary collapse

MOUNT_PATH =
"/admin".freeze
MOUNT_LINE =
%(mount Iron::Engine => "#{MOUNT_PATH}").freeze
SEEDS_MARKER =
"# == Iron CMS admin ==".freeze
OAUTH_ROUTES_MARKER =
"iron/oauth/metadata#protected_resource".freeze

Instance Method Summary collapse

Instance Method Details

#create_schema_skeletonObject



46
47
48
# File 'lib/generators/iron/install/install_generator.rb', line 46

def create_schema_skeleton
  copy_file "schema.json", "db/cms/schema.json"
end

#create_seedsObject



50
51
52
53
54
55
56
57
58
# File 'lib/generators/iron/install/install_generator.rb', line 50

def create_seeds
  return if seeds_marker_present?

  if File.exist?(seeds_path)
    append_to_file "db/seeds.rb", seeds_block
  else
    copy_file "seeds.rb", "db/seeds.rb"
  end
end

#display_instructionsObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/generators/iron/install/install_generator.rb', line 79

def display_instructions
  say "\n=== Iron CMS Installed ===\n", :green
  say "Created:"
  say "  - config/routes.rb mounts Iron::Engine at #{MOUNT_PATH}"
  say "  - db/cms/schema.json (minimal CMS schema skeleton — edit, then bin/rails iron:schema:apply)"
  say "  - db/seeds.rb provisions the first administrator (run by db:seed)"
  say "  - lib/tasks/iron_release.rake applies the CMS schema during db:prepare"
  say "  - config/routes.rb OAuth endpoints power the MCP endpoint at #{MOUNT_PATH}/api/mcp"
  say "  - .claude/skills/iron-cms/SKILL.md (the Iron CMS workflow for coding agents)"
  say "  - app/controllers/pages_controller.rb renders published content"
  say "\nSet IRON_SEED_EMAIL and IRON_SEED_PASSWORD outside local environments, or seeding fails fast."
  say "\nNext steps:"
  say "1. Run bin/dev and open http://localhost:3000#{MOUNT_PATH} to sign in."
  say "2. Deploy with bin/kamal deploy — db:prepare migrates and applies the CMS schema."
end

#install_action_textObject



33
34
35
36
37
38
# File 'lib/generators/iron/install/install_generator.rb', line 33

def install_action_text
  return if skip_db_steps?
  return if migration_present?("create_action_text_tables.action_text.rb")

  rails_command "action_text:install:migrations", inline: true
end

#install_active_storageObject



26
27
28
29
30
31
# File 'lib/generators/iron/install/install_generator.rb', line 26

def install_active_storage
  return if skip_db_steps?
  return if migration_present?("create_active_storage_tables.active_storage.rb")

  rails_command "active_storage:install", inline: true
end

#install_agent_skillObject



64
65
66
# File 'lib/generators/iron/install/install_generator.rb', line 64

def install_agent_skill
  invoke "iron:agents", [], quiet: true
end

#install_iron_migrationsObject



40
41
42
43
44
# File 'lib/generators/iron/install/install_generator.rb', line 40

def install_iron_migrations
  return if skip_db_steps?

  rails_command "iron:install:migrations", inline: true
end

#install_pagesObject



68
69
70
# File 'lib/generators/iron/install/install_generator.rb', line 68

def install_pages
  invoke "iron:pages", [], quiet: true unless routes_include?("iron_pages")
end

#mount_engineObject



16
17
18
# File 'lib/generators/iron/install/install_generator.rb', line 16

def mount_engine
  route MOUNT_LINE unless routes_include?(MOUNT_LINE)
end

#provision_adminObject



72
73
74
75
76
77
# File 'lib/generators/iron/install/install_generator.rb', line 72

def provision_admin
  return if skip_db_steps?

  rails_command "db:prepare", abort_on_failure: true
  rails_command "db:seed", abort_on_failure: true
end

#wire_oauth_routesObject



20
21
22
23
24
# File 'lib/generators/iron/install/install_generator.rb', line 20

def wire_oauth_routes
  return if routes_include?(OAUTH_ROUTES_MARKER)

  inject_into_file routes_path, "\n#{oauth_routes_block}", after: /#{Regexp.escape(MOUNT_LINE)}\n/
end

#wire_release_stepObject



60
61
62
# File 'lib/generators/iron/install/install_generator.rb', line 60

def wire_release_step
  copy_file "iron_release.rake", "lib/tasks/iron_release.rake"
end