Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 126 lines (97 sloc) 3.71 KB
#! /usr/bin/env ruby
$VERBOSE = nil
home = File.join(File.dirname(__FILE__), '..')
require 'fileutils'
require 'oyster'
require 'jake'
require 'rack'
require File.join(home, 'lib', 'helium')
spec = Oyster.spec do
name 'helium -- the Git-backed JavaScript package server'
author 'James Coglan <>'
description <<-EOS
Helium is a web application for deploying and serving versioned copies of
JavaScript libraries from Git repositories. It uses Jake to build libraries
and extract dependency data, generating a manifest for JS.Packages so that
client sites can load objects from Helium on demand.
The following command line tools are available; run each one with `--help`
for more information.
`he install` creates a copy of the web frontend that you can serve using
Rack and Passenger.
`he create` generates a stub JavaScript project with all the files required
for Helium to deploy it.
`he serve` starts a web server to serve static files from any directory,
useful for testing code that requires a domain name to function.
subcommand :install do
synopsis 'he install DIRECTORY'
description <<-EOS
Installs a copy of the Helium web application in the given directory.
Set up an Apache VHost with the DocumentRoot pointing to DIRECTORY/public
to serve the app through Phusion Passenger.
subcommand :create do
synopsis 'he create NAME'
description <<-EOS
Creates a new JavaScript project with the given name, containing a stub
library file, a jake.yml config file and support code for generating
local package listings and running tests.
subcommand :serve do
synopsis 'he serve DIRECTORY'
description <<-EOS
Starts a webserver on port 8000 that serves the given directory over HTTP.
Useful for testing pages that require Ajax or services with domain specific
API keys like Google Maps.
begin; options = spec.parse
rescue; exit
if opts = options[:install]
dir = opts[:unclaimed].first
if dir.nil?
puts "Installation directory required -- type `he install --help` for more info"
dir = File.expand_path(dir)
d = File.basename(dir)
puts "\nInstalling Helium app in #{dir} ..."
Helium.generate('web', dir)
puts "\n... done, now set up your webserver to serve the app:\n\n"
puts " * Point Apache at #{d}/public to serve using Passenger"
puts " * Run `rackup #{d}/` to run it locally\n\n"
elsif opts = options[:create]
name = opts[:unclaimed].first
if name.nil?
puts "Project name required -- type `he create --help` for more info"
dir = File.expand_path(name)
d = File.basename(dir)
puts "\nGenerating JavaScript project in #{dir} ..."
Helium.generate('project', dir, :name => name)
puts "\nBuilding project using Jake ..."
jake_hook(:file_created) do |build, package, type, path|
puts "create #{d}#{ path.sub(dir, '') }"
puts "\n... done, now your new JavaScript project is ready.\n\n"
puts " * Build your project by running `jake` in the root directory"
puts " * We've added generated files to your .gitignore"
puts " * Keep your dependencies up-to-date in jake.yml"
puts " * Point test/browser.html at your Helium server and write some tests!\n\n"
elsif opts = options[:serve]
dir = File.expand_path(opts[:unclaimed].first || '.')
app =
server = %w[thin mongrel webrick].map { |name|
begin; Rack::Handler.get(name)
rescue LoadError; nil
puts "Serving contents of #{dir} on port 8000 ...", :Port => 8000)