Class: Totem::ShellCmds::New

Inherits:
Base
  • Object
show all
Defined in:
lib/totem/shell_cmds/new.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Totem::ShellCmds::Base

Instance Method Details

#runObject



6
7
8
9
10
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
40
41
42
43
44
45
46
# File 'lib/totem/shell_cmds/new.rb', line 6

def run
  if @args[0].nil?
    puts 'ERROR: You must provide a name for the new project.'
    return
  end

  root_path = @args[0]

  puts 'Creating project root directory...'
  Dir.mkdir(root_path)
  puts

  puts 'Creating sub-directories...'
  %w(app config log tmp).each do |dir|
    puts "  #{dir}..."
    Dir.mkdir(root_path + '/' + dir)
  end
  puts

  template_path = File.expand_path(File.dirname(__FILE__) + '/../../../templates')

  puts 'Creating Gemfile...'
  input = File.read(template_path + '/Gemfile.erb')
  output = ERB.new(input).result(binding)
  File.open(root_path + '/Gemfile', 'w') { |f| f.write(output) }
  puts

  puts 'Creating config/environment.rb...'
  input = File.read(template_path + '/config/environment.rb.erb')
  output = ERB.new(input).result(binding)
  File.open(root_path + '/config/environment.rb', 'w') { |f| f.write(output) }
  puts

  puts 'Creating app/loader.rb...'
  input = File.read(template_path + '/app/loader.rb.erb')
  output = ERB.new(input).result(binding)
  File.open(root_path + '/app/loader.rb', 'w') { |f| f.write(output) }
  puts

  puts 'Finished! You must now run "bundle update" inside your project directory.'
end