Class: MnoEnterprise::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#application_configObject



15
16
17
18
19
20
21
22
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 15

def application_config
  return if options[:skip_application_config]

  say("\n")
  @company_name  = ask("Company Name [My Company]: ").presence || "My Company"
  @support_email = ask("Support email [[email protected]]: ").presence || "[email protected]"
  @system_email  = ask("System email [[email protected]]: ").presence || "[email protected]"
end

#copy_initializerObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 24

def copy_initializer
  # Foreman config
  template "Procfile"
  template "Procfile.dev"
  template ".foreman"
  template ".healthcheck"
  template "nginx.conf"

  template "config/initializers/mno_enterprise.rb"
  template "config/mno_enterprise_styleguide.yml"
  template "config/puma.rb", skip: true # Copied from Rails 5 - skip if already existing

  # Settings
  template "config/settings.yml", "config/settings.yml"
  create_file "config/settings.local.yml"
  directory "config/settings", "config/settings"

  template "config/application.yml", "config/application.yml"
  template "config/application.yml", "config/application.sample.yml"

  @new_relic_app_name = new_relic_app_name
  template "config/newrelic.yml", "config/newrelic.yml"
end

#install_summaryObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 133

def install_summary
  unless options[:quiet]
    say("\n\n")
    say_status("==> Maestrano Enterprise has been installed ==", nil)
    say("- You can generate deployment configs by running: 'rails g mno_enterprise:puma_stack'")
    say("- You can start the server with: 'foreman start'")

    if @install_frontend
      say("\n\n")
      say_status("==> Maestrano Enterprise Angular has been installed", nil)
      say("- You can quickly customize the platform style in frontend/src/app/stylesheets")
      say("- You can customize the whole frontend by overriding mno-enterprise-angular in frontend/src/")
      say("- You can run 'rake mnoe:frontend:build' to rebuild the frontend after changing frontend/src")
    end

    if @install_admin
      say("\n\n")
      say_status("==> Maestrano Enterprise Admin Dashboard has been installed", nil)
      say("- You can access the platform with an admin user (admin_role = 'admin')")
    end

    say("\n\n")
  end
end

#notify_about_routesObject

Inject engine routes



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 110

def notify_about_routes
  if (routes_file = destination_path.join('config', 'routes.rb')).file? && (routes_file.read !~ %r{mount\ MnoEnterprise::Engine})
    mount = %Q{  # This line mount Maestrano Enterprise routes in your application under /mnoe.
  # If you would like to change where this engine is mounted, simply change the :at option to something different
  #
  # We ask that you don't use the :as option here, as Mnoe relies on it being the default of "mno_enterprise"
  scope '(:locale)' do
    mount MnoEnterprise::Engine, at: '/mnoe', as: :mno_enterprise
  end

  root to: redirect('mnoe/auth/users/sign_in')
}
    inject_into_file routes_file, mount, after: "Rails.application.routes.draw do\n"
  end

  unless options[:quiet]
    say "\n"
    say "We added the following line to your application's config/routes.rb file:"
    say "    mount MnoEnterprise::Engine, at: '/mnoe'"
    say "    root to: redirect(MnoEnterprise.router.dashboard_path)"
  end
end

#setup_adminObject



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

def setup_admin
  unless options[:skip_admin]
    say("\n")
    @install_admin = ask_with_default("Would you like to install Maestrano Enterprise Admin Dashboard (frontend)?")
    if @install_admin
      rake "mnoe:admin:install"
    end
  end
end

#setup_assetsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 48

def setup_assets
  if defined?(MnoEnterprise::Frontend)
    # Stylesheets
    copy_file "stylesheets/main.less", "app/assets/stylesheets/main.less", skip: true

    # Require main stylesheet file
    inject_into_file 'app/assets/stylesheets/application.css', before: " */" do
      " *= require main\n"
    end

    # Disable require_tree which breaks the app
    gsub_file 'app/assets/stylesheets/application.css', /\*= require_tree ./, '* require_tree .'
  end
end

#setup_frontendObject



89
90
91
92
93
94
95
96
97
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 89

def setup_frontend
  unless options[:skip_frontend]
    say("\n")
    @install_frontend = ask_with_default("Would you like to install Maestrano Enterprise Angular (frontend)?")
    if @install_frontend
      rake "mnoe:frontend:install"
    end
  end
end

#setup_less_development_pathsObject



63
64
65
66
67
68
69
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 63

def setup_less_development_paths
  if defined?(MnoEnterprise::Frontend) || Rails.env.test?
    application(nil, env: "development") do
      "# Reload frontend stylesheets on changes\n  config.less.paths << \"\#{Rails.root}/frontend/src/app/stylesheets\"\n"
    end
  end
end

#update_gitignoreObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/generators/mno_enterprise/install/install_generator.rb', line 71

def update_gitignore
  create_file '.gitignore' unless File.exists? '.gitignore'

  append_to_file '.gitignore' do
    "\n"                                +
    "# Ignore application configuration\n" +
    "config/application.yml\n"          +
    "config/application-*.yml\n"        +
    "config/settings.local.yml\n"       +
    "config/settings/*.local.yml\n"     +
    "config/environments/*.local.yml\n" +
    "\n"                                +
    "# Bower and Node packages\n"       +
    "bower_components\n"                +
    "node_modules\n"
  end
end