Permalink
Browse files

New command-line rack server, useful for testing JS libs

  • Loading branch information...
ismasan committed May 29, 2011
1 parent c62f549 commit 6f3e56ecad2a05738f6a3921d644b7a884e5cd54
Showing with 73 additions and 9 deletions.
  1. +4 −0 Gemfile.lock
  2. +1 −8 bin/jbundle
  3. +2 −0 jbundle.gemspec
  4. +3 −0 lib/jbundle.rb
  5. +47 −0 lib/jbundle/command_line.rb
  6. +15 −0 lib/jbundle/server.rb
  7. +1 −1 lib/jbundle/version.rb
View
@@ -3,12 +3,16 @@ PATH
specs: specs:
jbundle (0.0.9) jbundle (0.0.9)
closure-compiler closure-compiler
rack
thor
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
closure-compiler (1.1.1) closure-compiler (1.1.1)
rack (1.3.0)
rspec (1.3.1) rspec (1.3.1)
thor (0.14.6)
PLATFORMS PLATFORMS
ruby ruby
View
9 bin/jbundle 100644 → 100755
@@ -1,10 +1,3 @@
require 'jbundle' require 'jbundle'
JBUNDLE_FILE = 'Jfile' JBundle::CommandLine.start
begin
JBundle.config_from_file(JBUNDLE_FILE)
JBundle.write!
rescue JBundle::NoJFileError => boom
puts boom.message
end
View
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
s.add_development_dependency "bundler", ">= 1.0.0" s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "rspec", '1.3.1' s.add_development_dependency "rspec", '1.3.1'
s.add_dependency 'closure-compiler' s.add_dependency 'closure-compiler'
s.add_dependency 'thor'
s.add_dependency 'rack'
s.files = `git ls-files`.split("\n") s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
View
@@ -4,9 +4,12 @@
require 'jbundle/bundle' require 'jbundle/bundle'
require 'jbundle/builder' require 'jbundle/builder'
require 'jbundle/writer' require 'jbundle/writer'
require 'jbundle/command_line'
module JBundle module JBundle
JFILE = 'Jfile'
class NoJFileError < StandardError;end class NoJFileError < StandardError;end
class << self class << self
@@ -0,0 +1,47 @@
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 'jbundle/server'
require 'rack'
puts "Starting test server on http://localhost:#{options[:port].inspect}/[:bundle_name].js"
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 'Print installed JBundle version'
def version
puts JBundle::VERSION
end
end
end
View
@@ -0,0 +1,15 @@
class Server
def initialize
JBundle.config_from_file(JBundle::JFILE)
end
def call(env)
bundle_name = env['PATH_INFO'].sub('/', '')
if !bundle_name == ''
raise 'You need to define a bundle name ie. /my_bundle.js'
end
[200, {'Content-Type' => 'application/x-javascript'}, [JBundle.build(bundle_name).src]]
end
end
View
@@ -1,3 +1,3 @@
module JBundle module JBundle
VERSION = "0.0.9" VERSION = "0.0.10"
end end

0 comments on commit 6f3e56e

Please sign in to comment.