Sha256: f1437e9058a28f86dc97a642c595417a84cd838d1c0c21f12bfc4ae8a5e32a3d

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

require 'erb'

module Totem
  module ShellCmds
    class New < Totem::ShellCmds::Base
      def run
        if @args[0].nil?
          puts "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

    end
  end
end

Totem::Shell.register_cmd(:new, Totem::ShellCmds::New)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
totem-0.0.6 lib/totem/shell_cmds/new.rb
totem-0.0.5 lib/totem/shell_cmds/new.rb
totem-0.0.4 lib/totem/shell_cmds/new.rb
totem-0.0.3 lib/totem/shell_cmds/new.rb