Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 6f3e56ecad2a05738f6a3921d644b7a884e5cd54 1 parent c62f549
@ismasan authored
View
4 Gemfile.lock
@@ -3,12 +3,16 @@ PATH
specs:
jbundle (0.0.9)
closure-compiler
+ rack
+ thor
GEM
remote: http://rubygems.org/
specs:
closure-compiler (1.1.1)
+ rack (1.3.0)
rspec (1.3.1)
+ thor (0.14.6)
PLATFORMS
ruby
View
9 bin/jbundle 100644 → 100755
@@ -1,10 +1,3 @@
require 'jbundle'
-JBUNDLE_FILE = 'Jfile'
-
-begin
- JBundle.config_from_file(JBUNDLE_FILE)
- JBundle.write!
-rescue JBundle::NoJFileError => boom
- puts boom.message
-end
+JBundle::CommandLine.start
View
2  jbundle.gemspec
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "rspec", '1.3.1'
s.add_dependency 'closure-compiler'
+ s.add_dependency 'thor'
+ s.add_dependency 'rack'
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
View
3  lib/jbundle.rb
@@ -4,9 +4,12 @@
require 'jbundle/bundle'
require 'jbundle/builder'
require 'jbundle/writer'
+require 'jbundle/command_line'
module JBundle
+ JFILE = 'Jfile'
+
class NoJFileError < StandardError;end
class << self
View
47 lib/jbundle/command_line.rb
@@ -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
15 lib/jbundle/server.rb
@@ -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
2  lib/jbundle/version.rb
@@ -1,3 +1,3 @@
module JBundle
- VERSION = "0.0.9"
+ VERSION = "0.0.10"
end
Please sign in to comment.
Something went wrong with that request. Please try again.