Class: Squib::Commands::New

Inherits:
Object
  • Object
show all
Defined in:
lib/squib/commands/new.rb

Overview

Generate a new Squib project into a fresh directory.

Provides conventions for using Git (you are using version control, right??). Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget.

Examples:

squib new foo-blasters
cd foo-blasters
ruby deck.rb
git init
git add .
git commit -m "Starting my cool new game using Squib!"

Instance Method Summary collapse

Instance Method Details

#advanced_messageObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/squib/commands/new.rb', line 57

def advanced_message
  <<-EOS

This is the advanced layout designed for larger games. Everything is
organized into separate directories and the workflow is all based on
the Rakefile.

From within this directory, run `bundle install` to install extra
gems.

After that,  run `rake` to build. Check out the Rakefile for more.

Happy Squibbing! And best of luck with your game.
  -Andy (@andymeneely)

  EOS
end

#empty_path_errorObject



43
44
45
# File 'lib/squib/commands/new.rb', line 43

def empty_path_error
  ArgumentError.new('Please specify a path.')
end

#process(args, advanced) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/squib/commands/new.rb', line 26

def process(args, advanced)
  raise empty_path_error if args.empty?

  new_project_path = File.expand_path(args.join(' '), Dir.pwd)

  FileUtils.mkdir_p new_project_path
  if !Dir["#{new_project_path}/**/*"].empty?
    $stderr.puts "#{new_project_path} exists and is not empty. Doing nothing and quitting."
  else
    Dir.chdir(new_project_path) do
      FileUtils.cp_r template_path(advanced) + '/.', new_project_path
    end
  end
  puts "Created basic Squib project in #{new_project_path}."
  puts advanced_message if advanced
end

#template_path(advanced) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/squib/commands/new.rb', line 47

def template_path(advanced)
  path = case advanced
         when true
           '../builtin/projects/advanced'
         else
           '../builtin/projects/basic'
         end
  File.expand_path(path, File.dirname(__FILE__))
end