class MnoEnterprise::Generators::InstallGenerator
Public Instance Methods
application_config()
click to toggle source
# 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 [support@example.com]: ").presence || "support@example.com" @system_email = ask("System email [no-reply@example.com]: ").presence || "no-reply@example.com" end
copy_initializer()
click to toggle source
# 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_summary()
click to toggle source
# 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_routes()
click to toggle source
Inject engine routes
# 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_admin()
click to toggle source
# 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_assets()
click to toggle source
# 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_frontend()
click to toggle source
# 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_paths()
click to toggle source
# 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_gitignore()
click to toggle source
# 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
Private Instance Methods
ask_with_default(message, default = 'yes', color = nil)
click to toggle source
Ask a question with a default answer Returns a boolean
# File lib/generators/mno_enterprise/install/install_generator.rb, line 166 def ask_with_default(message, default = 'yes', color = nil) question = "#{message} (yes/no) [#{default}]" valid = false until valid answer = ask(question) answer = default if answer.empty? valid = (answer =~ /\Ay(?:es)?|no?\Z/i) end answer.downcase[0] == ?y end
destination_path()
click to toggle source
Helper method to quickly convert destination_root to a Pathname for easy file path manipulation
# File lib/generators/mno_enterprise/install/install_generator.rb, line 160 def destination_path @destination_path ||= Pathname.new(self.destination_root) end
new_relic_app_name()
click to toggle source
# File lib/generators/mno_enterprise/install/install_generator.rb, line 178 def new_relic_app_name app_name = Rails.application.class.parent_name.to_s name = app_name.parameterize.gsub('enterprise', '') "frontend-#{name}" end