Sha256: a75984ef6f38f7c9e589cc9dd3aaa5d64cb14de8788bdc704c60f87ec6159c8b

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'thor'
module JBundle
  
  class CommandLine < Thor
    default_task :bundle
    
    map "s" => :server
    map "-v" => :version

    desc "bundle", "Minify and bundle bundle declarations into dist directory"
    def bundle
      begin
        JBundle.config_from_file(JBundle::JFILE)
        JBundle.write!
      rescue JBundle::NoJFileError => boom
        puts boom.message
      end
    end
    
    desc 'server', 'Start test rack server on port 5555'
    method_option :port, :default => "5555", :aliases => "-p"
    def server
      require 'rack'
      JBundle.config_from_file(JBundle::JFILE)
      puts "Starting test server on http://localhost:#{options[:port]}. Available bundles:"
      JBundle.config.bundles_and_files.each do |f|
        puts "- /#{f.name}"
      end

      handler = Rack::Handler.default
      downward = false
      ['INT', 'TERM', 'QUIT'].each do |signal|
        trap(signal) do
          exit! if downward
          downward = true
          handler.shutdown if handler.respond_to?(:shutdown)
          Process.wait rescue nil
          puts 'Shutting down test server'
          exit!
        end
      end
      handler.run JBundle::Server.new, {:Port => options[:port]}
    end
    
    desc 'version', 'Print installed JBundle version'
    def version
      puts JBundle::VERSION
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jbundle-0.0.10 lib/jbundle/command_line.rb