Class: Alchemy::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_npm_packageObject


96
97
98
# File 'lib/generators/alchemy/install/install_generator.rb', line 96

def add_npm_package
  run "yarn add @alchemy_cms/[email protected]~#{Alchemy.version}"
end

#copy_alchemy_entry_pointObject


100
101
102
103
104
105
106
107
# File 'lib/generators/alchemy/install/install_generator.rb', line 100

def copy_alchemy_entry_point
  webpack_config = YAML.safe_load(
    File.read(app_root.join("config", "webpacker.yml")),
    aliases: true
  )[Rails.env]
  copy_file "alchemy_admin.js",
    app_root.join(webpack_config["source_path"], webpack_config["source_entry_path"], "alchemy/admin.js")
end

#copy_configObject


40
41
42
# File 'lib/generators/alchemy/install/install_generator.rb', line 40

def copy_config
  copy_file "#{gem_config_path}/config.yml", app_config_path.join("alchemy", "config.yml")
end

#copy_demo_viewsObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/generators/alchemy/install/install_generator.rb', line 55

def copy_demo_views
  return if options[:skip_demo_files]

  copy_file "application.html.erb", app_views_path.join("layouts", "application.html.erb")
  copy_file "article.scss", app_assets_path.join("stylesheets", "alchemy", "elements", "article.scss")

  stylesheet_require = " *= require_tree ./alchemy/elements\n"
  if File.exist?(app_assets_path.join("stylesheets", "application.css"))
    insert_into_file app_assets_path.join("stylesheets", "application.css"), stylesheet_require,
      before: " */"
  else
    create_file app_assets_path.join("stylesheets", "application.css"), "/*\n#{stylesheet_require} */\n"
  end

  copy_file "_article.html.erb", app_views_path.join("alchemy", "elements", "_article.html.erb")
  copy_file "_standard.html.erb", app_views_path.join("alchemy", "page_layouts", "_standard.html.erb")
  copy_file "alchemy.en.yml", app_config_path.join("locales", "alchemy.en.yml")
end

#copy_dragonfly_configObject


74
75
76
77
78
79
80
# File 'lib/generators/alchemy/install/install_generator.rb', line 74

def copy_dragonfly_config
  template(
    "#{__dir__}/templates/dragonfly.rb.tt",
    app_config_path.join("initializers", "dragonfly.rb"),
    skip: options[:auto_accept]
  )
end

#copy_yml_filesObject


44
45
46
47
48
# File 'lib/generators/alchemy/install/install_generator.rb', line 44

def copy_yml_files
  %w(elements page_layouts menus).each do |file|
    template "#{__dir__}/templates/#{file}.yml.tt", app_config_path.join("alchemy", "#{file}.yml")
  end
end

#finalizeObject


123
124
125
126
127
128
129
130
131
# File 'lib/generators/alchemy/install/install_generator.rb', line 123

def finalize
  header
  say "Alchemy successfully installed!"
  say "Now start the server with:\n\n"
  say "  bin/rails server\n\n"
  say "and point your browser to\n\n"
  say "  http://localhost:3000/admin\n\n"
  say "and follow the onscreen instructions to finalize the installation.\n\n"
end

#install_assetsObject


50
51
52
53
# File 'lib/generators/alchemy/install/install_generator.rb', line 50

def install_assets
  copy_file "all.js", app_vendor_assets_path.join("javascripts", "alchemy", "admin", "all.js")
  copy_file "all.css", app_vendor_assets_path.join("stylesheets", "alchemy", "admin", "all.css")
end

#install_gutentag_migrationsObject


82
83
84
# File 'lib/generators/alchemy/install/install_generator.rb', line 82

def install_gutentag_migrations
  rake "gutentag:install:migrations"
end

#run_webpacker_installerObject


86
87
88
89
90
91
92
93
94
# File 'lib/generators/alchemy/install/install_generator.rb', line 86

def run_webpacker_installer
  unless options[:skip_webpacker_installer]
    # Webpacker does not create a package.json, but we need one
    unless File.exist? app_root.join("package.json")
      in_root { run "echo '{}' > package.json" }
    end
    rake("webpacker:install", abort_on_failure: true)
  end
end

#set_primary_languageObject


109
110
111
112
# File 'lib/generators/alchemy/install/install_generator.rb', line 109

def set_primary_language
  header
  install_tasks.set_primary_language(options[:auto_accept])
end

#setupObject


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

def setup
  header
  say "Welcome to AlchemyCMS!"
  say "Let's begin with some questions.\n\n"
  install_tasks.inject_routes(options[:auto_accept])
end

#setup_databaseObject


114
115
116
117
118
119
120
121
# File 'lib/generators/alchemy/install/install_generator.rb', line 114

def setup_database
  rake("db:create", abort_on_failure: true) unless options[:skip_db_create]
  # We can't invoke this rake task, because Rails will use wrong engine names otherwise
  rake("railties:install:migrations", abort_on_failure: true)
  rake("db:migrate", abort_on_failure: true)
  install_tasks.inject_seeder
  rake("db:seed", abort_on_failure: true)
end