#!/usr/bin/env ruby
# INSTALLS A SPROUTCORE BUNDLE
# This script will attempt to download and install framework and application
# bundles from github.
#
# Usage:
# sc-install owner-projectname
#
# You can also choose a different install URL:
# sc-install owner-projectname --source=sproutit/sproutcore-samples
#
# You can select an install method. (git is preferred and the default)
# sc-install owner-projectname --method=zip
APP_ROOT = File.expand_path(Dir.pwd)
SC_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
$:.unshift File.join(SC_ROOT,'lib') ;
# Set String encoding to Unicode
$KCODE = 'u'
# Require SproutCore
require 'rubygems'
require 'rubigen'
require 'sproutcore'
require 'optparse'
############################################################
## Define Helper Methods
##
############################################################
## Process Options
##
# Process options
bundle_name = ARGV.shift if (ARGV.size > 0 && ARGV[0][0..0] != '-')
options = { :verbose => false, :library_root => APP_ROOT }
opts = OptionParser.new do |opts|
opts.version = SproutCore::VERSION::STRING
opts.banner = "Usage: sc-install {bundle-name} {options}"
opts.define_head "Remotely install JavaScript bundles from Github and other sources"
opts.separator ''
opts.separator '*'*80
opts.separator 'If no flags are given, sc-install will attempt to install the named bundle from'
opts.separator 'github into the local project.'
opts.separator '*'*80
SC::BundleInstaller.configure_tool_options(opts, options)
end
begin
opts.parse!
rescue Exception => e
puts opts
puts e
exit(1)
end
############################################################
## SETUP ENVIRONMENT
##
# Configure logger
SC.logger.level = (options[:verbose]) ? Logger::DEBUG : Logger::INFO
SC.logger.progname = $0
SC.logger.info("sc-install v#{SproutCore::VERSION::STRING}")
# Confirm various safety settings
SC.logger.info(" ~ Verbose logging enabled") if options[:verbose]
SC.logger.info(" ~ Dry run mode - no change will be made") if options[:dry_run]
# Load Library
library = SC.library_for(options[:library_root])
############################################################
## PERFORM THE INSTALL
##
if bundle_name.nil?
puts opts
SC.logger.fatal("A bundle name is required.")
exit(1)
end
if library.nil?
SC.logger.fatal("No SproutCore library could be found. Make sure you are inside of your project directory (the one with an sc-config file in it).")
exit(1)
end
library.install_bundle(bundle_name, options)
SC.logger.debug("")