Class: ForgeCLI::ApplicationCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/forge-cli/application_creator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, modules = []) ⇒ ApplicationCreator

Returns a new instance of ApplicationCreator.



6
7
8
9
# File 'lib/forge-cli/application_creator.rb', line 6

def initialize(app, modules = [])
  @app = app
  @modules = modules
end

Class Method Details

.create!(app, modules = []) ⇒ Object



2
3
4
# File 'lib/forge-cli/application_creator.rb', line 2

def self.create!(app, modules = [])
  new(app, modules).create_application!
end

Instance Method Details

#completed_messageObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/forge-cli/application_creator.rb', line 41

def completed_message
  %{
#{"Your new Forge site is almost ready!  Next steps:".foreground(:cyan)}
1.  Run 'bundle install'
2.  Set up config/database.yml
3.  Run 'rake db:create' unless your database already exists
4.  Run 'rake db:migrate'
5.  Run 'rake forge:create_admin'
6.  Run 'rake forge:load_help'
7.  Edit the contents of config/sitemap.yml, then run 'rake db:seed'
8.  Set up delayed job with 'rails generate delayed_job:active_record'
9.  Review the settings in config/initializers/devise.rb and config/settings.yml
10.  Run 'rails server' to spin up the application
11. Access Forge by going to /forge in your browser (e.g. http://localhost:3000/forge)
  }
end

#create_application!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/forge-cli/application_creator.rb', line 11

def create_application!
  system("/usr/bin/env rails new #{@app} --skip-bundle")
  app_path = File.join(Dir.pwd, @app)
  ForgeCLI::ModuleInstaller.install_module!(:base, @app, app_path)
  @modules.each do |mod|
    ForgeCLI::ModuleInstaller.install_module!(mod, @app, app_path)
  end

  # Remove some base Rails files that we don't want
  STDOUT.puts "\nRemoving unneccessary base Rails files..."
  remove_file File.join(@app, 'app', 'views', 'layouts', 'application.html.erb')
  remove_file File.join(@app, 'app', 'assets', 'stylesheets', 'application.css')
  remove_file File.join(@app, 'public', 'index.html')
  remove_file File.join(@app, 'Gemfile.lock')

  # Copy custom files from ~/.forge
  if File.exist?(File.join(ENV["HOME"], '.forge'))
    STDOUT.puts "\nCopying your custom files from ~/.forge"
    ForgeCLI::CustomFileCopier.copy_files!(@app)
  end

  # Rewrite Forge3::Application
  rewrite_app_name

  # create some new tokens
  generate_devise_tokens

  STDOUT.puts completed_message
end