shawn42/gamebox

View on GitHub
bin/gamebox

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'rake'
require 'thor'
require 'gamebox'
include Rake::DSL

DIST_TYPES = %w(mac win linux)
load File.expand_path(File.join(File.dirname(__FILE__), "..", "/lib/gamebox/tasks/gamebox_tasks.rake"))

def print_version
  puts "Gamebox #{Gamebox::VERSION::STRING}"
end

def run_rake_task(*args)
  sh "rake #{args.shift}[#{args.join(',')}]"
end

if ARGV.include?('-v') || ARGV.include?('--version')
  print_version
  exit 0
end

class GameboxThorCommand < Thor
  include Thor::Actions

  def self.source_root
    File.join(File.dirname(__FILE__), "../templates/")
  end

  desc "new PATH", "Generates a new gamebox game at PATH."
  def new(*args)
    game_name = args[0]
    self.destination_root = game_name

    if Gamebox::VERSION::RC > 0
      @gamebox_version = Gamebox::VERSION::STRING
    else
      @gamebox_version = "~> "+[Gamebox::VERSION::MAJOR, Gamebox::VERSION::MINOR, '0'].join('.')
    end

    directory "app", "."
  end
  desc "n PATH", "Generates a new gamebox game at PATH."
  alias_method :n, :new

  desc "start", "starts the application"
  def start
    print_version
    run_rake_task("run")
  end

  desc "s", "starts the application"
  alias_method :s, :start

  desc "debug", "starts the application in debug"
  def debug
    print_version
    run_rake_task("debug")
  end

  desc "d", "starts the application in debug"
  alias_method :d, :debug

  desc "dist [mac|linux|win|all]", "Build an executable for your app"
  def dist(*args)
    dist_type = args[0]
    if DIST_TYPES.include?(dist_type)
      run_rake_task("dist:#{dist_type}")
    elsif dist_type == "all"
      DIST_TYPES.each do |type|
        run_rake_task("dist:#{type}")
      end
    else
      p "Unrecognized dist type"
    end
  end

  desc "generate [actor|behavior|stage] NAME", "Gamebox generator, this will generate templated files for you for quicker development"
  def generate(*args)
    run_rake_task("generate:#{args.shift}", *args)
  end
  desc "g [actor|behavior|stage] NAME", "Gamebox generator, this will generate templated files for you for quicker development"
  alias_method :g, :generate

end

GameboxThorCommand.start