lib/susanoo/cli/project.rb in susanoo-0.4.1 vs lib/susanoo/cli/project.rb in susanoo-0.5.0

- old
+ new

@@ -4,73 +4,47 @@ module Susanoo module CLI class Project < Thor - package_name "Susanoo" + package_name 'Susanoo' + map 's' => :server + map 'g' => :generate + def self.root=(path) @@root = path Susanoo::Project.path = path end - method_option :aliases => "g" - desc "generate GENERATOR [options]", "Run the given generator" - def generate(generator_name=nil, *options) + desc 'generate GENERATOR [options]', 'Run the given generator' + def generate(generator_name = nil, *options) if generator_name.nil? print_generator_list return end begin generator = Susanoo::Generators.const_get(camelize(generator_name.downcase)) rescue NameError - print "[Error]:".colorize(:red) + print '[Error]:'.colorize(:red) say "Generator `#{generator}` not found." exit 1 end generator.start options end - desc "server", "Run development server." - def server(port=6000) - require 'sprockets' - require 'rack' - require 'rack/rewrite' + method_option :debug, default: false + desc 'server', 'Run development server.' + def server(port = 3000) + project_root = Susanoo::Project.path + require File.join(project_root, 'config/routes') - root = Dir.getwd - #Rack::Handler::WEBrick.run :Port => 3000, :DocumentRoot => root - server = Rack::Builder.app do - map "/statics" do - project_root = Dir.getwd + # Set global debug flag + Susanoo::Project.debug = options[:debug] - assets = Sprockets::Environment.new(project_root) do |env| - env.logger = Logger.new(STDOUT) - end - - assets.append_path(File.join(project_root, 'www', 'assets')) - assets.append_path(File.join(project_root, 'www', 'assets', 'javascripts')) - assets.append_path(File.join(project_root, 'www', 'assets', 'stylesheets')) - assets.append_path(File.join(project_root, 'www', 'assets', 'images')) - - run assets - end - - map "/" do - use Rack::Static, :urls => [""], :index => "index.html" - run lambda { |env| - [ - 200, - { - 'Content-Type' => 'text/html', - 'Cache-Control' => 'public, max-age=86400' - }, - File.open('www/index.html', File::RDONLY) - ] - } - end - end - Rack::Handler::WEBrick.run(server, Port: port) + app = Rack::Server.start(app: ROUTER, server: :thin, Port: port, + debug: options[:debug]) end private def camelize(str)